mono_logger 1.1.0 → 1.1.1
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 +30 -0
- data/.gitignore +17 -17
- data/.travis.yml +4 -7
- data/Gemfile +9 -4
- data/LICENSE.txt +20 -20
- data/README.md +68 -66
- data/Rakefile +12 -12
- data/lib/mono_logger.rb +92 -93
- data/lib/mono_logger/version.rb +5 -5
- data/mono_logger.gemspec +24 -25
- data/test/mri_logger_test.rb +550 -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: 6108fc792b02ceca317d8644f7bff1be6386c52b3aef33358065fe1f5c7d4c72
|
4
|
+
data.tar.gz: 7e6a21e93da1b86718ee302a401c3ce70d1be84b08ef8a0d55e2c9217e7f3926
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 122c67de41dd4756fe832d9ee548f952361208c1b648d01f3f938c6cf2f3e6e6382dccf3d0fad3cbd6a732e56068c5f77c25d8994431996b333dddb96b84fbc4
|
7
|
+
data.tar.gz: dbcd88da37a3e99402941574b39e5b961258507256a22e724bb08011e42a7e9581972e623c8b494524b7c2852fad36c9fbe5e33b3d62b746b66dc3ae1b10f0bf
|
@@ -0,0 +1,30 @@
|
|
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
|
+
- '3.0'
|
14
|
+
- 2.7
|
15
|
+
- 2.6
|
16
|
+
- 2.5
|
17
|
+
- 2.4
|
18
|
+
- 2.3
|
19
|
+
- 2.2
|
20
|
+
- 2.1
|
21
|
+
fail-fast: false
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
# https://github.com/ruby/setup-ruby
|
25
|
+
- uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
28
|
+
- run: ruby -v
|
29
|
+
- run: bundle install
|
30
|
+
- 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,9 @@
|
|
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
|
9
|
+
gem 'coveralls', require: false
|
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) [![Coverage Status](https://coveralls.io/repos/steveklabnik/mono_logger/badge.png)](https://coveralls.io/r/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.rb
CHANGED
@@ -1,93 +1,92 @@
|
|
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
|
-
@dev =
|
51
|
-
@
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
logdev =
|
78
|
-
logdev
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
+
@progname = nil
|
32
|
+
@level = DEBUG
|
33
|
+
@default_formatter = Formatter.new
|
34
|
+
@formatter = nil
|
35
|
+
@logdev = nil
|
36
|
+
if logdev
|
37
|
+
@logdev = LocklessLogDevice.new(logdev)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
class LocklessLogDevice < LogDevice
|
43
|
+
|
44
|
+
def initialize(log = nil)
|
45
|
+
@dev = @filename = @shift_age = @shift_size = nil
|
46
|
+
if log.respond_to?(:write) and log.respond_to?(:close)
|
47
|
+
@dev = log
|
48
|
+
else
|
49
|
+
@dev = open_logfile(log)
|
50
|
+
@dev.sync = true
|
51
|
+
@filename = log
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def write(message)
|
56
|
+
@dev.write(message)
|
57
|
+
rescue Exception => ignored
|
58
|
+
warn("log writing failed. #{ignored}")
|
59
|
+
end
|
60
|
+
|
61
|
+
def close
|
62
|
+
@dev.close rescue nil
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def open_logfile(filename)
|
68
|
+
if (FileTest.exist?(filename))
|
69
|
+
open(filename, (File::WRONLY | File::APPEND))
|
70
|
+
else
|
71
|
+
create_logfile(filename)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def create_logfile(filename)
|
76
|
+
logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT))
|
77
|
+
logdev.sync = true
|
78
|
+
add_log_header(logdev)
|
79
|
+
logdev
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_log_header(file)
|
83
|
+
file.write(
|
84
|
+
"# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName]
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
end
|
92
|
+
|