lumberjack 1.2.8 → 1.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +152 -58
  3. data/README.md +35 -6
  4. data/VERSION +1 -1
  5. data/lib/lumberjack/context.rb +13 -0
  6. data/lib/lumberjack/device/date_rolling_log_file.rb +10 -1
  7. data/lib/lumberjack/device/log_file.rb +8 -1
  8. data/lib/lumberjack/device/multi.rb +2 -1
  9. data/lib/lumberjack/device/null.rb +1 -1
  10. data/lib/lumberjack/device/rolling_log_file.rb +22 -22
  11. data/lib/lumberjack/device/size_rolling_log_file.rb +1 -1
  12. data/lib/lumberjack/device/writer.rb +21 -1
  13. data/lib/lumberjack/device.rb +16 -1
  14. data/lib/lumberjack/formatter/date_time_formatter.rb +2 -1
  15. data/lib/lumberjack/formatter/exception_formatter.rb +4 -2
  16. data/lib/lumberjack/formatter/id_formatter.rb +2 -1
  17. data/lib/lumberjack/formatter/inspect_formatter.rb +1 -1
  18. data/lib/lumberjack/formatter/object_formatter.rb +1 -1
  19. data/lib/lumberjack/formatter/pretty_print_formatter.rb +3 -1
  20. data/lib/lumberjack/formatter/string_formatter.rb +1 -1
  21. data/lib/lumberjack/formatter/strip_formatter.rb +1 -1
  22. data/lib/lumberjack/formatter/structured_formatter.rb +3 -1
  23. data/lib/lumberjack/formatter/truncate_formatter.rb +27 -0
  24. data/lib/lumberjack/formatter.rb +55 -9
  25. data/lib/lumberjack/log_entry.rb +10 -2
  26. data/lib/lumberjack/logger.rb +141 -18
  27. data/lib/lumberjack/rack/context.rb +1 -1
  28. data/lib/lumberjack/rack/request_id.rb +1 -1
  29. data/lib/lumberjack/rack/unit_of_work.rb +1 -1
  30. data/lib/lumberjack/rack.rb +1 -1
  31. data/lib/lumberjack/severity.rb +21 -1
  32. data/lib/lumberjack/tag_formatter.rb +19 -0
  33. data/lib/lumberjack/tagged_logger_support.rb +1 -1
  34. data/lib/lumberjack/tags.rb +6 -0
  35. data/lib/lumberjack/template.rb +15 -3
  36. data/lib/lumberjack.rb +20 -2
  37. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7912cf1bfe32dcaa911a6a65a0b755fb3051eebc2a7e4a65ff5d422f2f61ad7
4
- data.tar.gz: b4077d2ef97be7169ed0e7bca7d107ec3f42372dde45cae1e7cdcedae1fb4e61
3
+ metadata.gz: f5ab13ef762e8cdcb989ce1937c117fdbf938edc723c48f338b74edcd5d8e776
4
+ data.tar.gz: a003d08ef71531551083e4794807d3469fd9691abdc0686e5cc36e6859199922
5
5
  SHA512:
6
- metadata.gz: a092775aec0c7670eda8ff4959a7cc928a57b0934ecc8a1190efe395b437bc0a681bdbd2f3455b98f3cf757904f5f39b31c96e24e9c8bcd7a481b806027e92c8
7
- data.tar.gz: 885f76da2738f3f6236a363d9a7dea68f83a80a03e123a3c52c578984f963e959de6fd60d0fd222d9a9933c22ed959181538abb4118163c8fd6528292e88673c
6
+ metadata.gz: b0b527513bd37ca507bfe63c83cd00831f544a9ecdcedc13aeb566a3e74ae4ff0469eefed220da79c7cbeb385aa0fcff249b2480d74c95a1ff21899a8e723afb
7
+ data.tar.gz: 109411706ed4976f9711d6fcc17dd93bd7700cf72e01f40eaadba5701284e4175aa3791a311a19ab78eaedc34270ff9b16cd4ca394bb01a90b6c29d8e295f8e0
data/CHANGELOG.md CHANGED
@@ -1,129 +1,223 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 1.2.10
8
+
9
+ ### Added
10
+
11
+ - Added `with_level` method for compatibility with the latest standard library logger gem.
12
+
13
+ ### Fixed
14
+
15
+ - Fixed typo in magic frozen string literal comments. (thanks @andyw8 and @steveclarke)
16
+
17
+ ## 1.2.9
18
+
19
+ ### Added
20
+
21
+ - Allow passing in formatters as class names when adding them.
22
+ - Allow passing in formatters initialization arguments when adding them.
23
+ - Add truncate formatter for capping the length of log messages.
24
+
1
25
  ## 1.2.8
