lite_logger 0.1.7 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc0767fbf6ac0335c9837e6444668caf5882dfa7ac140552bcf6170c4b005689
4
- data.tar.gz: cfd5533a426c2762f8b9626bb405131853e197723561a8a3187e33eac3300874
3
+ metadata.gz: d602a3b8fc99ae133103a80f0433ae75b108c71cf09e4a139bc46ba3cc4476da
4
+ data.tar.gz: 200bc83513a92bf88b7a95b57f1a89e86847b20717e83a097fdc417577652224
5
5
  SHA512:
6
- metadata.gz: 4867f776609006ed5567edb328760b686328196d66651b06f9cec605081dc3eb3a37b86c22c7f55264f1294f8be5fcadffdebbd385de465e6b0b6caab60c0f7c
7
- data.tar.gz: a4462cb36487009bc994fb73fa3afc1945cb44ab33e6ed48f3e1ccc878ca1e653a1ce115b72183dc4d861240c838d9f1e6d04c0428653ab44b824bd28f48fb85
6
+ metadata.gz: 2c0328c6b5214b05f823f526d4d8228028b2ed2e3c2398efe54c4e8366927d7196ae4051ed03d29b08f5c932b8938f949df81f5219118e9c1dde38e167459d53
7
+ data.tar.gz: 5839ca20af83326d06e0f98923de9f217148fd8d399bc57d1f378654e57b288702a84d5e0793c5e102a137bed1eba9c6e4752aec8608214b54098e7b82d68da6
data/CHANGELOG.md CHANGED
@@ -40,3 +40,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
40
40
 
41
41
  - Small text fix in README.md
42
42
  - Remove unused file `all_changes.txt`
43
+
44
+ ## [0.1.8] - 2026-03-29
45
+
46
+ - Add optional custom formatter support for application-specific log output.
47
+ - Create parent directories automatically when logging to a file destination.
48
+ - Move development tools out of runtime dependencies.
49
+
50
+ ## [0.1.9] - 2026-03-29
51
+
52
+ - Expand the spec suite around global configuration, formatter errors, JSON timestamps, and append behavior.
53
+ - Refresh the README with examples for file logging, JSON output, custom formatters, and global configuration.
data/README.md CHANGED
@@ -28,17 +28,15 @@ gem install lite_logger
28
28
 
29
29
  ## Usage
30
30
 
31
- ### Example
31
+ ### Basic example
32
32
 
33
- #### In a Ruby class:
33
+ In a Ruby class:
34
34
 
35
35
  ```ruby
36
- # Require the gem
37
36
  require 'lite_logger'
38
37
 
39
38
  class MyClass
40
39
  def initialize
41
- # Initialize the logger
42
40
  @logger = LiteLogger::Logger.new
43
41
  end
44
42
 
@@ -49,19 +47,18 @@ class MyClass
49
47
  @logger.error('This is an error message')
50
48
  @logger.fatal('This is a fatal message')
51
49
 
52
- # [...]
53
50
  end
54
51
  end
55
52
  ```
56
53
 
57
- #### Logging to a file
54
+ ### Logging to a file
58
55
 
59
56
  ```ruby
60
57
  require 'lite_logger'
61
58
 
62
- @logger = LiteLogger::Logger.new
63
- @logger.destination = './application.log'
64
- @logger.info('Application started!')
59
+ logger = LiteLogger::Logger.new
60
+ logger.destination = './log/application.log'
61
+ logger.info('Application started!')
65
62
  ```
66
63
 
67
64
  Output:
@@ -70,6 +67,54 @@ Output:
70
67
  2024-07-10 18:58:07 -0300 [INFO] Application started!
71
68
  ```
72
69
 
70
+ Parent directories are created automatically when the destination is a file path.
71
+
72
+ ### JSON output
73
+
74
+ ```ruby
75
+ require 'lite_logger'
76
+
77
+ logger = LiteLogger::Logger.new
78
+ logger.format = :json
79
+ logger.info('Application started!')
80
+ ```
81
+
82
+ Example output:
83
+
84
+ ```json
85
+ {"level":"info","message":"Application started!","timestamp":"2026-03-29 21:00:00 -0300"}
86
+ ```
87
+
88
+ ### Custom formatter
89
+
90
+ Use `formatter` when you need full control over the rendered log line.
91
+
92
+ ```ruby
93
+ require 'lite_logger'
94
+ require 'time'
95
+
96
+ logger = LiteLogger::Logger.new
97
+ logger.destination = './log/custom.log'
98
+ logger.formatter = lambda do |level, message, time|
99
+ "[#{time.iso8601}] #{level.upcase}: #{message}"
100
+ end
101
+
102
+ logger.info('Application started!')
103
+ ```
104
+
105
+ ### Global configuration
106
+
107
+ ```ruby
108
+ require 'lite_logger'
109
+
110
+ LiteLogger.configure do |logger|
111
+ logger.level = :debug
112
+ logger.destination = './log/application.log'
113
+ end
114
+
115
+ LiteLogger.logger.info('Application started!')
116
+ ```
117
+
73
118
  ## Contributing
74
119
 
75
120
  Bug reports and pull requests are welcome: <https://github.com/dmferrari/lite_logger/pulls>.
@@ -1,15 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fileutils'
4
+ require 'json'
5
+
3
6
  module LiteLogger
4
7
  class Logger
5
8
  LEVELS = { debug: 0, info: 1, warn: 2, error: 3, fatal: 4 }.freeze
6
9
 
7
- attr_accessor :level, :format, :destination
10
+ attr_accessor :level, :format, :destination, :formatter
8
11
 
9
12
  def initialize
10
13
  @level = :info
11
14
  @format = :plain
12
15
  @destination = $stdout
16
+ @formatter = nil
13
17
  end
14
18
 
15
19
  LEVELS.each_key do |level_name|
@@ -29,6 +33,8 @@ module LiteLogger
29
33
 
30
34
  def format_message(level, message)
31
35
  current_time = Time.now
36
+ return @formatter.call(level, message, current_time) if @formatter
37
+
32
38
  case @format
33
39
  when :json
34
40
  { level: level, message: message, timestamp: current_time }.to_json
@@ -41,7 +47,10 @@ module LiteLogger
41
47
  case @destination
42
48
  when $stdout, $stderr
43
49
  @destination.puts message
50
+ when ->(destination) { destination.respond_to?(:puts) }
51
+ @destination.puts message
44
52
  else
53
+ FileUtils.mkdir_p(File.dirname(@destination))
45
54
  File.open(@destination, 'a') { |file| file.puts message }
46
55
  end
47
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LiteLogger
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.9'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Ferrari
@@ -16,7 +16,7 @@ dependencies:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
18
  version: '13.0'
19
- type: :runtime
19
+ type: :development
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
@@ -30,7 +30,7 @@ dependencies:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.0'
33
- type: :runtime
33
+ type: :development
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
@@ -44,7 +44,7 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.21'
47
- type: :runtime
47
+ type: :development
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements: