log_tribe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4eb5ee72fac8834d034f667da0e62b5d750557c
4
+ data.tar.gz: 7a75231f1c4e9e0665bec7cc55e112d7e1538aae
5
+ SHA512:
6
+ metadata.gz: dc367959523714222881a2e31a8144bed98f264ff54ecda85093433b84aaf63c215b3bdb5ab2d946240338ae6b8bbd30db35a7bd88fd38fe9c44e17de9f33080
7
+ data.tar.gz: 61337d75b602509e61b1cae64afe4956dc9cc9f4f87927bd9467c10b61271169ef9336433f0f38394ea70a8426ddae623cb15258c8a9975b4db70a6b23e5ad4e
data/.gitignore ADDED
@@ -0,0 +1,46 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+
37
+ /.bundle/
38
+ /.yardoc
39
+ /Gemfile.lock
40
+ /_yardoc/
41
+ /coverage/
42
+ /doc/
43
+ /pkg/
44
+ /spec/reports/
45
+ /tmp/
46
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ # Reference here: https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
2
+
3
+ Metrics/LineLength:
4
+ Description: 'Limit lines to 165 characters.'
5
+ Enabled: true
6
+ Max: 165
7
+
8
+ Metrics/MethodLength:
9
+ Description: 'Try to avoid methods longer than 50 lines of code.'
10
+ Enabled: true
11
+ Max: 50
12
+
13
+ Style/Documentation:
14
+ Description: 'Document classes and non-namespace modules.'
15
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.6
5
+ - 2.2.2
6
+ script: bundle exec rspec spec
data/.versions.conf ADDED
@@ -0,0 +1,2 @@
1
+ ruby=ruby-2.2.2
2
+ ruby-gemset=log_tribe
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in log_tribe.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Christian Kakesa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Christian Kakesa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # LogTribe
2
+
3
+ Write logs messages to multiple destinations.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'log_tribe'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install log_tribe
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ log = LogTribe::Loggers.new([Logger.new(STDOUT), Fluent::Logger::FluentLogger.new(nil, host: 'srv', port: 10_010)],
25
+ { tag_name: 'app_name.app_type' })
26
+ log.info 'this log message is send to the 2 loggers passed in parameter'
27
+ log.debug 'debug message send too...'
28
+ log.close # Or not...
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/fenicks/log_tribe/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task default: :spec
@@ -0,0 +1,179 @@
1
+ require 'logger'
2
+
3
+ module LogTribe
4
+ class Loggers < ::Logger
5
+ attr_reader :loggers, :tag_name
6
+
7
+ # Logging severity threshold (e.g. <tt>::Logger::INFO</tt>).
8
+ attr_reader :level
9
+
10
+ # See #level
11
+ def level=(value)
12
+ @level = value
13
+ @loggers.each do |logger|
14
+ logger.level = value
15
+ end
16
+ end
17
+
18
+ # Program name to include in log messages.
19
+ attr_reader :progname
20
+
21
+ # See #progname
22
+ def progname=(value)
23
+ @progname = value
24
+ @loggers.each do |logger|
25
+ logger.progname = value if logger.respond_to?(:progname)
26
+ end
27
+ end
28
+
29
+ # Returns the date format being used. See #datetime_format=
30
+ attr_reader :datetime_format
31
+
32
+ # Set date-time format.
33
+ #
34
+ # +datetime_format+:: A string suitable for passing to +strftime+.
35
+ def datetime_format=(datetime_format)
36
+ @datetime_format = datetime_format
37
+ @loggers.each do |logger|
38
+ logger.datetime_format = datetime_format if logger.respond_to?(:datetime_format)
39
+ end
40
+ end
41
+
42
+ # Logging formatter, as a +Proc+ that will take four arguments and
43
+ # return the formatted message. The arguments are:
44
+ #
45
+ # +severity+:: The Severity of the log message.
46
+ # +time+:: A Time instance representing when the message was logged.
47
+ # +progname+:: The #progname configured, or passed to the logger method.
48
+ # +msg+:: The _Object_ the user passed to the log message; not necessarily a
49
+ # String.
50
+ #
51
+ # The block should return an Object that can be written to the logging
52
+ # device via +write+. The default formatter is used when no formatter is
53
+ # set.
54
+ attr_reader :formatter
55
+
56
+ # See #formatter
57
+ def formatter=(callable)
58
+ @formatter = callable
59
+ @loggers.each do |logger|
60
+ logger.formatter = callable if logger.respond_to?(:formatter)
61
+ end
62
+ end
63
+
64
+ # See ::Logger#Formatter
65
+ attr_reader :default_formatter
66
+
67
+ # :call-seq:
68
+ # LogTribe::Loggers.new(log_or_logs_array, options)
69
+ #
70
+ # Create a multi log objects manager in order to send message through multiple destination loggers.
71
+ #
72
+ # === Attributes
73
+ #
74
+ # * +log_or_logs_array+ - A simple log object or an array of logger objects.
75
+ # * +options+ - Options used in logger objects which makes sense.
76
+ #
77
+ # === Options
78
+ #
79
+ # * +:tag_name+ - Name of the tag for logger like FluentLogger (Fluentd).
80
+ #
81
+ # === Examples
82
+ #
83
+ # Build log's tribe:
84
+ #
85
+ # LogTribe::Loggers.new([Logger.new(STDOUT), Fluent::Logger::FluentLogger.new(nil, host: 'srv', port: 10_010)], { tag_name: 'app_name.app_type' })
86
+ # LogTribe::Loggers.new(Logger.new(STDOUT))
87
+ # LogTribe::Loggers.new(Fluent::Logger::FluentLogger.new(nil, host: 'srv', port: 10_010), { tag_name: 'app_name.app_type' })
88
+ # LogTribe::Loggers.new(Fluent::Logger::FluentLogger.new(nil, host: 'srv', port: 10_010))
89
+ #
90
+ def initialize(log_or_logs_array, options = {})
91
+ @loggers = Array(log_or_logs_array)
92
+ @tag_name = options.delete(:tag_name)
93
+ @level = DEBUG
94
+ @progname = nil
95
+ @datetime_format = nil
96
+ @formatter = nil
97
+ @default_formatter = Formatter.new
98
+ end
99
+
100
+ #
101
+ # :call-seq:
102
+ # Logger#add(severity, message = nil, progname = nil) { ... }
103
+ #
104
+ # === Args
105
+ #
106
+ # +severity+::
107
+ # Severity. Constants are defined in Logger namespace: +DEBUG+, +INFO+,
108
+ # +WARN+, +ERROR+, +FATAL+, or +UNKNOWN+.
109
+ # +message+::
110
+ # The log message. A String or Exception.
111
+ # +progname+::
112
+ # Program name string. Can be omitted. Treated as a message if no
113
+ # +message+ and +block+ are given.
114
+ # +block+::
115
+ # Can be omitted. Called to get a message string if +message+ is nil.
116
+ #
117
+ # === Return
118
+ #
119
+ # When the given severity is not high enough (for this particular logger),
120
+ # log no message, and return +true+.
121
+ #
122
+ # === Description
123
+ #
124
+ # Log a message if the given severity is high enough. This is the generic
125
+ # logging method. Users will be more inclined to use #debug, #info, #warn,
126
+ # #error, and #fatal.
127
+ #
128
+ # <b>Message format</b>: +message+ can be any object, but it has to be
129
+ # converted to a String in order to log it. Generally, +inspect+ is used
130
+ # if the given object is not a String.
131
+ # A special case is an +Exception+ object, which will be printed in detail,
132
+ # including message, class, and backtrace. See #msg2str for the
133
+ # implementation if required.
134
+ #
135
+ # === Bugs
136
+ #
137
+ # * Logfile is not locked.
138
+ # * Append open does not need to lock file.
139
+ # * If the OS supports multi I/O, records possibly may be mixed.
140
+ #
141
+ def add(severity, message = nil, progname = nil, &block)
142
+ @loggers.each do |logger|
143
+ if logger.respond_to?(:add)
144
+ logger.add(severity, message, progname, &block)
145
+ elsif defined?(::Fluent::Logger) && logger.respond_to?(:post)
146
+ # FluentLogger
147
+ logger.post(@tag_name || 'none'.freeze,
148
+ message: format_message(format_severity(severity), Time.now, progname, message)
149
+ )
150
+ end
151
+ end
152
+ end
153
+ # alias_method :log, :add
154
+
155
+ #
156
+ # Dump given message to the log device without any formatting. If no log
157
+ # device exists, return +nil+.
158
+ #
159
+ def <<(msg)
160
+ @loggers.each do |logger|
161
+ if logger.respond_to?(:<<)
162
+ logger << msg
163
+ elsif defined?(::Fluent::Logger) && logger.respond_to?(:post)
164
+ # FluentLogger
165
+ logger.post(@tag_name || 'none'.freeze, message: msg)
166
+ end
167
+ end
168
+ end
169
+
170
+ #
171
+ # Close the logging devices.
172
+ #
173
+ def close
174
+ @loggers.each do |logger|
175
+ logger.close if logger.respond_to?(:close)
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,3 @@
1
+ module LogTribe
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/log_tribe.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'log_tribe/version'
2
+ require_relative 'log_tribe/loggers'
data/log_tribe.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'log_tribe/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'log_tribe'
8
+ spec.version = LogTribe::VERSION
9
+ spec.authors = ['Christian Kakesa']
10
+ spec.email = ['christian.kakesa@gmail.com']
11
+
12
+ spec.summary = 'Write logs messages to multiple destinations.'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/fenicks/log_tribe'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'bin'
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.9'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rubocop', '~> 0.30.1'
33
+ spec.add_development_dependency 'rspec', '~> 3.3'
34
+ spec.add_development_dependency 'simplecov', '~> 0.10.0'
35
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log_tribe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Kakesa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.30.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.30.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ description: Write logs messages to multiple destinations.
84
+ email:
85
+ - christian.kakesa@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - ".versions.conf"
95
+ - Gemfile
96
+ - LICENSE
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - lib/log_tribe.rb
101
+ - lib/log_tribe/loggers.rb
102
+ - lib/log_tribe/version.rb
103
+ - log_tribe.gemspec
104
+ homepage: https://github.com/fenicks/log_tribe
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Write logs messages to multiple destinations.
129
+ test_files: []