2
26
 
3
- * Add `Logger#untagged` to remove previously set logging tags from a block.
4
- * Return result of the block when a block is passed to `Logger#tag`.
27
+ ### Added
28
+
29
+ - Add `Logger#untagged` to remove previously set logging tags from a block.
30
+ - Return result of the block when a block is passed to `Logger#tag`.
5
31
 
6
32
  ## 1.2.7
7
33
 
8
- * Allow passing frozen hashes to `Logger#tag`. Tags passed to this method are now duplicated so the logger maintains it's own copy of the hash.
34
+ ### Fixed
35
+
36
+ - Allow passing frozen hashes to `Logger#tag`. Tags passed to this method are now duplicated so the logger maintains it's own copy of the hash.
9
37
 
10
38
  ## 1.2.6
11
39
 
12
- * Fix `Logger#tag` so it only ads to the current block's logger tags instead of the global tags if called inside a `Logger#tag` block.
13
- * Add Logger#remove_tag
40
+ ### Added
41
+
42
+ - Add Logger#remove_tag
43
+
44
+ ### Fixed
45
+
46
+ - Fix `Logger#tag` so it only ads to the current block's logger tags instead of the global tags if called inside a `Logger#tag` block.
47
+
14
48
 
15
49
  ## 1.2.5
16
50
 
17
- * Fix logic with recursive reference guard in StructuredFormatter so it only suppresses Enumerable references.
18
- * Add support for bang methods (error!) for setting the log level.
51
+ ### Added
52
+
53
+ - Add support for bang methods (error!) for setting the log level.
54
+
55
+ ### Fixed
56
+
57
+ - Fixed logic with recursive reference guard in StructuredFormatter so it only suppresses Enumerable references.
19
58
 
20
59
  ## 1.2.4
21
60
 
22
- * Enhance `ActiveSupport::TaggedLogging` support so code that Lumberjack loggers can be wrapped with a tagged logger.
61
+ ### Added
62
+
63
+ - Enhance `ActiveSupport::TaggedLogging` support so code that Lumberjack loggers can be wrapped with a tagged logger.
23
64
 
24
65
  ## 1.2.3
25
66
 
26
- * Fix structured formatter so no-recursive, duplicate references are allowed.
67
+ ### Fixed
68
+
69
+ - Fix structured formatter so no-recursive, duplicate references are allowed.
27
70
 
28
71
  ## 1.2.2
29
72
 
30
- * Prevent infinite loops in the structured formatter where objects have backreferences to each other.
73
+ ### Fixed
74
+
75
+ - Prevent infinite loops in the structured formatter where objects have backreferences to each other.
31
76
 
32
77
  ## 1.2.1
33
78
 
34
- * Prevent infinite loops where logging a statement triggers the logger.
79
+ ### Fixed
80
+
81
+ - Prevent infinite loops where logging a statement triggers the logger.
35
82
 
36
83
  ## 1.2.0
37
84
 
