optional_logger 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 354caeb0cca2eda91b7927e823369b519733d69d
4
- data.tar.gz: 07589eb6bdf45bf32ac43bf27b1c5141dcbf67d6
3
+ metadata.gz: 9053d81db875e3d007c47d17c61f451d2c5373ba
4
+ data.tar.gz: aec324fa8c19728d07ceee530a1dcc88a10a9b5a
5
5
  SHA512:
6
- metadata.gz: 8ca684990bc9d4015ecf21204ae0819d08ccbb4803aff29a45ff102dcb63cf598cb29c5704d046b9a9710f23b12b264c78fe8afaaca04124df9b8a29844b460f
7
- data.tar.gz: 07f03c04e2aa3eb55c8e5bf111d5100c8b494dbc26e95833535226f0adc2618cf8a857e9732e39ceb0b7fd6ef0b8a1c8b5abef5af8f2befa43f616df0f9257d8
6
+ metadata.gz: 000d11c38ffefad76fb1a7f3829ad21ffa359a58baea45d2c698ecf844857428de7cd761a918ae01c0d5fbf7b6715df6e451e03e4b6f99fcd5f4fcb12503d6c7
7
+ data.tar.gz: 85c300ccc030a4324224b8b7b89d8c0b0fb8815deeb4e67548ceecf9430df23ad6586db9e8c8d86b7c61d380a62d4fd25b2656121ca5544a3e758b0dc102a7cd
data/.codeclimate.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ engines:
3
+ fixme:
4
+ enabled: true
5
+ rubcop:
6
+ enabled: true
7
+ ratings:
8
+ paths:
9
+ - "lib/**/*"
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # ChangeLog
2
+
3
+ The following are lists of the notable changes included with each release.
4
+ This is intended to help keep people informed about notable changes between
5
+ versions, as well as provide a rough history.
6
+
7
+ #### Next Release
8
+
9
+ #### v1.0.0
10
+
11
+ * Added documentation around all the classes, modules, constants and methods
12
+ * Added OptionalLogger::Logger level introspection methods (#debug?, #info?,
13
+ #warn?, #error?, #fatal?)
14
+ * Added OptionalLogger::Logger level convenience methods (#debug, #info, #warn,
15
+ #error, #fatal, #unknown)
16
+ * Added OptionalLogger::Logger#add and #log methods
17
+ * Added OptionalLogger::Logger class and constructor
18
+ * Added OptionalLogger module skeleton
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem "codeclimate-test-reporter", group: :test, require: nil
4
+
3
5
  # Specify your gem's dependencies in optional_logger.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,12 +1,13 @@
1
+ [![Build Status](https://travis-ci.org/Acornsgrow/optional_logger.svg?branch=master)](https://travis-ci.org/Acornsgrow/optional_logger)
2
+ [![Code Climate](https://codeclimate.com/github/Acornsgrow/optional_logger/badges/gpa.svg)](https://codeclimate.com/github/Acornsgrow/optional_logger)
3
+ [![Test Coverage](https://codeclimate.com/github/Acornsgrow/optional_logger/badges/coverage.svg)](https://codeclimate.com/github/Acornsgrow/optional_logger/coverage)
4
+ [![Issue Count](https://codeclimate.com/github/Acornsgrow/optional_logger/badges/issue_count.svg)](https://codeclimate.com/github/Acornsgrow/optional_logger)
5
+ [![Inline docs](http://inch-ci.org/github/Acornsgrow/optional_logger.svg?branch=master)](http://inch-ci.org/github/Acornsgrow/optional_logger)
6
+
1
7
  # OptionalLogger
2
8
 
3
9
  Easily support application loggers in your gems.
4
10
 
5
- **Note:** At the moment the following is what is under HEAVY development. The
6
- Usage is currently written based on the planned usage. I will remove this notice
7
- and udpate the Usage documentation once we have finalized the API and release
8
- v1.0.0.
9
-
10
11
  ## Why?
11
12
 
12
13
  OptionalLogger was built out of the need to be able to easily support logging
@@ -35,7 +36,7 @@ accidentally altering the applications logger.
35
36
  Add this line to your gem's gemspec file:
36
37
 
37
38
  ```ruby
38
- spec.add_dependency 'optional_logger', '~> 0.1'
39
+ spec.add_dependency 'optional_logger', '~> 1.0'
39
40
  ```
40
41
 
41
42
  Or install it yourself as:
@@ -55,7 +56,7 @@ instance as `received_logger`.
55
56
  ```ruby
56
57
  require 'optional_logger'
57
58
 
58
- logger = OptionalLogger.new(received_logger)
59
+ logger = OptionalLogger::Logger.new(received_logger)
59
60
 
60
61
  logger.info("some info log message")
61
62
  logger.info("Program Name") { "some expensive info log message" }
@@ -0,0 +1,189 @@
1
+ require 'logger'
2
+
3
+ module OptionalLogger
4
+ # Proxy logger to handle making the proxied logger optional
5
+ #
6
+ # The original intent for this optional proxy logger was specifically to be
7
+ # used inside of gems. This would enable them to receive a logger from the
8
+ # parenting application/gem and log within their gem without having to worry
9
+ # about spreading conditionals all over their gem.
10
+ class Logger
11
+ # Construct an instance of the proxy logger
12
+ #
13
+ # @param logger [#add,#info?,#warn?,#debug?,#fatal?,#error?] the ruby logger
14
+ # to wrap
15
+ # @return the instance of the proxy logger
16
+ def initialize(logger)
17
+ @logger = logger
18
+ end
19
+
20
+ # Get the ruby logger instance this proxy logger wraps
21
+ #
22
+ # @return the wrapped ruby logger
23
+ def wrapped_logger
24
+ @logger
25
+ end
26
+
27
+ # Log a message at the given level if the logger is present
28
+ #
29
+ # This isn't generally a recommended method to use while logging in your
30
+ # libraries. Instead see {#debug}, {#info}, {#warn}, {#error}, {#fatal}, and
31
+ # {#unknown} as they simplify messaging considerably.
32
+ #
33
+ # If you don't want to use the recommended methods and want more control for
34
+ # some reason. There are a few ways to log a message depending on your usecase.
35
+ #
36
+ # The first is probably the most generally useful, which is logging messages
37
+ # that aren't costly to build. This is accomplished as follows:
38
+ #
39
+ # add(::Logger::INFO, 'some message', nil)
40
+ #
41
+ # The second is for use cases in which it is costly to build the log message
42
+ # as it avoids executing the block until the logger knows that the message
43
+ # level will be displayed. If the message level would not be displayed then
44
+ # the block is not executed, saving the performance cost of building the
45
+ # message.
46
+ #
47
+ # add(::Logger::INFO) { 'some expensive message' }
48
+ #
49
+ # The third gives you the benefits of preventing uneeded expensive messages
50
+ # but also allows you to override the program name that will be prefixed on
51
+ # that log message. This is accomplished as follows.
52
+ #
53
+ # add(::Logger::INFO, nil, 'overridden progname') { 'some expensive message' }
54
+ #
55
+ # It is important to realize that if the wrapped logger is nil then this
56
+ # method will simply do nothing.
57
+ #
58
+ # @param severity ::Logger::DEBUG, ::Logger::INFO, ::Logger::WARN,
59
+ # ::Logger::ERROR, ::Logger::FATAL, ::Logger::UNKNOWN
60
+ # @param message the optional message to log
61
+ # @param progname_or_message the optional program name or message, if
62
+ # message is nil, and a block is NOT provided, then progname_or_message is
63
+ # treated as a message rather than progname
64
+ # @param block the block to evaluate and yield a message, generally useful
65
+ # preventing building of expensive messages when message of that level
66
+ # aren't allowed
67
+ def add(severity, message = nil, progname_or_message = nil, &block)
68
+ @logger.add(severity, message, progname_or_message, &block) if @logger
69
+ end
70
+ alias log add
71
+
72
+ # Log a message at the info level if the logger is present
73
+ #
74
+ # There are a few ways to log a message depending on your usecase.
75
+ #
76
+ # The first is probably the most generally useful, which is logging messages
77
+ # that aren't costly to build. This is accomplished as follows:
78
+ #
79
+ # info('some message')
80
+ #
81
+ # The second is for use cases in which it is costly to build the log message
82
+ # as it avoids executing the block until the logger knows that the message
83
+ # level will be displayed. If the message level would not be displayed then
84
+ # the block is not executed, saving the performance cost of building the
85
+ # message.
86
+ #
87
+ # info { 'some expensive message' }
88
+ #
89
+ # The third gives you the benefits of preventing uneeded expensive messages
90
+ # but also allows you to override the program name that will be prefixed on
91
+ # that log message. This is accomplished as follows.
92
+ #
93
+ # info('overridden progname') { 'some expensive message' }
94
+ #
95
+ # It is important to realize that if the wrapped logger is nil then this
96
+ # method will simply do nothing.
97
+ #
98
+ # @param progname_or_message the progname or message depending on scenario
99
+ # @param block the optional block depending on scenario
100
+ def info(progname_or_message = nil, &block)
101
+ add(::Logger::INFO, nil, progname_or_message, &block)
102
+ end
103
+
104
+ # Log a message at the warn level if the logger is present
105
+ #
106
+ # See {#info} for details on specifics around various scenarios
107
+ def warn(progname_or_message = nil, &block)
108
+ add(::Logger::WARN, nil, progname_or_message, &block)
109
+ end
110
+
111
+ # Log a message at the debug level if the logger is present
112
+ #
113
+ # See {#info} for details on specifics around various scenarios
114
+ def debug(progname_or_message = nil, &block)
115
+ add(::Logger::DEBUG, nil, progname_or_message, &block)
116
+ end
117
+
118
+ # Log a message at the error level if the logger is present
119
+ #
120
+ # See {#info} for details on specifics around various scenarios
121
+ def error(progname_or_message = nil, &block)
122
+ add(::Logger::ERROR, nil, progname_or_message, &block)
123
+ end
124
+
125
+ # Log a message at the fatal level if the logger is present
126
+ #
127
+ # See {#info} for details on specifics around various scenarios
128
+ def fatal(progname_or_message = nil, &block)
129
+ add(::Logger::FATAL, nil, progname_or_message, &block)
130
+ end
131
+
132
+ # Log a message at the unknown level if the logger is present
133
+ #
134
+ # See {#info} for details on specifics around various scenarios
135
+ def unknown(progname_or_message = nil, &block)
136
+ add(::Logger::UNKNOWN, nil, progname_or_message, &block)
137
+ end
138
+
139
+ # Check if info level messages are allowed by loggers current configuration
140
+ #
141
+ # @return [Boolean] true if the current severity level allows for the
142
+ # printing of info messages and false otherwise. It will also return false
143
+ # if there is no logger present.
144
+ def info?
145
+ return @logger.info? if @logger
146
+ false
147
+ end
148
+
149
+ # Check if warn level messages are allowed by loggers current configuration
150
+ #
151
+ # @return [Boolean] true if the current severity level allows for the
152
+ # printing of warn messages and false otherwise. It will also return false
153
+ # if there is no logger present.
154
+ def warn?
155
+ return @logger.warn? if @logger
156
+ false
157
+ end
158
+
159
+ # Check if debug level messages are allowed by loggers current configuration
160
+ #
161
+ # @return [Boolean] true if the current severity level allows for the
162
+ # printing of debug messages and false otherwise. It will also return false
163
+ # if there is no logger present.
164
+ def debug?
165
+ return @logger.debug? if @logger
166
+ false
167
+ end
168
+
169
+ # Check if fatal level messages are allowed by loggers current configuration
170
+ #
171
+ # @return [Boolean] true if the current severity level allows for the
172
+ # printing of fatal messages and false otherwise. It will also return false
173
+ # if there is no logger present.
174
+ def fatal?
175
+ return @logger.fatal? if @logger
176
+ false
177
+ end
178
+
179
+ # Check if error level messages are allowed by loggers current configuration
180
+ #
181
+ # @return [Boolean] true if the current severity level allows for the
182
+ # printing of error messages and false otherwise. It will also return false
183
+ # if there is no logger present.
184
+ def error?
185
+ return @logger.error? if @logger
186
+ false
187
+ end
188
+ end
189
+ end
@@ -1,3 +1,4 @@
1
1
  module OptionalLogger
2
- VERSION = "0.1.0"
2
+ # The version of the library
3
+ VERSION = "1.0.0"
3
4
  end
@@ -1,5 +1,7 @@
1
- require "optional_logger/version"
1
+ require 'optional_logger/version'
2
+ require 'optional_logger/logger'
2
3
 
4
+ # Top-level namespace for a library providing an optional logger and supporting
5
+ # functionality around it
3
6
  module OptionalLogger
4
- # Your code goes here...
5
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optional_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew De Ponte
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-08 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,9 +59,11 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".codeclimate.yml"
62
63
  - ".gitignore"
63
64
  - ".rspec"
64
65
  - ".travis.yml"
66
+ - CHANGELOG.md
65
67
  - CODE_OF_CONDUCT.md
66
68
  - Gemfile
67
69
  - LICENSE.txt
@@ -70,6 +72,7 @@ files:
70
72
  - bin/console
71
73
  - bin/setup
72
74
  - lib/optional_logger.rb
75
+ - lib/optional_logger/logger.rb
73
76
  - lib/optional_logger/version.rb
74
77
  - optional_logger.gemspec
75
78
  homepage: http://github.com/Acornsgrow/optional_logger