mono_logger 1.1.0 → 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: 7727c05cae0ac2286c24d7baf6be422ec67d6c29
4
- data.tar.gz: be3aad2bb37089d76253b982acb058f92ff22d4a
2
+ SHA256:
3
+ metadata.gz: 823f37da856af8b746e568ef27edab8caa15fd5130311f31617840bfdc80b8f4
4
+ data.tar.gz: 77608e001c19214270877f209f4b791ae65d83aba0f1d02925c57f57d535610f
5
5
  SHA512:
6
- metadata.gz: 75100d8e2db14e9e6c4f7821dcb23589743e2b19f0462b4b4738bf06e3bb8c72e8d0f239e6b93efcb2f588cec692f0677fd88b83e0655ab7c37e3466b9f3d3af
7
- data.tar.gz: 69d1a4317d617870afdfcf5898f34018785f0ac2856ced89a866eca43b7181804f4e01792313c37a0308ced122401c109cfd62aff296ca400c292ab7c90e129f
6
+ metadata.gz: d0dd2a78c38a20f444a4bfcfe6702f7a8ab61e14e93fa404de64888d8457e5e8ed6c5e1131f279c2243f803fc82be473cd4c25723af758d9decb1288d379626a
7
+ data.tar.gz: 5744a0a832cd33cf50fd8ebf13a032daf9b32b7f005323120953b4c1d8e0f201e57de3848ba1cfa037aa49d9dcca7adc66296cd5de5297eebaf5299b43e7262a
@@ -0,0 +1,33 @@
1
+ name: Build
2
+ on: [push, pull_request]
3
+ jobs:
4
+ build:
5
+ name: >-
6
+ ruby ${{ matrix.ruby }}
7
+ # Available hosts.
8
+ # https://docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners
9
+ runs-on: ubuntu-20.04 # focal
10
+ strategy:
11
+ matrix:
12
+ ruby:
13
+ - head
14
+ - '3.2'
15
+ - '3.1'
16
+ - '3.0'
17
+ - 2.7
18
+ - 2.6
19
+ - 2.5
20
+ - 2.4
21
+ - 2.3
22
+ - 2.2
23
+ - 2.1
24
+ fail-fast: false
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ # https://github.com/ruby/setup-ruby
28
+ - uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby }}
31
+ - run: ruby -v
32
+ - run: bundle install
33
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -1,17 +1,17 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml CHANGED
@@ -1,7 +1,4 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- - 2.0.0
6
- - jruby-19mode
7
- - rbx-19mode
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - jruby-19mode
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in mono_logger.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mono_logger.gemspec
4
+ gemspec
5
+
6
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2.0")
7
+ gem 'logger-application'
8
+ end
data/LICENSE.txt CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2013 Steve Klabnik
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
- of the Software, and to permit persons to whom the Software is furnished to do
8
- so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- SOFTWARE.
20
-
1
+ Copyright (c) 2013 Steve Klabnik
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
20
+
data/README.md CHANGED
@@ -1,66 +1,68 @@
1
- # MonoLogger
2
-
3
- Ruby's stdlib Logger wraps all IO in mutexes. Ruby 2.0 doesn't allow you to
4
- request a lock in a trap handler because that could deadlock. This gem fixes
5
- this issue by giving you a lock-free logger class.
6
-
7
- If you've ever seen `log writing failed. can't be called from trap context`,
8
- you're in the right place!
9
-
10
- ## Installation
11
-
12
- Add this line to your application's Gemfile:
13
-
14
- gem 'mono_logger'
15
-
16
- And then execute:
17
-
18
- $ bundle
19
-
20
- Or install it yourself as:
21
-
22
- $ gem install mono_logger
23
-
24
- ## Usage
25
-
26
- It's simple, just use `MonoLogger` anywhere you'd use `Logger`:
27
-
28
- ```ruby
29
- require 'logger'
30
-
31
-
32
- logger = Logger.new(STDOUT)
33
- logger.level = Logger::WARN
34
-
35
- logger.debug("Created logger")
36
- logger.info("Program started")
37
- logger.warn("Nothing to do!")
38
- ```
39
-
40
- Turns into
41
-
42
- ```ruby
43
- require 'mono_logger'
44
-
45
-
46
- logger = MonoLogger.new(STDOUT)
47
- logger.level = MonoLogger::WARN
48
-
49
- logger.debug("Created logger")
50
- logger.info("Program started")
51
- logger.warn("Nothing to do!")
52
- ```
53
-
54
- That's it! No more errors!
55
-
56
- ## Contributing
57
-
58
- 1. Fork it
59
- 2. Create your feature branch (`git checkout -b my-new-feature`)
60
- 3. Commit your changes (`git commit -am 'Add some feature'`)
61
- 4. Push to the branch (`git push origin my-new-feature`)
62
- 5. Create new Pull Request
63
-
64
- ## License
65
-
66
- MIT. See LICENSE.txt for more details.
1
+ # MonoLogger
2
+
3
+ [![Build Status](https://travis-ci.org/steveklabnik/mono_logger.png?branch=master)](https://travis-ci.org/steveklabnik/mono_logger) [![Code Climate](https://codeclimate.com/github/steveklabnik/mono_logger.png)](https://codeclimate.com/github/steveklabnik/mono_logger)
4
+
5
+ Ruby's stdlib Logger wraps all IO in mutexes. Ruby 2.0 doesn't allow you to
6
+ request a lock in a trap handler because that could deadlock. This gem fixes
7
+ this issue by giving you a lock-free logger class.
8
+
9
+ If you've ever seen `log writing failed. can't be called from trap context`,
10
+ you're in the right place!
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'mono_logger'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install mono_logger
25
+
26
+ ## Usage
27
+
28
+ It's simple, just use `MonoLogger` anywhere you'd use `Logger`:
29
+
30
+ ```ruby
31
+ require 'logger'
32
+
33
+
34
+ logger = Logger.new(STDOUT)
35
+ logger.level = Logger::WARN
36
+
37
+ logger.debug("Created logger")
38
+ logger.info("Program started")
39
+ logger.warn("Nothing to do!")
40
+ ```
41
+
42
+ Turns into
43
+
44
+ ```ruby
45
+ require 'mono_logger'
46
+
47
+
48
+ logger = MonoLogger.new(STDOUT)
49
+ logger.level = MonoLogger::WARN
50
+
51
+ logger.debug("Created logger")
52
+ logger.info("Program started")
53
+ logger.warn("Nothing to do!")
54
+ ```
55
+
56
+ That's it! No more errors!
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
65
+
66
+ ## License
67
+
68
+ MIT. See LICENSE.txt for more details.
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- require "bundler/gem_tasks"
2
-
3
- require 'rake/testtask'
4
-
5
- Rake::TestTask.new do |t|
6
- t.libs << "lib"
7
- t.test_files = FileList['test/*_test.rb']
8
- t.ruby_opts = ['-w']
9
- t.verbose = true
10
- end
11
-
12
- task :default => :test
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.ruby_opts = ['-w']
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
@@ -1,5 +1,5 @@
1
- require 'logger'
2
-
3
- class MonoLogger < Logger
4
- VERSION = "1.1.0"
5
- end
1
+ require 'logger'
2
+
3
+ class MonoLogger < Logger
4
+ VERSION = "1.1.2"
5
+ end
data/lib/mono_logger.rb CHANGED
@@ -1,93 +1,89 @@
1
- require 'mono_logger/version'
2
-
3
- require 'logger'
4
-
5
- #== MonoLogger
6
- # A subclass of Ruby's stdlib Logger with all the mutex and logrotation stuff
7
- # ripped out.
8
- class MonoLogger < Logger
9
-
10
- #
11
- # === Synopsis
12
- #
13
- # Logger.new(name, shift_age = 7, shift_size = 1048576)
14
- # Logger.new(name, shift_age = 'weekly')
15
- #
16
- # === Args
17
- #
18
- # +logdev+::
19
- # The log device. This is a filename (String) or IO object (typically
20
- # +STDOUT+, +STDERR+, or an open file).
21
- # +shift_age+::
22
- # Number of old log files to keep, *or* frequency of rotation (+daily+,
23
- # +weekly+ or +monthly+).
24
- # +shift_size+::
25
- # Maximum logfile size (only applies when +shift_age+ is a number).
26
- #
27
- # === Description
28
- #
29
- # Create an instance.
30
- #
31
- def initialize(logdev, shift_age=nil, shift_size=nil)
32
- @progname = nil
33
- @level = DEBUG
34
- @default_formatter = Formatter.new
35
- @formatter = nil
36
- @logdev = nil
37
- if logdev
38
- @logdev = LocklessLogDevice.new(logdev)
39
- end
40
- end
41
-
42
-
43
- class LocklessLogDevice < LogDevice
44
-
45
- def initialize(log = nil)
46
- @dev = @filename = @shift_age = @shift_size = nil
47
- if log.respond_to?(:write) and log.respond_to?(:close)
48
- @dev = log
49
- else
50
- @dev = open_logfile(log)
51
- @dev.sync = true
52
- @filename = log
53
- end
54
- end
55
-
56
- def write(message)
57
- @dev.write(message)
58
- rescue Exception => ignored
59
- warn("log writing failed. #{ignored}")
60
- end
61
-
62
- def close
63
- @dev.close rescue nil
64
- end
65
-
66
- private
67
-
68
- def open_logfile(filename)
69
- if (FileTest.exist?(filename))
70
- open(filename, (File::WRONLY | File::APPEND))
71
- else
72
- create_logfile(filename)
73
- end
74
- end
75
-
76
- def create_logfile(filename)
77
- logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT))
78
- logdev.sync = true
79
- add_log_header(logdev)
80
- logdev
81
- end
82
-
83
- def add_log_header(file)
84
- file.write(
85
- "# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName]
86
- )
87
- end
88
-
89
- end
90
-
91
-
92
- end
93
-
1
+ require 'mono_logger/version'
2
+
3
+ require 'logger'
4
+
5
+ #== MonoLogger
6
+ # A subclass of Ruby's stdlib Logger with all the mutex and logrotation stuff
7
+ # ripped out.
8
+ class MonoLogger < Logger
9
+
10
+ #
11
+ # === Synopsis
12
+ #
13
+ # MonoLogger.new(STDOUT)
14
+ # MonoLogger.new(filename)
15
+ #
16
+ # === Args
17
+ #
18
+ # +logdev+::
19
+ # The log device. This is a filename (String) or IO object (typically
20
+ # +STDOUT+, +STDERR+, or an open file).
21
+ # +shift_age+::
22
+ # ignored in MonoLogger
23
+ # +shift_size+::
24
+ # ignored in MonoLogger
25
+ #
26
+ # === Description
27
+ #
28
+ # Create an instance.
29
+ #
30
+ def initialize(logdev, shift_age=nil, shift_size=nil)
31
+ super(nil)
32
+
33
+ if logdev
34
+ @logdev = LocklessLogDevice.new(logdev)
35
+ end
36
+ end
37
+
38
+
39
+ class LocklessLogDevice < LogDevice
40
+
41
+ def initialize(log = nil)
42
+ @dev = @filename = @shift_age = @shift_size = nil
43
+ if log.respond_to?(:write) and log.respond_to?(:close)
44
+ @dev = log
45
+ else
46
+ @dev = open_logfile(log)
47
+ @dev.sync = true
48
+ @filename = log
49
+ end
50
+ end
51
+
52
+ def write(message)
53
+ @dev.write(message)
54
+ rescue Exception => ignored
55
+ warn("log writing failed. #{ignored}")
56
+ end
57
+
58
+ def close
59
+ @dev.close rescue nil
60
+ end
61
+
62
+ private
63
+
64
+ def open_logfile(filename)
65
+ if (FileTest.exist?(filename))
66
+ open(filename, (File::WRONLY | File::APPEND))
67
+ else
68
+ create_logfile(filename)
69
+ end
70
+ end
71
+
72
+ def create_logfile(filename)
73
+ logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT))
74
+ logdev.sync = true
75
+ add_log_header(logdev)
76
+ logdev
77
+ end
78
+
79
+ def add_log_header(file)
80
+ file.write(
81
+ "# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName]
82
+ )
83
+ end
84
+
85
+ end
86
+
87
+
88
+ end
89
+
data/mono_logger.gemspec CHANGED
@@ -1,25 +1,24 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'mono_logger/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = "mono_logger"
9
- spec.version = MonoLogger::VERSION
10
- spec.authors = ["Steve Klabnik"]
11
- spec.email = ["steve@steveklabnik.com"]
12
- spec.description = %q{A lock-free logger compatible with Ruby 2.0. Ruby does not allow you to request a lock in a trap handler because that could deadlock, so Logger is not sufficient.}
13
- spec.summary = %q{A lock-free logger compatible with Ruby 2.0.}
14
- spec.homepage = "http://github.com/steveklabnik/mono_logger"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files`.split($/)
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
24
- spec.add_development_dependency "minitest", "~> 4.0"
25
- end
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'mono_logger/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "mono_logger"
9
+ spec.version = MonoLogger::VERSION
10
+ spec.authors = ["Steve Klabnik"]
11
+ spec.email = ["steve@steveklabnik.com"]
12
+ spec.description = %q{A lock-free logger compatible with Ruby 2.0. Ruby does not allow you to request a lock in a trap handler because that could deadlock, so Logger is not sufficient.}
13
+ spec.summary = %q{A lock-free logger compatible with Ruby 2.0.}
14
+ spec.homepage = "http://github.com/steveklabnik/mono_logger"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest", "~> 5.0"
24
+ end