38
- * Enable compatibility with `ActiveSupport::TaggedLogger` by calling `tagged_logger!` on a logger.
39
- * Add `tag_formatter` to logger to specify formatting of tags for output.
40
- * Allow adding and removing classes by name to formatters.
41
- * Allow adding and removing multiple classes in a single call to a formatter.
42
- * Allow using symbols and strings as log level for silencing a logger.
43
- * Ensure flusher thread gets stopped when logger is closed.
44
- * Add writer for logger device attribute.
45
- * Handle passing an array of devices to a multi device.
46
- * Helper method to get a tag with a specified name.
47
- * Add strip formatter to strip whitespace from strings.
48
- * Support non-alpha numeric characters in template variables.
49
- * Add backtrace cleaner to ExceptionFormatter.
85
+ ### Added
86
+
87
+ - Enable compatibility with `ActiveSupport::TaggedLogger` by calling `tagged_logger!` on a logger.
88
+ - Add `tag_formatter` to logger to specify formatting of tags for output.
89
+ - Allow adding and removing classes by name to formatters.
90
+ - Allow adding and removing multiple classes in a single call to a formatter.
91
+ - Allow using symbols and strings as log level for silencing a logger.
92
+ - Ensure flusher thread gets stopped when logger is closed.
93
+ - Add writer for logger device attribute.
94
+ - Handle passing an array of devices to a multi device.
95
+ - Helper method to get a tag with a specified name.
96
+ - Add strip formatter to strip whitespace from strings.
97
+ - Support non-alpha numeric characters in template variables.
98
+ - Add backtrace cleaner to ExceptionFormatter.
50
99
 
51
100
  ## 1.1.1
52
101
 
53
- * Replace Procs in tag values with the value of calling the Proc in log entries.
102
+ ### Added
103
+
104
+ - Replace Procs in tag values with the value of calling the Proc in log entries.
54
105
 
55
106
  ## 1.1.0
56
107
 
57
- * Change `Lumberjack::Logger` to inherit from ::Logger
58
- * Add support for tags on log messages
59
- * Add global tag context for all loggers
60
- * Add per logger tags and tag contexts
61
- * Reimplement unit of work id as a tag on log entries
62
- * Add support for setting datetime format on log devices
63
- * Performance optimizations
64
- * Add Multi device to output to multiple devices
65
- * Add `DateTimeFormatter`, `IdFormatter`, `ObjectFormatter`, and `StructuredFormatter`
66
- * Add rack `Context` middleware for setting thread global context
67
- * End support for ruby versions < 2.3
68
- * Add support for modules in formatters
108
+ ### Added
109
+
110
+ - Change `Lumberjack::Logger` to inherit from ::Logger
111
+ - Add support for tags on log messages
112
+ - Add global tag context for all loggers
113
+ - Add per logger tags and tag contexts
114
+ - Reimplement unit of work id as a tag on log entries
115
+ - Add support for setting datetime format on log devices
116
+ - Performance optimizations
117
+ - Add Multi device to output to multiple devices
118
+ - Add `DateTimeFormatter`, `IdFormatter`, `ObjectFormatter`, and `StructuredFormatter`
119
+ - Add rack `Context` middleware for setting thread global context
120
+ - Add support for modules in formatters
121
+
122
+ ### Removed
123
+
124
+ - End support for ruby versions < 2.3
69
125
 
70
126
  ## 1.0.13
71
127
 
72
- * Reduce amount of code executed inside a mutex lock when writing to the logger stream.
73
- * Added `:min_roll_check` option to `Lumberjack::Device::RollingLogFile` to reduce file system checks. Default is now to only check if a file needs to be rolled at most once per second.
74
- * Force immutable strings for Ruby versions that support them.
128
+ ### Added
129
+
130
+ - Added `:min_roll_check` option to `Lumberjack::Device::RollingLogFile` to reduce file system checks. Default is now to only check if a file needs to be rolled at most once per second.
131
+ - Force immutable strings for Ruby versions that support them.
132
+
133
+ ### Changed
134
+
135
+ - Reduce amount of code executed inside a mutex lock when writing to the logger stream.
75
136
 
76
137
  ## 1.0.12
77
138
 
78
- * Add support for `ActionDispatch` request id for better Rails compatibility.
139
+ ### Added
140
+
141
+ - Add support for `ActionDispatch` request id for better Rails compatibility.
79
142
 
80
143
  ## 1.0.11
81
144
 
