sinlog 0.0.2 → 0.0.3

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.
data/docs/Readme.md CHANGED
@@ -4,6 +4,9 @@ A very, very simple Ruby singleton logger with colored log levels.
4
4
 
5
5
  > Singleton means that the entire program will share the same instance (logger).
6
6
 
7
+ [![Gem Version](https://badge.fury.io/rb/sinlog.svg?icon=si%3Arubygems)](https://rubygems.org/gems/sinlog)
8
+ <!-- [![RubyDoc](https://img.shields.io/badge/-y?label=rubydoc&color=orange)](https://www.rubydoc.info/gems/sinlog) -->
9
+
7
10
  ---
8
11
 
9
12
  | Language/語言 | ID |
@@ -12,10 +15,6 @@ A very, very simple Ruby singleton logger with colored log levels.
12
15
  | [简体中文](./Readme-zh.md) | zh-Hans-CN |
13
16
  | [繁體中文](./Readme-zh-Hant.md) | zh-Hant-TW |
14
17
 
15
- > Want to support Mehr Sprachen/Más idiomas/Autres langues/Другие языки/...?
16
- >
17
- > Please feel free to send me an issue!
18
-
19
18
  ---
20
19
 
21
20
  <details>
@@ -23,10 +22,17 @@ A very, very simple Ruby singleton logger with colored log levels.
23
22
  Table of Contents (click to expand)
24
23
  </summary>
25
24
 
26
- - [Learn Sinlog API By Example](#learn-sinlog-api-by-example)
27
- - [include module](#include-module)
28
- - [LambdaExt](#lambdaext)
29
- - [LogLambdaExt](#loglambdaext)
25
+ - [Quick Start](#quick-start)
26
+ - [Installation](#installation)
27
+ - [Comparison](#comparison)
28
+ - [Method List](#method-list)
29
+ - [Loggable \& LogExt](#loggable--logext)
30
+ - [LogShortExt](#logshortext)
31
+ - [Examples](#examples)
32
+ - [Classic Method Call (Neither Mixin nor Refinement)](#classic-method-call-neither-mixin-nor-refinement)
33
+ - [Mixin](#mixin)
34
+ - [Refinement](#refinement)
35
+ - [Learn Sinlog API by Example](#learn-sinlog-api-by-example)
30
36
  - [Classic Method Call](#classic-method-call)
31
37
  - [Advanced](#advanced)
32
38
  - [Real World Example](#real-world-example)
@@ -36,148 +42,150 @@ Table of Contents (click to expand)
36
42
  - [Other Logger Methods](#other-logger-methods)
37
43
  - [Notes](#notes)
38
44
  - [Side Note](#side-note)
45
+ - [Changelog](#changelog)
46
+ - [0.0.3](#003)
39
47
  - [License](#license)
40
48
 
41
49
  </details>
42
50
 
43
- ## Learn Sinlog API By Example
51
+ ## Quick Start
44
52
 
45
- First, install `sinlog`.
53
+ ## Installation
46
54
 
47
55
  ```sh
56
+ # POSIX-sh
57
+ #
48
58
  gem install sinlog
49
59
  ```
50
60
 
51
- Then, we can run `irb` to quickly try it out.
61
+ ### Comparison
52
62
 
53
- ### include module
63
+ | Module | Type | Methods |
64
+ | ----------- | ---------- | -------------------------------------------- |
65
+ | Loggable | Mixin | `log_dbg`, `log_info`, etc. |
66
+ | LogExt | Refinement | `log_dbg`, `log_info`, etc. |
67
+ | LogShortExt | Refinement | `dbg`, `info`, `warn`, `err`, `fatal`, `unk` |
54
68
 
55
- #### LambdaExt
69
+ ### Method List
56
70
 
57
- When you see: `irb(main):001>`, we can start operating.
71
+ #### Loggable & LogExt
58
72
 
59
- ```ruby
60
- irb(main):001> require 'sinlog'
73
+ * `log_dbg` – DEBUG
74
+ * `log_info` – INFO
75
+ * `log_warn` – WARN
76
+ * `log_err` – ERROR
77
+ * `log_fatal` – FATAL
78
+ * `log_unk` – UNKNOWN
61
79
 
62
- irb(main):002> include Sinlog::LambdaExt
63
- # It provides: dbg, info, warning, err, fatal, unk
64
- # We can call them using .tap(&dbg) or .then(&dbg).
80
+ #### LogShortExt
65
81
 
66
- irb(main):003> 'debug'.tap(&dbg)
67
- irb(main):004> 'information'.tap(&info)
82
+ `LogShortExt` works the same way as `LogExt`, except for method naming:
68
83
 
69
- # Note: Creating a warn method will cause issues with irb's auto-completion.
70
- # Therefore, LambdaExt uses warning instead of warn.
71
- # If you really need warn, then call include Sinlog::LambdaWarnExt
72
- irb(main):005> 'warning'.tap(&warning)
84
+ - `LogExt` methods use the `log_` prefix.
85
+ - `LogShortExt` methods do not.
73
86
 
74
- irb(main):006> 'error'.tap(&err)
75
- irb(main):007> 'fatal'.tap(&fatal)
76
- irb(main):008> 'unknown'.tap(&unk)
77
- ```
87
+ ---
78
88
 
79
- <img src="../assets/img/LambdaExt.jpg" alt="LambdaExt" style="width: 50%; height: 50%">
89
+ - `dbg` – DEBUG
90
+ - `info` – INFO
91
+ - `warn` – WARN
92
+ - `err` – ERROR
93
+ - `fatal` – FATAL
94
+ - `unk` – UNKNOWN
80
95
 
81
- LambdaExt provides:
96
+ > ⚠️ Note: `LogShortExt` defines a `warn` method, which overrides Ruby’s built-in `warn`.
97
+ > If you need to call the original `warn "msg"`, use `Kernel.warn "msg"` instead.
98
+ >
99
+ > If this is a concern, use `using Sinlog::LogExt` instead of `using Sinlog::LogShortExt`.
82
100
 
83
- - dbg
84
- - info
85
- - warning
86
- - wng (same as warning, just a different name)
87
- - err
88
- - fatal
89
- - unk
101
+ ### Examples
90
102
 
91
- #### LogLambdaExt
103
+ #### Classic Method Call (Neither Mixin nor Refinement)
92
104
 
93
- There is a module very similar to LambdaExt called LogLambdaExt.
94
- The main difference between them is the naming of the lambda functions.
105
+ ```ruby
106
+ require 'sinlog'
95
107
 
96
- - LogLambdaExt has a `log_` prefix
97
- - LambdaExt does not
108
+ log = Sinlog.logger
109
+ log.info "Information"
110
+ log.debug "This is a debug message"
111
+ ```
98
112
 
99
- LambdaExt and LogLambdaExt can be included simultaneously, but in general, including one of them is sufficient.
113
+ #### Mixin
100
114
 
101
- Which one is better?
115
+ ```ruby
116
+ require 'sinlog'
117
+ include Sinlog::Loggable
118
+ "Hello".log_info
119
+ ```
102
120
 
103
- Let's try them out to understand the differences and choose the one we prefer.
121
+ #### Refinement
104
122
 
105
123
  ```ruby
106
- irb(main):009> include Sinlog::LogLambdaExt
107
- # It provides log_dbg, log_info, log_warn, log_err, log_fatal, log_unk
108
- # We can call them using .tap(&log_dbg) or .then(&log_dbg).
109
-
110
- irb(main):010> "debug".tap(&log_dbg)
111
- irb(main):011> "information".tap(&log_info)
124
+ require 'sinlog'
125
+ using Sinlog::LogExt
126
+ { dir: "/path/to/xx" }.log_info
127
+ ```
112
128
 
113
- # Note: Here we use log_warn, not log_warning
114
- irb(main):012> "warning".tap(&log_warn)
129
+ ## Learn Sinlog API by Example
115
130
 
116
- irb(main):013> "error".tap(&log_err)
117
- irb(main):014> "fatal".tap(&log_fatal)
118
- irb(main):015> "unknown".tap(&log_unk)
119
- ```
131
+ <img src="../assets/img/preview.png" alt="preview">
120
132
 
121
133
  ```ruby
122
- # Here is a more complex example
123
- irb(main):016> require 'pathname'
124
-
125
- irb(main):017> Pathname('lib/lambda.rb').tap do
126
- "Filename: #{it}".then(&log_info)
127
- "size: #{
128
- it
129
- .tap{ '⚠️ Getting file size might fail'.then(&log_warn) }
130
- .size
131
- }".then(&log_info)
132
- end
133
- ```
134
+ require 'sinlog'
134
135
 
135
- <img src="../assets/img/LogLambdaExt.jpg" alt="LogLambdaExt" style="width: 90%; height: 90%">
136
+ class A
137
+ using Sinlog::LogShortExt
136
138
 
137
- LogLambdaExt provides:
139
+ def self.log
140
+ 'Hello, this is a debug message.'.dbg
141
+ 'Just some info.'.info
138
142
 
139
- - log_dbg
140
- - log_info
141
- - log_warn
142
- - log_warning (same as log_warn, just a different name)
143
- - log_wng (same as log_warn, just a different name)
144
- - log_err
145
- - log_fatal
146
- - log_unk
143
+ 'FBI, open the door!'.warn
144
+ { error: "IO", type: "InvalidData" }.err
145
+ 'Error occurred, continuing may break things.'.err
146
+ 'Bzzzz... it is bro...ken...nnn~'.fatal
147
+ end
148
+ end
147
149
 
148
- ### Classic Method Call
150
+ Sinlog::LV[:info].then do
151
+ Sinlog.logger_with_level it
152
+ end
153
+
154
+ A.log
155
+ ```
149
156
 
150
- If you don't like lambdas, you can try the classic method call!
157
+ ### Classic Method Call
151
158
 
152
- First, run `irb` to enter the Ruby REPL, then follow these steps:
159
+ If you prefer the traditional style (`log.info(msg)` instead of `msg.info`):
153
160
 
154
161
  ```ruby
155
- irb(main):001> require 'sinlog'
162
+ require 'sinlog'
156
163
 
157
- irb(main):002> log = Sinlog.instance.logger
164
+ log = Sinlog.logger
158
165
 
159
- irb(main):003> log.debug 'debug'
160
- irb(main):004> log.info 'information'
161
- irb(main):005> log.warn 'warning'
162
- irb(main):006> log.error 'error'
163
- irb(main):007> log.fatal 'fatal'
164
- irb(main):008> log.unknown 'unknown'
166
+ log.debug 'debug'
167
+ log.info 'information'
168
+ log.warn 'warning'
169
+ log.error 'error'
170
+ log.fatal 'fatal'
171
+ log.unknown 'unknown'
165
172
  ```
166
173
 
167
- Sinlog.instance.logger provides methods from Ruby's standard library logger.
174
+ > The data type of `Sinlog.logger` is Rubys standard library `Logger`.
168
175
 
169
- The most common ones are:
176
+ In addition to the common methods listed above, you can also use other methods such as `.reopen`.
177
+ For details, see <https://docs.ruby-lang.org/en/3.4/Logger.html>
170
178
 
171
- - debug
172
- - info
173
- - warn
174
- - error
175
- - fatal
176
- - unknown
179
+ - `debug`
180
+ - `info`
181
+ - `warn`
182
+ - `error`
183
+ - `fatal`
184
+ - `unknown`
177
185
 
178
186
  ## Advanced
179
187
 
180
- After trying it out ourselves, we have a basic understanding of `sinlog`.
188
+ After trying it out ourselves, we have a basic understanding of `sinlog`.
181
189
  In most cases, knowing its basic usage is sufficient.
182
190
 
183
191
  If you're interested, let's continue exploring together.
@@ -192,7 +200,7 @@ require 'sinlog'
192
200
  class EpubProcessor
193
201
  def initialize(epub_file, logger = nil)
194
202
  @epub = epub_file
195
- @logger = logger || Sinlog.instance.tap { it.fetch_env_and_update_log_level("XX_LOG") }.logger
203
+ @logger = logger || Sinlog.instance.tap { it.set_level_from_env!("XX_LOG") }.logger
196
204
  @logger.debug "EpubProcessor class initialization completed."
197
205
  end
198
206
  end
@@ -220,9 +228,11 @@ p Sinlog::LV
220
228
  # => {debug: 0, info: 1, warn: 2, error: 3, fatal: 4, unknown: 5}
221
229
 
222
230
  # Change the log level to warn
223
- log = Sinlog.instance.logger.tap { it.level = Sinlog::LV[:warn] }
224
- # Or:
225
- # log = Sinlog.instance.logger.tap { it.level = 2 }
231
+ log = Sinlog.logger_with_level(Sinlog::LV[:warn])
232
+ # OR:
233
+ # log = Sinlog.logger.tap { it.level = Sinlog::LV[:warn] }
234
+ # OR:
235
+ # log = Sinlog.instance.logger.tap { it.level = 2 }
226
236
 
227
237
  log.error "This message will be displayed! Lower level WARN (2) will display higher level ERROR (3) logs."
228
238
  log.info "This message will not be displayed! Higher level WARN (2) will not display lower level INFO (1) logs."
@@ -234,14 +244,14 @@ log.info "This message will not be displayed! Higher level WARN (2) will not dis
234
244
 
235
245
  ### Environment Variables
236
246
 
237
- In the real world, for client applications, the end users are typically regular users.
247
+ In the real world, for client applications, the end users are typically regular users.
238
248
  To allow them to configure `log.level` directly, we can use environment variables.
239
249
 
240
250
  > Using environment variables is simple and efficient.
241
251
 
242
252
  By default, Sinlog will attempt to read the value of the environment variable `RUBY_LOG`.
243
253
 
244
- It essentially calls the function `fetch_env_and_update_log_level(env_name = 'RUBY_LOG')`.
254
+ It essentially calls the function `set_level_from_env!(env_name = 'RUBY_LOG')`.
245
255
 
246
256
  - If the environment variable does not exist, it uses `debug(0)`.
247
257
  - If the environment variable exists but is empty, it uses `unknown(5)`.
@@ -265,7 +275,7 @@ export XX_CLI_LOG=info
265
275
  Ruby:
266
276
 
267
277
  ```ruby
268
- logger = Sinlog.instance.tap { it.fetch_env_and_update_log_level("XX_CLI_LOG") }.logger
278
+ logger = Sinlog.instance.tap { it.set_level_from_env!("XX_CLI_LOG") }.logger
269
279
 
270
280
  logger.debug "This message will not be displayed because the current log level is INFO(1)."
271
281
  logger.info "Hello!"
@@ -275,11 +285,11 @@ logger.info "Hello!"
275
285
 
276
286
  By default, Sinlog outputs to `STDERR`.
277
287
 
278
- If you need to customize the log output path, you can call the logger's `reopen` method.
288
+ If you need to customize the log output path, you can call the Logger's `reopen` method.
279
289
 
280
290
  ```ruby
281
291
  # Logs will be output to the file a.log
282
- log = Sinlog.instance.logger.tap { it.reopen("a.log") }
292
+ log = Sinlog.logger.tap { it.reopen("a.log") }
283
293
 
284
294
  log.error "What happened! QuQ"
285
295
  ```
@@ -287,7 +297,7 @@ log.error "What happened! QuQ"
287
297
  OR:
288
298
 
289
299
  ```ruby
290
- log = Sinlog.instance.logger
300
+ log = Sinlog.logger
291
301
  log.reopen("a.log")
292
302
 
293
303
  log.error "What happened! QuQ"
@@ -305,9 +315,27 @@ Modifying Sinlog in class A of the same program will affect Sinlog in class B.
305
315
 
306
316
  ## Side Note
307
317
 
308
- This is the first Ruby gem I have released.
318
+ This is the first Ruby gem I have released.
309
319
  The API might not fully adhere to idiomatic Ruby usage, so I appreciate your understanding.
310
320
 
321
+ ## Changelog
322
+
323
+ ### 0.0.3
324
+
325
+ - `Sinlog.instance.logger` can be simplified => `Sinlog.logger`
326
+
327
+ - add `Sinlog.logger_with_level`
328
+ - e.g., `logger = Sinlog.logger_with_level(Sinlog::LV[:warn])`
329
+ - old: `Sinlog.instance.logger.tap { it.level = Sinlog::LV[:warn] }`
330
+
331
+ - add `LogExt`, `LogShortExt` and `Loggleable`
332
+
333
+ - add sorbet **.rbi** files
334
+
335
+ Breaking changes:
336
+ - `fetch_env_and_update_log_level(ENV_NAME)` => `set_level_from_env!(ENV_NAME)`
337
+ - remove `LogLambdaExt` and related modules
338
+
311
339
  ## License
312
340
 
313
341
  [MIT License](../License)
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'singleton'
4
+ require 'logger'
5
+
3
6
  # Logger Singleton Class
4
7
  class Sinlog
5
8
  include Singleton
@@ -27,9 +30,9 @@ class Sinlog
27
30
 
28
31
  # Example:
29
32
  #
30
- # logger = Sinlog.instance.logger
31
- # logger.info "Information"
32
- # logger.debug "This is a debug message"
33
+ # logger = Sinlog.instance.logger
34
+ # logger.info "Information"
35
+ # logger.debug "This is a debug message"
33
36
  #
34
37
  # The log output format will be similar to:
35
38
  #
@@ -42,7 +45,7 @@ class Sinlog
42
45
  # If this variable is not set, the default level is DEBUG.
43
46
  def initialize
44
47
  @logger = Logger.new($stderr)
45
- fetch_env_and_update_log_level
48
+ set_level_from_env!
46
49
  @logger.formatter = proc do |severity, datetime, progname, msg|
47
50
  color = COLORS[severity.downcase.to_sym]
48
51
  reset = COLORS[:unknown]
@@ -52,6 +55,20 @@ class Sinlog
52
55
  end
53
56
  end
54
57
 
58
+ def self.logger
59
+ instance.logger
60
+ end
61
+
62
+ # Example:
63
+ #
64
+ # require 'sinlog'
65
+ # dbg_logger = Sinlog.with_level(Sinlog::LV[:debug])
66
+ # dbg_logger.info "This is an info message"
67
+ # dbg_logger.debug "This is a debug message"
68
+ def self.logger_with_level(level = LV[:warn])
69
+ instance.logger.tap { _1.level = level }
70
+ end
71
+
55
72
  # Set the `@logger.level` (**log level**) based on the value of an environment variable.
56
73
  #
57
74
  # If env_name is not specified, it reads the value of the `RUBY_LOG` environment variable.
@@ -64,13 +81,12 @@ class Sinlog
64
81
  #
65
82
  # Example:
66
83
  #
67
- # ENV["XX_LOG"] = "info" # or setenv in posix-sh: export XX_LOG=info
68
- #
69
- # logger = Sinlog.instance.tap { it.fetch_env_and_update_log_level("XX_LOG") }.logger
84
+ # ENV["XX_LOG"] = "info" # or setenv in posix-sh: export XX_LOG=info
85
+ # logger = Sinlog.instance.tap { it.set_level_from_env!("XX_LOG") }.logger
70
86
  #
71
- # logger.debug "This message will not be displayed because the current log level is info"
72
- # logger.info "Hello!"
73
- def fetch_env_and_update_log_level(env_name = 'RUBY_LOG')
87
+ # logger.debug "This message will not be displayed because the current log level is info"
88
+ # logger.info "Hello!"
89
+ def set_level_from_env!(env_name = 'RUBY_LOG')
74
90
  env_lv = ENV[env_name]&.downcase&.to_sym || :debug
75
91
 
76
92
  (LV[env_lv] || Logger::UNKNOWN)
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Sinlog
4
+ # LogExt is a Refinement that adds convenient logging methods to all objects.
5
+ #
6
+ # When activated with `using Sinlog::LogExt`, any object can call:
7
+ #
8
+ # == Overview
9
+ #
10
+ # * `log_dbg` – Logs the object at DEBUG level
11
+ # * `log_info` – Logs the object at INFO level
12
+ # * `log_warn` – Logs the object at WARN level
13
+ # * `log_err` – Logs the object at ERROR level
14
+ # * `log_fatal` – Logs the object at FATAL level
15
+ # * `log_unk` – Logs the object at UNKNOWN level
16
+ #
17
+ # == Example
18
+ #
19
+ # require 'sinlog'
20
+ #
21
+ # class A
22
+ # using Sinlog::LogExt
23
+ # def demo
24
+ # "Something happened".log_warn
25
+ # end
26
+ # end
27
+ #
28
+ module LogExt
29
+ # Logs the current object at *debug* level using Sinlog.logger
30
+ refine Object do
31
+ def log_dbg
32
+ Sinlog.logger.debug(self)
33
+ end
34
+ end
35
+
36
+ # Logs the current object at *information* level using Sinlog.logger
37
+ refine Object do
38
+ # logger.info
39
+ def log_info
40
+ Sinlog.logger.info(self)
41
+ end
42
+ end
43
+
44
+ # Logs the current object at *warning* level using Sinlog.logger
45
+ refine Object do
46
+ def log_warn
47
+ Sinlog.logger.warn(self)
48
+ end
49
+ end
50
+
51
+ # Logs the current object at *error* level using Sinlog.logger
52
+ refine Object do
53
+ def log_err
54
+ Sinlog.logger.error(self)
55
+ end
56
+ end
57
+
58
+ # Logs the current object at *fatal* level using Sinlog.logger
59
+ refine Object do
60
+ def log_fatal
61
+ Sinlog.logger.fatal(self)
62
+ end
63
+ end
64
+
65
+ # Logs the current object at *unknown* level using Sinlog.logger
66
+ refine Object do
67
+ def log_unk
68
+ Sinlog.logger.unknown(self)
69
+ end
70
+ end
71
+
72
+ # -----
73
+ end
74
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Sinlog
4
+ # LogShortExt is a Refinement that adds convenient logging methods to all objects.
5
+ #
6
+ # Similar to LogExt, but methods omit the `log_` prefix.
7
+ #
8
+ # For example:
9
+ # * `"msg".err` instead of `"msg".log_err`;
10
+ # * `"msg".warn` instead of `"msg".log_warn`
11
+ #
12
+ # When activated with `using Sinlog::LogShortExt`, any object can call:
13
+ #
14
+ # == Overview
15
+ #
16
+ # * `dbg` – Logs the object at DEBUG level
17
+ # * `info` – Logs the object at INFO level
18
+ # * `warn` – Logs the object at WARN level
19
+ # * `err` – Logs the object at ERROR level
20
+ # * `fatal` – Logs the object at FATAL level
21
+ # * `unk` – Logs the object at UNKNOWN level
22
+ #
23
+ # == Example
24
+ #
25
+ # require 'sinlog'
26
+ #
27
+ # class A
28
+ # using Sinlog::LogShortExt
29
+ #
30
+ # def demo
31
+ # "Something happened".warn
32
+ # end
33
+ # end
34
+ #
35
+ module LogShortExt
36
+ # Logs the current object at *debug* level using Sinlog.logger
37
+ refine Object do
38
+ def dbg
39
+ Sinlog.logger.debug(self)
40
+ end
41
+ end
42
+
43
+ # Logs the current object at *information* level using Sinlog.logger
44
+ refine Object do
45
+ # logger.info
46
+ def info
47
+ Sinlog.logger.info(self)
48
+ end
49
+ end
50
+
51
+ # Logs the current object at *warning* level using Sinlog.logger
52
+ refine Object do
53
+ def warn
54
+ Sinlog.logger.warn(self)
55
+ end
56
+ end
57
+
58
+ # Logs the current object at *error* level using Sinlog.logger
59
+ refine Object do
60
+ def err
61
+ Sinlog.logger.error(self)
62
+ end
63
+ end
64
+
65
+ # Logs the current object at *fatal* level using Sinlog.logger
66
+ refine Object do
67
+ def fatal
68
+ Sinlog.logger.fatal(self)
69
+ end
70
+ end
71
+
72
+ # Logs the current object at *unknown* level using Sinlog.logger
73
+ refine Object do
74
+ def unk
75
+ Sinlog.logger.unknown(self)
76
+ end
77
+ end
78
+
79
+ # -----
80
+ end
81
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Sinlog
4
+ # Provides logging helpers for any object.
5
+ #
6
+ # == Overview
7
+ #
8
+ # * `log_dbg` – Logs the object at DEBUG level
9
+ # * `log_info` – Logs the object at INFO level
10
+ # * `log_warn` – Logs the object at WARN level
11
+ # * `log_err` – Logs the object at ERROR level
12
+ # * `log_fatal` – Logs the object at FATAL level
13
+ # * `log_unk` – Logs the object at UNKNOWN level
14
+ #
15
+ # == Example
16
+ #
17
+ # require 'sinlog'
18
+ #
19
+ # include Sinlog::Loggleable
20
+ #
21
+ # "A debug message".log_dbg
22
+ # "Hello, world".log_info
23
+ #
24
+ module Loggleable
25
+ # Logs the current object at *debug* level using Sinlog.logger
26
+ def log_dbg
27
+ Sinlog.logger.debug(self)
28
+ end
29
+
30
+ # Logs the current object at *information* level using Sinlog.logger
31
+ # logger.info
32
+ def log_info
33
+ Sinlog.logger.info(self)
34
+ end
35
+
36
+ # Logs the current object at *warning* level using Sinlog.logger
37
+ def log_warn
38
+ Sinlog.logger.warn(self)
39
+ end
40
+
41
+ # Logs the current object at *error* level using Sinlog.logger
42
+ def log_err
43
+ Sinlog.logger.error(self)
44
+ end
45
+
46
+ # Logs the current object at *fatal* level using Sinlog.logger
47
+ def log_fatal
48
+ Sinlog.logger.fatal(self)
49
+ end
50
+
51
+ # Logs the current object at *unknown* level using Sinlog.logger
52
+ def log_unk
53
+ Sinlog.logger.unknown(self)
54
+ end
55
+ # -----
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Sinlog
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end