outland-tag_runes 1.1.0 → 1.1.1

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
  SHA1:
3
- metadata.gz: b0041da0204a138ad68c9b50d2e6d2184bbeca3b
4
- data.tar.gz: 9578c026b45fb7bd1f0342e901721d0310374e9f
3
+ metadata.gz: 482c914249f74c3904e253aa9ca61b6e93f41280
4
+ data.tar.gz: 9c8d5ee467fc04d8fdd03981ca7c2ea80304c763
5
5
  SHA512:
6
- metadata.gz: 7c5733c26df6dff47380d8a28cf4e16d65372b38a6d6cc93a6ebd41b5f378497adcf5d205d9b9b9d84b7efb4f204d45454943744cf47238de195ded4a0b64ad1
7
- data.tar.gz: 16f2176cc19f3810fdcae176a8ceb5b9c6d4000f6a9ae7ff2b2643c98d3ebaf29353bc6e24127e52b850e146a7cb6be3e3a42dee1a33174d88817c7d3ac45366
6
+ metadata.gz: 0cf599184e10e5f45a1289c7837d6863f12c0d969dce15285683bd4d33c91309703301daf9ca747520858793456d052f76becef17b255b075f30b4a90a0678fa
7
+ data.tar.gz: ceb4386d94be3d16c05dd7ee7cc8e20873a877e61c8947985bb0da6e6b8f6e8c432265dc7fb9ed9ad45c792fa4295788e1eb1a2bc4c682ea47b702437afadf28
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ **1.1.1** (February 27, 2017)
2
+
3
+ * Less intrusive method of controlling the RotationalLogs renaming pattern by using singleton classes on directly created objects rather than a general monkeypatch.
4
+
1
5
  **1.1** (February 27, 2017)
2
6
 
3
7
  * Rotational logger
@@ -0,0 +1,63 @@
1
+ module Outland
2
+ module TagRunes
3
+
4
+ # Not in fact a Logger, but a Logger manager that handles daily log rotation
5
+ # with a custom naming pattern.
6
+
7
+ class RotationalLogs
8
+
9
+ def initialize(opts={})
10
+ @base = opts[:base] || 'rails'
11
+ end
12
+
13
+ def customize_rename(logger)
14
+ # use singleton methods to pull out the internal LogDevice and then
15
+ # override its shift_log_period method, which does the daily renaming
16
+ # in a multi-process aware fashion (should be called only once per day per log).
17
+
18
+ class <<logger
19
+ attr_reader :logdev
20
+ end
21
+
22
+ logdev = logger.logdev
23
+
24
+ # Testing rotation
25
+ # class <<logdev
26
+ # attr_writer :next_rotate_time
27
+ # end
28
+ # logdev.next_rotate_time = Time.now + 10
29
+
30
+ class <<logdev
31
+
32
+ def shift_log_period(period_end)
33
+ super
34
+ log_dir = File.dirname(@filename)
35
+ return true unless File.directory?("#{log_dir}/rot") # standard behavior unless rot dir exists
36
+ Dir.glob("#{@filename}.*").each do |fn|
37
+ base = File.basename(fn).gsub(/\.log\.(\d\d\d\d)(\d\d)(\d\d)$/, '-\1-\2-\3.log')
38
+ File.rename fn, "#{log_dir}/rot/#{base}"
39
+ end
40
+ true
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ def set(config)
48
+ # Follows the pattern from the Rails generator for RAILS_LOG_TO_STDOUT
49
+ if Rails.env.development? || Rails.env.test?
50
+ logger = ActiveSupport::Logger.new(STDOUT)
51
+ else
52
+ logger = ActiveSupport::Logger.new("#{Rails.root}/log/#{@base}.log", 'daily')
53
+ customize_rename(logger)
54
+ end
55
+ logger.formatter = config.log_formatter
56
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
57
+ end
58
+
59
+ end
60
+
61
+
62
+ end
63
+ end
@@ -1,7 +1,7 @@
1
1
  module Outland
2
2
  module TagRunes
3
3
 
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.1"
5
5
 
6
6
  end
7
7
  end
@@ -1,5 +1,4 @@
1
- require 'outland/tag_runes/custom_log_renamer'
2
- require 'outland/tag_runes/rotational_logger'
1
+ require 'outland/tag_runes/rotational_logs'
3
2
  require 'outland/tag_runes/version'
4
3
 
5
4
  module Outland
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outland-tag_runes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill Lipa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-27 00:00:00.000000000 Z
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -68,8 +68,7 @@ files:
68
68
  - bin/console
69
69
  - bin/setup
70
70
  - lib/outland/tag_runes.rb
71
- - lib/outland/tag_runes/custom_log_renamer.rb
72
- - lib/outland/tag_runes/rotational_logger.rb
71
+ - lib/outland/tag_runes/rotational_logs.rb
73
72
  - lib/outland/tag_runes/version.rb
74
73
  - outland-tag_runes.gemspec
75
74
  homepage: https://github.com/outland/tag_runes
@@ -1,21 +0,0 @@
1
- class Logger
2
- class LogDevice
3
-
4
- private
5
-
6
- alias_method :orig_shift_log_period, :shift_log_period
7
-
8
- # Override the shift method to allow us to control the file name.
9
- def shift_log_period(period_end)
10
- orig_shift_log_period(period_end)
11
- log_dir = File.dirname(@filename)
12
- return true unless File.directory?("#{log_dir}/rot") # standard behavior unless rot dir exists
13
- Dir.glob("#{@filename}.*").each do |fn|
14
- base = File.basename(fn).gsub(/\.log\.(\d\d\d\d)(\d\d)(\d\d)$/, '-\1-\2-\3.log')
15
- File.rename fn, "#{log_dir}/rot/#{base}"
16
- end
17
- true
18
- end
19
-
20
- end
21
- end
@@ -1,21 +0,0 @@
1
- module Outland
2
- module TagRunes
3
-
4
-
5
- class RotationalLogger
6
-
7
- def self.set(config)
8
- logger = if Rails.env.development? || Rails.env.test?
9
- ActiveSupport::Logger.new(STDOUT)
10
- else
11
- ActiveSupport::Logger.new("#{Rails.root}/log/rails.log", 'daily')
12
- end
13
- logger.formatter = config.log_formatter
14
- config.logger = ActiveSupport::TaggedLogging.new(logger)
15
- end
16
-
17
- end
18
-
19
-
20
- end
21
- end