82
- * Fix Ruby 2.4 deprecation warning on Fixnum (thanks koic).
83
- * Fix gemspec files to be flat array (thanks e2).
145
+ ### Fixed
146
+
147
+ - Fix Ruby 2.4 deprecation warning on Fixnum (thanks @koic).
148
+ - Fix gemspec files to be flat array (thanks @e2).
84
149
 
85
150
  ## 1.0.10
86
151
 
87
- * Expose option to manually roll log files.
88
- * Minor code cleanup.
152
+ ### Added
153
+
154
+ - Expose option to manually roll log files.
155
+
156
+ ### Changed
157
+
158
+ - Minor code cleanup.
89
159
 
90
160
  ## 1.0.9
91
161
 
92
- * Add method so Formatter is compatible with `ActiveSupport` logging extensions.
162
+ ### Added
163
+
164
+ - Add method so Formatter is compatible with `ActiveSupport` logging extensions.
93
165
 
94
166
  ## 1.0.8
95
167
 
96
- * Fix another internal variable name conflict with `ActiveSupport` logging extensions.
168
+ ### Fixed
169
+
170
+ - Fix another internal variable name conflict with `ActiveSupport` logging extensions.
97
171
 
98
172
  ## 1.0.7
99
173
 
100
- * Fix broken formatter attribute method.
174
+ ### Fixed
175
+
176
+ - Fix broken formatter attribute method.
101
177
 
102
178
  ## 1.0.6
103
179
 
104
- * Fix internal variable name conflict with `ActiveSupport` logging extensions.
180
+ ### Fixed
181
+
182
+ - Fix internal variable name conflict with `ActiveSupport` logging extensions.
105
183
 
106
184
  ## 1.0.5
107
185
 
108
- * Update docs.
109
- * Remove autoload calls to make thread safe.
110
- * Make compatible with Ruby 2.1.1 Pathname.
111
- * Make compatible with standard library Logger's use of progname as default message.
186
+ ### Changed
187
+
188
+ - Update docs.
189
+ - Remove autoload calls to make thread safe.
190
+ - Make compatible with Ruby 2.1.1 Pathname.
191
+ - Make compatible with standard library Logger's use of progname as default message.
112
192
 
113
193
  ## 1.0.4
114
194
 
115
- * Add ability to supply a unit of work id for a block instead of having one generated every time.
195
+ ### Added
196
+
197
+ - Add ability to supply a unit of work id for a block instead of having one generated every time.
116
198
 
117
199
  ## 1.0.3
118
200
 
119
- * Change log file output format to binary to avoid encoding warnings.
120
- * Fixed bug in log file rolling that left the file locked.
201
+ ### Fixed
202
+
203
+ - Change log file output format to binary to avoid encoding warnings.
204
+ - Fixed bug in log file rolling that left the file locked.
121
205
 
122
206
  ## 1.0.2
123
207
 
124
- * Remove deprecation warnings under ruby 1.9.3.
125
- * Add more error checking around file rolling.
208
+ ### Fixed
209
+
210
+ - Remove deprecation warnings under ruby 1.9.3.
211
+ - Add more error checking around file rolling.
126
212
 
127
213
  ## 1.0.1
128
214
 
