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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7727c05cae0ac2286c24d7baf6be422ec67d6c29
4
- data.tar.gz: be3aad2bb37089d76253b982acb058f92ff22d4a
2
+ SHA256:
3
+ metadata.gz: 6108fc792b02ceca317d8644f7bff1be6386c52b3aef33358065fe1f5c7d4c72
4
+ data.tar.gz: 7e6a21e93da1b86718ee302a401c3ce70d1be84b08ef8a0d55e2c9217e7f3926
5
5
  SHA512:
6
- metadata.gz: 75100d8e2db14e9e6c4f7821dcb23589743e2b19f0462b4b4738bf06e3bb8c72e8d0f239e6b93efcb2f588cec692f0677fd88b83e0655ab7c37e3466b9f3d3af
7
- data.tar.gz: 69d1a4317d617870afdfcf5898f34018785f0ac2856ced89a866eca43b7181804f4e01792313c37a0308ced122401c109cfd62aff296ca400c292ab7c90e129f
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
@@ -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,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
- 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) [![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
- # 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
+ @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
+