chrono_logger 0.0.5 → 1.1.2

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
- SHA1:
3
- metadata.gz: 08bc980d1aec36c6dd84be8aa0964a89f026357a
4
- data.tar.gz: 36c8767249f645a1cf6a491dd03a29e0e47a95bd
2
+ SHA256:
3
+ metadata.gz: ee8232f6e93fdb6766c7685404c008954c26570cc08ee7d9a26df0492b721ad3
4
+ data.tar.gz: 8c362f4ef826b32830a4326ee6929fc6731579cb0a55f871757fcc4233338ea2
5
5
  SHA512:
6
- metadata.gz: 364f9de5b3a3694e4e54d4dfa2a27511c6a0d18bbcb5186f69bf538503cd950fdd46ef35681f950ec8b158977103b3fa2f4496851f1b3939e75846d0a5a40ba9
7
- data.tar.gz: db43d8701920d88b5fa46e1b9ed3aeae4b6fa97f5b82aace8fc99431c0f64decb645a4a2953029d16ec146bab507c358423971c73acca6d2c232bc6407eb2495
6
+ metadata.gz: 60f8897ee73f13eedc17b65de6c0c64339827c6abd6b8892ed95a81ad24c50f3b346b5a4667f721a2c3183cefcd9384ca0f293623c1805befb1b863695976525
7
+ data.tar.gz: e4676e13ab6e54452249fa1e089d96e1d19a5d76c935ff8cc9945592b5f47a421ce6ecf7e833363dc3f408a94975bc178442dc97182e00908c792d491fec2455
@@ -0,0 +1,36 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+
15
+ jobs:
16
+ test:
17
+
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ ruby: [ '2.6', '2.7', '3.0', '3.1' ]
22
+
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - name: Set up Ruby
26
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
27
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby }}
31
+ - name: Install dependencies
32
+ run: |
33
+ bundle config path vendor/bundle
34
+ bundle install --jobs 4 --retry 3
35
+ - name: Run tests
36
+ run: bundle exec rake
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## 1.1.0 (2015-08-17)
4
+
5
+ * Enhancements
6
+ * strftime format for directory name
7
+
8
+ ```ruby
9
+ logger = ChronoLogger.new('%Y/%m/%d.log')
10
+ ```
11
+
12
+ ## 1.0.0 (2015-02-05)
13
+
14
+ * First Major Release
15
+
data/README.md CHANGED
@@ -1,11 +1,8 @@
1
1
  # ChronoLogger
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/chrono_logger.svg)](http://badge.fury.io/rb/chrono_logger)
4
- [![Build Status](https://travis-ci.org/ma2gedev/chrono_logger.svg)](https://travis-ci.org/ma2gedev/chrono_logger)
4
+ [![Build Status](https://github.com/ma2gedev/chrono_logger/workflows/Ruby/badge.svg?branch=master)](https://github.com/ma2gedev/chrono_logger/actions?query=workflow%3ARuby)
5
5
  [![Code Climate](https://codeclimate.com/github/ma2gedev/chrono_logger/badges/gpa.svg)](https://codeclimate.com/github/ma2gedev/chrono_logger)
6
- [![Coverage Status](https://coveralls.io/repos/ma2gedev/chrono_logger/badge.svg)](https://coveralls.io/r/ma2gedev/chrono_logger)
7
- [![Inline docs](http://inch-ci.org/github/ma2gedev/chrono_logger.svg?branch=master)](http://inch-ci.org/github/ma2gedev/chrono_logger)
8
- [![endorse](https://api.coderwall.com/ma2gedev/endorsecount.png)](https://coderwall.com/ma2gedev)
9
6
 
10
7
  A lock-free logger with timebased file rotation.
11
8
 
@@ -33,8 +30,8 @@ File.exist?('/log/production.log.20150127')
33
30
  Current my projects uses `::Logger` with cronolog. So
34
31
 
35
32
  - Reduce dependency such as cronolog
36
- - Remove mutexes in ruby world because os already does
37
- - Support time based rotation without renaming file because file renaming is complex
33
+ - Remove mutexes in ruby world because os already does when some environments (ex: ext4 file system)
34
+ - Support time based rotation without renaming file because file renaming sometime makes problem
38
35
 
39
36
  ## Installation
40
37
 
@@ -56,7 +53,7 @@ Or install it yourself as:
56
53
 
57
54
  Same interfaces ruby's stdlib `Logger` except for `new` method.
58
55
 
59
- ```
56
+ ```ruby
60
57
  require 'chrono_logger'
61
58
 
62
59
  # specify path with `Time#strftime` format
@@ -68,9 +65,29 @@ logger.info("Enjoy")
68
65
  logger.debug("programming!")
69
66
  ```
70
67
 
68
+ With Rails:
69
+
70
+ ```ruby
71
+ # in config/environments/{development,production}.rb
72
+
73
+ config.logger = ChronoLogger.new("#{config.paths['log'].first}.%Y%m%d")
74
+ ```
75
+
76
+ ## Migrating from `::Logger` with cronolog
77
+
78
+ You only change `Logger.new` into `ChronoLogger.new`:
79
+
80
+ ```ruby
81
+ # for instance your setup is like the following
82
+ Logger.new(IO.popen("/usr/sbin/cronolog production.%Y%m%d", "w"))
83
+
84
+ # turns into
85
+ ChronoLogger.new('production.%Y%m%d')
86
+ ```
87
+
71
88
  ## Limitation
72
89
 
73
- - High performance only daily based time formatting path for example `'%Y%m%d'`. You can create pull request if you need other time period.
90
+ - High performance logging only daily based time formatting path for example `'%Y%m%d'`. You can create pull request if you need other time period.
74
91
 
75
92
  ## Contributing
76
93
 
@@ -83,3 +100,8 @@ logger.debug("programming!")
83
100
  ## License
84
101
 
85
102
  MIT. See [LICENSE.txt](LICENSE.txt) for more details.
103
+
104
+ ## Resources
105
+
106
+ - [ChronoLogger logging is 1.5x faster than ruby's stdlib Logger](https://coderwall.com/p/vjjszq/chronologger-logging-is-1-5x-faster-than-ruby-s-stdlib-logger)
107
+
@@ -18,13 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rake", ">= 0"
23
22
  spec.add_development_dependency "test-unit"
24
23
  spec.add_development_dependency "pry"
25
24
  spec.add_development_dependency "delorean"
26
25
  spec.add_development_dependency "parallel"
27
- spec.add_development_dependency "coveralls"
26
+ spec.add_development_dependency "simplecov"
28
27
 
29
28
  # for performance check
30
29
  spec.add_development_dependency "mono_logger"
@@ -1,5 +1,5 @@
1
1
  require 'logger'
2
2
 
3
3
  class ChronoLogger < Logger
4
- VERSION = "0.0.5"
4
+ VERSION = "1.1.2"
5
5
  end
data/lib/chrono_logger.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "chrono_logger/version"
2
2
  require 'logger'
3
+ require 'pathname'
3
4
 
4
5
  # A lock-free logger with timebased file rotation.
5
6
  class ChronoLogger < Logger
@@ -53,8 +54,13 @@ class ChronoLogger < Logger
53
54
  DELAY_SECOND_TO_CLOSE_FILE = 5
54
55
 
55
56
  def initialize(log = nil, opt = {})
56
- @dev = @filename = nil
57
- @mutex = LogDeviceMutex.new
57
+ @dev = @filename = @pattern = nil
58
+ if defined?(LogDeviceMutex) # Ruby < 2.3
59
+ @mutex = LogDeviceMutex.new
60
+ else
61
+ mon_initialize
62
+ @mutex = self
63
+ end
58
64
  if log.respond_to?(:write) and log.respond_to?(:close)
59
65
  @dev = log
60
66
  else
@@ -69,7 +75,7 @@ class ChronoLogger < Logger
69
75
  end
70
76
 
71
77
  def write(message)
72
- check_shift_log if @pattern
78
+ check_and_shift_log if @pattern
73
79
  @dev.write(message)
74
80
  rescue
75
81
  warn("log writing failed. #{$!}")
@@ -91,6 +97,7 @@ class ChronoLogger < Logger
91
97
 
92
98
  def create_logfile(filename)
93
99
  begin
100
+ Pathname(filename).dirname.mkpath
94
101
  logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT | File::EXCL))
95
102
  logdev.sync = true
96
103
  rescue Errno::EEXIST
@@ -101,12 +108,12 @@ class ChronoLogger < Logger
101
108
  logdev
102
109
  end
103
110
 
104
- def check_shift_log
111
+ def check_and_shift_log
105
112
  if next_period?(Time.now)
106
113
  now = Time.now
107
114
  new_filename = now.strftime(@pattern)
108
115
  next_start_period = next_start_period(now, @period)
109
- shift_log_period(new_filename)
116
+ shift_log(new_filename)
110
117
  @filename = new_filename
111
118
  @next_start_period = next_start_period
112
119
  end
@@ -120,7 +127,7 @@ class ChronoLogger < Logger
120
127
  end
121
128
  end
122
129
 
123
- def shift_log_period(filename)
130
+ def shift_log(filename)
124
131
  begin
125
132
  @mutex.synchronize do
126
133
  tmp_dev = @dev
@@ -131,7 +138,7 @@ class ChronoLogger < Logger
131
138
  end
132
139
  end
133
140
  rescue Exception => ignored
134
- warn("log shifting failed. #{$!}")
141
+ warn("log shifting failed. #{ignored}")
135
142
  end
136
143
  end
137
144
  end
@@ -12,6 +12,7 @@ class TestLogger < Test::Unit::TestCase
12
12
  class Log
13
13
  attr_reader :label, :datetime, :pid, :severity, :progname, :msg
14
14
  def initialize(line)
15
+ # NOTE: adapt the following pattern ruby's original test after support only ruby 3.1 or higher
15
16
  /\A(\w+), \[([^#]*)#(\d+)\]\s+(\w+) -- (\w*): ([\x0-\xff]*)/ =~ line
16
17
  @label, @datetime, @pid, @severity, @progname, @msg = $1, $2, $3, $4, $5, $6
17
18
  end
@@ -82,10 +83,11 @@ class TestLogger < Test::Unit::TestCase
82
83
  assert_match(/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\s*\d+ $/, log.datetime)
83
84
  logger.datetime_format = "%d%b%Y@%H:%M:%S"
84
85
  log = log_add(logger, INFO, "foo")
85
- assert_match(/^\d\d\w\w\w\d\d\d\d@\d\d:\d\d:\d\d$/, log.datetime)
86
+ # NOTE: ` ?` contained in the following will be removed after support only ruby 3.1 or higher
87
+ assert_match(/^\d\d\w\w\w\d\d\d\d@\d\d:\d\d:\d\d ?$/, log.datetime)
86
88
  logger.datetime_format = ""
87
89
  log = log_add(logger, INFO, "foo")
88
- assert_match(/^$/, log.datetime)
90
+ assert_match(/^ ?$/, log.datetime)
89
91
  end
90
92
 
91
93
  def test_formatter
data/test/helper.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'coveralls'
2
- Coveralls.wear!
1
+ require 'simplecov'
2
+ SimpleCov.start
3
3
 
4
4
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
5
  require 'chrono_logger'
@@ -29,6 +29,31 @@ class TestChronoLogger < Test::Unit::TestCase
29
29
  confirm_daily_rotation(in_processes: 2)
30
30
  end
31
31
 
32
+ def test_exception_on_shifting_log
33
+ old_log = [@tempfile.path, '20220101'].join
34
+ new_log = [@tempfile.path, '20220102'].join
35
+ $stderr, stderr = StringIO.new, $stderr
36
+ begin
37
+ Delorean.time_travel_to '2022-01-01 23:59:59.990'
38
+ logger = ChronoLogger.new(@format)
39
+ old_logdev = logger.instance_variable_get('@logdev')
40
+ def old_logdev.create_logfile(filename)
41
+ raise 'override create_logfile method'
42
+ end
43
+ sleep 1 # waiting for shift log file
44
+
45
+ logger.info 'shift log'
46
+
47
+ assert_match(/log shifting failed\. override create_logfile method/, $stderr.string)
48
+ assert { File.exist?(old_log) }
49
+ assert { !File.exist?(new_log) }
50
+ ensure
51
+ $stderr, stderr = stderr, $stderr
52
+ Delorean.back_to_the_present
53
+ File.unlink(old_log)
54
+ end
55
+ end
56
+
32
57
  def test_rotation_per_second
33
58
  Dir.mktmpdir do |tmpdir|
34
59
  begin
@@ -46,6 +71,23 @@ class TestChronoLogger < Test::Unit::TestCase
46
71
  end
47
72
  end
48
73
 
74
+ def test_rotation_per_day_and_create_dir
75
+ Dir.mktmpdir do |tmpdir|
76
+ begin
77
+ Delorean.time_travel_to '2015-08-01 23:59:50'
78
+ logger = ChronoLogger.new([tmpdir, '/%Y/%m/%d/test.log'].join)
79
+ logger.debug 'rotation'
80
+ Delorean.time_travel_to '2015-08-02 00:00:01'
81
+ logger.debug 'new dir'
82
+
83
+ assert { File.exist?([tmpdir, '/2015/08/01/test.log'].join) }
84
+ assert { File.exist?([tmpdir, '/2015/08/02/test.log'].join) }
85
+ ensure
86
+ Delorean.back_to_the_present
87
+ end
88
+ end
89
+ end
90
+
49
91
  class PeriodTest
50
92
  include ChronoLogger::Period
51
93
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chrono_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takayuki Matsubara
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-31 00:00:00.000000000 Z
11
+ date: 2022-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.7'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.7'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '10.0'
19
+ version: '0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '10.0'
26
+ version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: test-unit
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +81,7 @@ dependencies:
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
- name: coveralls
84
+ name: simplecov
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - ">="
@@ -143,8 +129,9 @@ executables: []
143
129
  extensions: []
144
130
  extra_rdoc_files: []
145
131
  files:
132
+ - ".github/workflows/ruby.yml"
146
133
  - ".gitignore"
147
- - ".travis.yml"
134
+ - CHANGELOG.md
148
135
  - Gemfile
149
136
  - LICENSE.txt
150
137
  - README.md
@@ -161,7 +148,7 @@ homepage: https://github.com/ma2gedev/chrono_logger
161
148
  licenses:
162
149
  - MIT
163
150
  metadata: {}
164
- post_install_message:
151
+ post_install_message:
165
152
  rdoc_options: []
166
153
  require_paths:
167
154
  - lib
@@ -176,9 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
163
  - !ruby/object:Gem::Version
177
164
  version: '0'
178
165
  requirements: []
179
- rubyforge_project:
180
- rubygems_version: 2.4.5
181
- signing_key:
166
+ rubygems_version: 3.2.3
167
+ signing_key:
182
168
  specification_version: 4
183
169
  summary: A lock-free logger with timebased file rotation.
184
170
  test_files:
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0-p598
4
- - 2.1.5
5
- - 2.2.0
6
- sudo: false
7
- cache: bundler