logging_library 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +4 -0
- data/.rubocop.yml +24 -0
- data/.rubocop_todo.yml +17 -0
- data/.travis.yml +7 -0
- data/.yardopts +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/LICENSE +23 -0
- data/README.md +88 -0
- data/Rakefile +17 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/test.rb +23 -0
- data/lib/ecraft/logging_library.rb +4 -0
- data/lib/logging_library.rb +9 -0
- data/lib/logging_library/custom_formatter.rb +127 -0
- data/lib/logging_library/logger.rb +23 -0
- data/lib/logging_library/logger_factory.rb +17 -0
- data/lib/logging_library/mixins/loggable.rb +29 -0
- data/lib/logging_library/version.rb +3 -0
- data/logging_library.gemspec +32 -0
- metadata +164 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f72e7d15d7d2da84c698f410c97268c48917f709
|
|
4
|
+
data.tar.gz: 2c7fd595e3ba4b99d41b8c810e699480050f3c9b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5808dc5f7f9883cd23c506cc70ca3ef97991a381c3179b865b22dafc933e4cf2cc9efb1674af041dbd97455fd9cb1502de62fff645c5183d540f1d8e8fe61e2d
|
|
7
|
+
data.tar.gz: '018d3c1b6cc34c98e2e20372cb12f2ca7ac451f75bc75b2a55e557eccaea207502c3867ada1aa37c64368ec10af90b25e83315977b63de8f82ec2466e4c511d4'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Lint/EndAlignment:
|
|
2
|
+
AlignWith: variable
|
|
3
|
+
|
|
4
|
+
Metrics/BlockLength:
|
|
5
|
+
Exclude:
|
|
6
|
+
- spec/**/*
|
|
7
|
+
Metrics/LineLength:
|
|
8
|
+
Max: 132
|
|
9
|
+
Metrics/MethodLength:
|
|
10
|
+
Severity: warning
|
|
11
|
+
|
|
12
|
+
# Rationale: allow Weirich-style blocks
|
|
13
|
+
Style/BlockDelimiters:
|
|
14
|
+
Enabled: false
|
|
15
|
+
Style/Documentation:
|
|
16
|
+
Enabled: false
|
|
17
|
+
Style/Encoding:
|
|
18
|
+
Enabled: false
|
|
19
|
+
Style/FileName:
|
|
20
|
+
Enabled: false
|
|
21
|
+
Style/MultilineOperationIndentation:
|
|
22
|
+
EnforcedStyle: indented
|
|
23
|
+
|
|
24
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2017-03-17 11:15:17 +0200 using RuboCop version 0.46.0.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
# Offense count: 1
|
|
10
|
+
Lint/HandleExceptions:
|
|
11
|
+
Exclude:
|
|
12
|
+
- 'Rakefile'
|
|
13
|
+
|
|
14
|
+
# Offense count: 1
|
|
15
|
+
# Configuration parameters: CountComments.
|
|
16
|
+
Metrics/BlockLength:
|
|
17
|
+
Max: 86
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--markup markdown --no-private
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at per.lundberg@ecraft.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) eCraft Oy Ab and Contributors
|
|
4
|
+
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
[](https://travis-ci.org/ecraft/logging_library)
|
|
2
|
+
|
|
3
|
+
# LoggingLibrary
|
|
4
|
+
|
|
5
|
+
This library provides logging support for your application or framework, with an opinionated default configuration in terms of log
|
|
6
|
+
format, etc.
|
|
7
|
+
|
|
8
|
+
It is compatible with both JRuby and MRI.
|
|
9
|
+
|
|
10
|
+
Wraps the functionality of [mixlog-log](https://github.com/chef/mixlib-log).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this line to your application's `Gemfile`:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'logging_library'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
And then execute:
|
|
21
|
+
|
|
22
|
+
$ bundle install
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
require 'logging_library'
|
|
28
|
+
|
|
29
|
+
class MyClass
|
|
30
|
+
include LoggingLibrary::Loggable
|
|
31
|
+
|
|
32
|
+
def load_data_from_database
|
|
33
|
+
logger.info('Starting to load data from database')
|
|
34
|
+
|
|
35
|
+
# DEBUG-level messages are not printed by default; see logger#level= if you
|
|
36
|
+
# want to customize the log level.
|
|
37
|
+
logger.debug("Running as user #{current_user}")
|
|
38
|
+
|
|
39
|
+
# If you use blocks to wrap log messages, they'll only execute if needed
|
|
40
|
+
logger.debug { "Score for all participants: #{expensive_operation}" }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def current_user
|
|
44
|
+
'john_doe'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def expensive_operation
|
|
48
|
+
sleep 5
|
|
49
|
+
9_000
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Development
|
|
55
|
+
|
|
56
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
|
57
|
+
run `rake spec` to run the tests. You can also run `bin/console` for an
|
|
58
|
+
interactive prompt that will allow you to experiment.
|
|
59
|
+
|
|
60
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
61
|
+
To release a new version, update the version number in `version.rb`, and then
|
|
62
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
|
63
|
+
push git commits and tags, and push the `.gem` file to
|
|
64
|
+
[rubygems.org](https://rubygems.org).
|
|
65
|
+
|
|
66
|
+
## Contributing
|
|
67
|
+
|
|
68
|
+
Bug reports and pull requests are welcome on GitHub at
|
|
69
|
+
https://github.com/ecraft/logging_library. This project is intended to
|
|
70
|
+
be a safe, welcoming space for collaboration, and contributors are expected to
|
|
71
|
+
adhere to the [Contributor Covenant](http://contributor-covenant.org) code of
|
|
72
|
+
conduct.
|
|
73
|
+
|
|
74
|
+
### Documentation
|
|
75
|
+
|
|
76
|
+
We strive to write API documentation inline in [YARD](http://yardoc.org) format.
|
|
77
|
+
|
|
78
|
+
Generate API documentation using `yardoc` or `rake yard`.
|
|
79
|
+
|
|
80
|
+
Preview API documentation locally with
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
bundle exec yard server -r
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### License
|
|
87
|
+
|
|
88
|
+
MIT
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
6
|
+
rescue LoadError
|
|
7
|
+
task :spec
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
begin
|
|
11
|
+
require 'yard'
|
|
12
|
+
require 'yard/rake/yardoc_task'
|
|
13
|
+
YARD::Rake::YardocTask.new
|
|
14
|
+
rescue LoadError
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
task default: :spec
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'ecraft/logging_library'
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require 'irb'
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bin/test.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'ecraft/logging_library'
|
|
4
|
+
|
|
5
|
+
Rainbow.enabled = true
|
|
6
|
+
|
|
7
|
+
class SomeClass
|
|
8
|
+
include Ecraft::LoggingLibrary::Loggable
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
logger.level = :debug
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def colortest
|
|
15
|
+
logger.fatal('This is a fatal error')
|
|
16
|
+
logger.error('This is a non-fatal error')
|
|
17
|
+
logger.warn('This is a warning. No need to panic.')
|
|
18
|
+
logger.info('This is just regular info.')
|
|
19
|
+
logger.debug('This is a debug message that most applications will have disabled.')
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
SomeClass.new.colortest
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
require 'rainbow'
|
|
3
|
+
|
|
4
|
+
module LoggingLibrary
|
|
5
|
+
#
|
|
6
|
+
# Handles log formatting. Not intended to be used from user code.
|
|
7
|
+
#
|
|
8
|
+
class CustomFormatter < ::Logger::Formatter
|
|
9
|
+
DATE_PATTERN = '%Y-%m-%d %H:%M:%S.%L'.freeze
|
|
10
|
+
|
|
11
|
+
LogMessage = Struct.new(:severity, :time, :logger_name, :message) do
|
|
12
|
+
LINE_PREPEND = ' ' * 8
|
|
13
|
+
|
|
14
|
+
def to_formatted_string
|
|
15
|
+
if show_time?
|
|
16
|
+
format("%s %s %s %s\n", formatted_colored_severity, formatted_colored_time,
|
|
17
|
+
formatted_colored_logger_name, colored_message)
|
|
18
|
+
else
|
|
19
|
+
format("%-5s %s %s\n", formatted_colored_severity, formatted_colored_logger_name, colored_message)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def colored_message
|
|
24
|
+
return formatted_message unless Rainbow.enabled
|
|
25
|
+
Rainbow(formatted_message).color(text_color_for_severity)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Converts some argument to a Logger.severity() call to a string. Regular strings pass through like
|
|
29
|
+
# normal, Exceptions get formatted as "message (class)\nbacktrace", and other random stuff gets
|
|
30
|
+
# put through "object.inspect"
|
|
31
|
+
def formatted_message
|
|
32
|
+
case message
|
|
33
|
+
when ::String
|
|
34
|
+
message
|
|
35
|
+
when ::Exception
|
|
36
|
+
"#{message.message} (#{message.class})\n" +
|
|
37
|
+
LINE_PREPEND +
|
|
38
|
+
(message.backtrace || []).join("\n#{LINE_PREPEND}")
|
|
39
|
+
else
|
|
40
|
+
message.inspect
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def formatted_colored_severity
|
|
45
|
+
if Rainbow.enabled
|
|
46
|
+
Rainbow(formatted_severity).color(color_for_severity)
|
|
47
|
+
else
|
|
48
|
+
formatted_severity
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def formatted_colored_time
|
|
53
|
+
if Rainbow.enabled
|
|
54
|
+
Rainbow(formatted_time).color(time_color_for_severity)
|
|
55
|
+
else
|
|
56
|
+
formatted_severity
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def formatted_colored_logger_name
|
|
61
|
+
return formatted_logger_name unless Rainbow.enabled
|
|
62
|
+
|
|
63
|
+
Rainbow(formatted_logger_name).color(text_color_for_severity)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def formatted_severity
|
|
67
|
+
format('%-5s', severity)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def formatted_time
|
|
71
|
+
'[' + time.strftime(DATE_PATTERN) + ']'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def formatted_logger_name
|
|
75
|
+
logger_name + ':'
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def color_for_severity
|
|
79
|
+
if show_time?
|
|
80
|
+
text_color_for_severity
|
|
81
|
+
else
|
|
82
|
+
color_for_severity_lighter
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def text_color_for_severity
|
|
87
|
+
case severity.downcase.to_sym
|
|
88
|
+
when :fatal then :magenta
|
|
89
|
+
when :error then :red
|
|
90
|
+
when :warn then :yellow
|
|
91
|
+
when :info then :gray
|
|
92
|
+
when :debug then '#606060'
|
|
93
|
+
else :gray
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Returns a somewhat lighter color for the time, to make it stand out in the presentation.
|
|
98
|
+
def time_color_for_severity
|
|
99
|
+
case severity.downcase.to_sym
|
|
100
|
+
when :fatal then '#FF00FF'
|
|
101
|
+
when :error then '#FF0000'
|
|
102
|
+
when :warn then '#FFFF00'
|
|
103
|
+
when :info then '#FFFFFF'
|
|
104
|
+
when :debug then '#808080'
|
|
105
|
+
else :gray
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# We want "something" to stand out. If time isn't being shown, we utilize its color for displaying the severity.
|
|
110
|
+
alias_method :color_for_severity_lighter, :time_color_for_severity
|
|
111
|
+
|
|
112
|
+
def show_time?
|
|
113
|
+
# When STDERR is redirected, we are likely running as a service with a syslog daemon already appending a timestamp to the
|
|
114
|
+
# line (and two timestamps is redundant).
|
|
115
|
+
tty?
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def tty?
|
|
119
|
+
$stderr.tty?
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def call(severity, time, progname, message)
|
|
124
|
+
LogMessage.new(severity, time, progname, message).to_formatted_string
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
require 'mixlib/log'
|
|
3
|
+
|
|
4
|
+
module LoggingLibrary
|
|
5
|
+
#
|
|
6
|
+
# Responsible for printing out log messages. Not intended to be used directly from user code; use the Loggable mixin
|
|
7
|
+
# (preferred) or LoggerFactory (secondary choice) to create a logger.
|
|
8
|
+
#
|
|
9
|
+
class Logger
|
|
10
|
+
include Mixlib::Log
|
|
11
|
+
extend Forwardable
|
|
12
|
+
|
|
13
|
+
def_delegator :logger, :progname, :name
|
|
14
|
+
|
|
15
|
+
def initialize(name)
|
|
16
|
+
init($stderr)
|
|
17
|
+
|
|
18
|
+
logger.level = :info
|
|
19
|
+
logger.progname = name
|
|
20
|
+
logger.formatter = CustomFormatter.new
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module LoggingLibrary
|
|
2
|
+
#
|
|
3
|
+
# Module responsible for instantiating logger objects.
|
|
4
|
+
#
|
|
5
|
+
module LoggerFactory
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
# Creates a new `Logger` object.
|
|
9
|
+
#
|
|
10
|
+
# @param name [String] An optional parameter for overriding the name of the logger. If not provided, a default will be
|
|
11
|
+
# determined automatically.
|
|
12
|
+
def create(name = nil)
|
|
13
|
+
logger_name = name || caller[0][/`.*'/][1..-2]
|
|
14
|
+
Logger.new(logger_name)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module LoggingLibrary
|
|
2
|
+
module Mixins
|
|
3
|
+
#
|
|
4
|
+
# Mixin for adding a lazily-instantiated `logger` attribute to your class, with reasonable defaults based on the class name.
|
|
5
|
+
#
|
|
6
|
+
module Loggable
|
|
7
|
+
def logger
|
|
8
|
+
@logger ||= LoggerFactory.create(_logger_name)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def _logger_name
|
|
14
|
+
# Handle both `extend` and `include` use cases.
|
|
15
|
+
if self.class == Class
|
|
16
|
+
_short_class_name(to_s)
|
|
17
|
+
else
|
|
18
|
+
_short_class_name(self.class.name)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def _short_class_name(full_name)
|
|
23
|
+
# ClassThatIncludesLoggable vs Ecraft::LoggingLibrary::ClassThatIncludesLoggable. The latter feels overly detailed;
|
|
24
|
+
# there are hopefully not that many classes with the same name in an application...
|
|
25
|
+
full_name.split('::').last
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'logging_library/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'logging_library'
|
|
8
|
+
spec.version = LoggingLibrary::VERSION
|
|
9
|
+
spec.authors = ['Tre Kronor']
|
|
10
|
+
spec.email = ['team.trekronor@ecraft.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = 'Logging library'
|
|
13
|
+
spec.description = 'Library with support for logging in applications.'
|
|
14
|
+
spec.homepage = 'https://github.com/ecraft/logging_library'
|
|
15
|
+
spec.license = 'MIT'
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = 'exe'
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ['lib']
|
|
23
|
+
|
|
24
|
+
spec.add_runtime_dependency 'mixlib-log', '~> 1.7'
|
|
25
|
+
spec.add_runtime_dependency 'rainbow', '~> 2.2'
|
|
26
|
+
|
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.5'
|
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 0.46'
|
|
31
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: logging_library
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.4
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tre Kronor
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: mixlib-log
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.7'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.7'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rainbow
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.2'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.2'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.13'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.13'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '10.5'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '10.5'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.5'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.5'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rubocop
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0.46'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0.46'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: yard
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0.9'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0.9'
|
|
111
|
+
description: Library with support for logging in applications.
|
|
112
|
+
email:
|
|
113
|
+
- team.trekronor@ecraft.com
|
|
114
|
+
executables: []
|
|
115
|
+
extensions: []
|
|
116
|
+
extra_rdoc_files: []
|
|
117
|
+
files:
|
|
118
|
+
- ".gitignore"
|
|
119
|
+
- ".rspec"
|
|
120
|
+
- ".rubocop.yml"
|
|
121
|
+
- ".rubocop_todo.yml"
|
|
122
|
+
- ".travis.yml"
|
|
123
|
+
- ".yardopts"
|
|
124
|
+
- CODE_OF_CONDUCT.md
|
|
125
|
+
- Gemfile
|
|
126
|
+
- LICENSE
|
|
127
|
+
- README.md
|
|
128
|
+
- Rakefile
|
|
129
|
+
- bin/console
|
|
130
|
+
- bin/setup
|
|
131
|
+
- bin/test.rb
|
|
132
|
+
- lib/ecraft/logging_library.rb
|
|
133
|
+
- lib/logging_library.rb
|
|
134
|
+
- lib/logging_library/custom_formatter.rb
|
|
135
|
+
- lib/logging_library/logger.rb
|
|
136
|
+
- lib/logging_library/logger_factory.rb
|
|
137
|
+
- lib/logging_library/mixins/loggable.rb
|
|
138
|
+
- lib/logging_library/version.rb
|
|
139
|
+
- logging_library.gemspec
|
|
140
|
+
homepage: https://github.com/ecraft/logging_library
|
|
141
|
+
licenses:
|
|
142
|
+
- MIT
|
|
143
|
+
metadata: {}
|
|
144
|
+
post_install_message:
|
|
145
|
+
rdoc_options: []
|
|
146
|
+
require_paths:
|
|
147
|
+
- lib
|
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
|
+
requirements:
|
|
155
|
+
- - ">="
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: '0'
|
|
158
|
+
requirements: []
|
|
159
|
+
rubyforge_project:
|
|
160
|
+
rubygems_version: 2.6.11
|
|
161
|
+
signing_key:
|
|
162
|
+
specification_version: 4
|
|
163
|
+
summary: Logging library
|
|
164
|
+
test_files: []
|