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 +5 -5
- data/.github/workflows/build.yml +33 -0
- data/.gitignore +17 -17
- data/.travis.yml +4 -7
- data/Gemfile +8 -4
- data/LICENSE.txt +20 -20
- data/README.md +68 -66
- data/Rakefile +12 -12
- data/lib/mono_logger/version.rb +5 -5
- data/lib/mono_logger.rb +89 -93
- data/mono_logger.gemspec +24 -25
- data/test/mri_logger_test.rb +544 -533
- metadata +17 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 823f37da856af8b746e568ef27edab8caa15fd5130311f31617840bfdc80b8f4
|
4
|
+
data.tar.gz: 77608e001c19214270877f209f4b791ae65d83aba0f1d02925c57f57d535610f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
logger.
|
36
|
-
|
37
|
-
logger.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
logger.
|
50
|
-
|
51
|
-
logger.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
data/lib/mono_logger/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
class MonoLogger < Logger
|
4
|
-
VERSION = "1.1.
|
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
|
-
#
|
14
|
-
#
|
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
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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 "
|
23
|
-
spec.add_development_dependency "
|
24
|
-
|
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
|