129
- * Writes are no longer buffered by default.
215
+ ### Fixed
216
+
217
+ - Writes are no longer buffered by default.
218
+
219
+ ## 1.0.0
220
+
221
+ ### Added
222
+
223
+ - Initial release
data/README.md CHANGED
@@ -1,14 +1,15 @@
1
- ![Continuous Integration](https://github.com/bdurand/lumberjack/workflows/Continuous%20Integration/badge.svg)
2
- [![Maintainability](https://api.codeclimate.com/v1/badges/a0abc03721fff9b0cde1/maintainability)](https://codeclimate.com/github/bdurand/lumberjack/maintainability)
3
- [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
4
-
5
1
  # Lumberjack
6
2
 
3
+ [![Continuous Integration](https://github.com/bdurand/lumberjack/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/bdurand/lumberjack/actions/workflows/continuous_integration.yml)
4
+ [![Regression Test](https://github.com/bdurand/lumberjack/actions/workflows/regression_test.yml/badge.svg)](https://github.com/bdurand/lumberjack/actions/workflows/regression_test.yml)
5
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
6
+ [![Gem Version](https://badge.fury.io/rb/lumberjack.svg)](https://badge.fury.io/rb/lumberjack)
7
+
7
8
  Lumberjack is a simple, powerful, and fast logging implementation in Ruby. It uses nearly the same API as the Logger class in the Ruby standard library and as ActiveSupport::BufferedLogger in Rails.
8
9
 
9
10
  ## Usage
10
11
 
11
- This code aims to be extremely simple to use. The core interface it the Lumberjack::Logger which is used to log messages (which can be any object) with a specified Severity. Each logger has a level associated with it and messages are only written if their severity is greater than or equal to the level.
12
+ This code aims to be extremely simple to use. The core interface is the Lumberjack::Logger which is used to log messages (which can be any object) with a specified Severity. Each logger has a level associated with it and messages are only written if their severity is greater than or equal to the level.
12
13
 
13
14
  ```ruby
14
15
  logger = Lumberjack::Logger.new("logs/application.log") # Open a new log file with INFO level
@@ -41,7 +42,7 @@ The following information is recorded for each message:
41
42
 
42
43
  ### Tags
43
44
 
44
- You can use tags to provide additional meta data about a log message or the context that the log message is being made in. Using tags can keep you log messages clean. You can avoid string interoplation to add additional meta data.
45
+ You can use tags to provide additional meta data about a log message or the context that the log message is being made in. Using tags can keep your log messages clean. You can avoid string interpolation to add additional meta data.
45
46
 
46
47
  Each of the logger methods includes an additional argument that can be used to specify tags on a messsage:
47
48
 
@@ -276,3 +277,31 @@ To send log messages to syslog instead of to a file, you could use this (require
276
277
  ```ruby
277
278
  config.logger = Lumberjack::Logger.new(Lumberjack::SyslogDevice.new)
278
279
  ```
280
+
281
+ ## Installation
282
+
283
+ Add this line to your application's Gemfile:
284
+
285
+ ```ruby
286
+ gem 'lumberjack'
287
+ ```
288
+
289
+ And then execute:
290
+ ```bash
291
+ $ bundle
292
+ ```
293
+
294
+ Or install it yourself as:
295
+ ```bash
296
+ $ gem install lumberjack
297
+ ```
298
+
299
+ ## Contributing
300
+
301
+ Open a pull request on GitHub.
302
+
303
+ Please use the [standardrb](https://github.com/testdouble/standard) syntax and lint your code with `standardrb --fix` before submitting.
304
+
305
+ ## License
306
+
307
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.8
1
+ 1.2.10
@@ -5,12 +5,16 @@ module Lumberjack
5
5
  class Context
6
6
  attr_reader :tags
7
7
 
8
+ # @param [Context] parent_context A parent context to inherit tags from.
8
9
  def initialize(parent_context = nil)
9
10
  @tags = {}
10
11
  @tags.merge!(parent_context.tags) if parent_context
11
12
  end
12
13
 
13
14
  # Set tags on the context.
15
+ #
16
+ # @param [Hash] tags The tags to set.
17
+ # @return [void]
14
18
  def tag(tags)
15
19
  tags.each do |key, value|
16
20
  @tags[key.to_s] = value
@@ -18,16 +22,25 @@ module Lumberjack
18
22
  end
19
23
 
20
24
  # Get a context tag.
25
+ #
26
+ # @param [String, Symbol] key The tag key.
27
+ # @return [Object] The tag value.
21
28
  def [](key)
22
29
  @tags[key.to_s]
23
30
  end
24
31
 
25
32
  # Set a context tag.
33
+ #
34
+ # @param [String, Symbol] key The tag key.
35
+ # @param [Object] value The tag value.
36
+ # @return [void]
26
37
  def []=(key, value)
27
38
  @tags[key.to_s] = value
28
39
  end
29
40
 
30
41
  # Clear all the context data.
42
+ #
43
+ # @return [void]
31
44
  def reset
32
45
  @tags.clear
33
46
  end
@@ -1,4 +1,4 @@
1
- # frozen_string_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  require "date"
4
4
 
@@ -13,6 +13,9 @@ module Lumberjack
13
13
  # Create a new logging device to the specified file. The period to roll the file is specified
14
14
  # with the :roll option which may contain a value of :daily, :weekly,
15
15
  # or :monthly.
16
+ #
17
+ # @param [String, Pathname] path The path to the log file.
18
+ # @param [Hash] options The options for the device.
16
19
  def initialize(path, options = {})
17
20
  @manual = options[:manual]
18
21
  @file_date = Date.today
@@ -25,6 +28,9 @@ module Lumberjack
25
28
  super
26
29
  end
27
30
 
31
+ # The date based suffix for file.
32
+ #
33
+ # @return [String]
28
34
  def archive_file_suffix
29
35
  case @roll_period
30
36
  when :weekly
@@ -36,6 +42,9 @@ module Lumberjack
36
42
  end
37
43
  end
38
44
 
45
+ # Check if the file should be rolled.
46
+ #
47
+ # @return [Boolean]
39
48
  def roll_file?
40
49
  if @manual
41
50
  true
@@ -1,4 +1,4 @@
1
- # frozen_string_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  require "fileutils"
4
4
 
@@ -12,12 +12,19 @@ module Lumberjack
12
12
  attr_reader :path
13
13
 
14
14
  # Create a logger to the file at +path+. Options are passed through to the Writer constructor.
15
+ #
16
+ # @param [String, Pathname] path The path to the log file.
17
+ # @param [Hash] options The options for the device.
15
18
  def initialize(path, options = {})
16
19
  @path = File.expand_path(path)
17
20
  FileUtils.mkdir_p(File.dirname(@path))
18
21
  super(file_stream, options)
19
22
  end
20
23
 
24
+ # Reopen the log file.
25
+ #
26
+ # @param [Object] logdev not used
27
+ # @return [void]
21
28
  def reopen(logdev = nil)
22
29
  close
23
30
  @stream = file_stream
@@ -1,9 +1,10 @@
1
- # frozen_string_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Lumberjack
4
4
  class Device
5
5
  # This is a logging device that forward log entries to multiple other devices.
6
6
  class Multi < Device
7
+ # @param [Array<Lumberjack::Device>] devices The devices to write to.
7
8
  def initialize(*devices)
8
9
  @devices = devices.flatten
9
10
  end
@@ -1,4 +1,4 @@
1
- # frozen_string_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Lumberjack
4
4
  class Device
@@ -1,4 +1,4 @@
1
- # frozen_string_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Lumberjack
4
4
  class Device
@@ -20,10 +20,10 @@ module Lumberjack
20
20
  @keep = options[:keep]
21
21
  super(path, options)
22
22
  @file_inode = begin
23
- stream.lstat.ino
24
- rescue
25
- nil
26
- end
23
+ stream.lstat.ino
24
+ rescue
25
+ nil
26
+ end
27
27
  @@rolls = []
28
28
  @next_stat_check = Time.now.to_f
29
29
  @min_roll_check = (options[:min_roll_check] || 1.0).to_f
@@ -42,15 +42,15 @@ module Lumberjack
42
42
 
43
43
  # Roll the log file by renaming it to the archive file name and then re-opening a stream to the log
44
44
  # file path. Rolling a file is safe in multi-threaded or multi-process environments.
45
- def roll_file! #:nodoc:
45
+ def roll_file! # :nodoc:
46
46
  do_once(stream) do
47
47
  archive_file = "#{path}.#{archive_file_suffix}"
48
48
  stream.flush
49
49
  current_inode = begin
50
- File.stat(path).ino
51
- rescue
52
- nil
53
- end
50
+ File.stat(path).ino
51
+ rescue
52
+ nil
53
+ end
54
54
  if @file_inode && current_inode == @file_inode && !File.exist?(archive_file) && File.exist?(path)
55
55
  begin
56
56
  File.rename(path, archive_file)
@@ -78,10 +78,10 @@ module Lumberjack
78
78
  if @min_roll_check <= 0.0 || Time.now.to_f >= @next_stat_check
79
79
  @next_stat_check += @min_roll_check
80
80
  path_inode = begin
81
- File.lstat(path).ino
82
- rescue
83
- nil
84
- end
81
+ File.lstat(path).ino
82
+ rescue
83
+ nil
84
+ end
85
85
  if path_inode != @file_inode
86
86
  @file_inode = path_inode
87
87
  reopen_file
@@ -98,10 +98,10 @@ module Lumberjack
98
98
  new_stream = File.open(path, "a", encoding: EXTERNAL_ENCODING)
99
99
  new_stream.sync = true if buffer_size > 0
100
100
  @file_inode = begin
101
- new_stream.lstat.ino
102
- rescue
103
- nil
104
- end
101
+ new_stream.lstat.ino
102
+ rescue
103
+ nil
104
+ end
105
105
  self.stream = new_stream
106
106
  old_stream.close
107
107
  end
@@ -127,10 +127,10 @@ module Lumberjack
127
127
  end
128
128
  begin
129
129
  verify = begin
130
- file.lstat
131
- rescue
132
- nil
133
- end
130
+ file.lstat
131
+ rescue
132
+ nil
133
+ end
134
134
  # Execute only if the file we locked is still the same one that needed to be rolled
135
135
  yield if verify && verify.ino == @file_inode && verify.size > 0
136
136
  ensure
@@ -1,4 +1,4 @@
1
- # frozen_string_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Lumberjack
4
4
  class Device
@@ -1,4 +1,4 @@
1
- # frozen_string_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Lumberjack
4
4
  class Device
@@ -60,6 +60,9 @@ module Lumberjack
60
60
  # work id will only appear if it is present.
61
61
  #
62
62
  # The size of the internal buffer in bytes can be set by providing :buffer_size (defaults to 32K).
63
+ #
64
+ # @param [IO] stream The stream to write log entries to.
65
+ # @param [Hash] options The options for the device.
63
66
  def initialize(stream, options = {})
64
67
  @lock = Mutex.new
65
68
  @stream = stream
@@ -77,12 +80,18 @@ module Lumberjack
77
80
 
78
81
  # Set the buffer size in bytes. The device will only be physically written to when the buffer size
79
82
  # is exceeded.
83
+ #
84
+ # @param [Integer] value The size of the buffer in bytes.
85
+ # @return [void]
80
86
  def buffer_size=(value)
81
87
  @buffer_size = value
82
88
  flush
83
89
  end
84
90
 
85
91
  # Write an entry to the stream. The entry will be converted into a string using the defined template.
92
+ #
93
+ # @param [LogEntry, String] entry The entry to write to the stream.
94
+ # @return [void]
86
95
  def write(entry)
87
96
  string = (entry.is_a?(LogEntry) ? @template.call(entry) : entry)
88
97
  return if string.nil?
@@ -105,12 +114,16 @@ module Lumberjack
105
114
  end
106
115
 
107
116
  # Close the underlying stream.
117
+ #
118
+ # @return [void]
108
119
  def close
109
120
  flush
110
121
  stream.close
111
122
  end
112
123
 
113
124
  # Flush the underlying stream.
125
+ #
126
+ # @return [void]
114
127
  def flush
115
128
  lines = nil
116
129
  @lock.synchronize do
@@ -120,10 +133,17 @@ module Lumberjack
120
133
  write_to_stream(lines) if lines
121
134
  end
122
135
 
136
+ # Get the datetime format.
137
+ #
138
+ # @return [String] The datetime format.
123
139
  def datetime_format
124
140
  @template.datetime_format if @template.respond_to?(:datetime_format)
125
141
  end
126
142
 
143
+ # Set the datetime format.
144
+ #
145
+ # @param [String] format The datetime format.
146
+ # @return [void]
127
147
  def datetime_format=(format)
128
148
  if @template.respond_to?(:datetime_format=)
129
149
  @template.datetime_format = format