Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with Ruby HEAD & add Ruby versions to CI #12

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
strategy:
matrix:
ruby:
- head
- '3.2'
- '3.1'
- '3.0'
- 2.7
- 2.6
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ gemspec
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2.0")
gem 'logger-application'
end
gem 'coveralls', require: false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MonoLogger

[![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)
[![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)

Ruby's stdlib Logger wraps all IO in mutexes. Ruby 2.0 doesn't allow you to
request a lock in a trap handler because that could deadlock. This gem fixes
Expand Down
7 changes: 2 additions & 5 deletions lib/mono_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ class MonoLogger < Logger
# Create an instance.
#
def initialize(logdev, shift_age=nil, shift_size=nil)
@progname = nil
@level = DEBUG
@default_formatter = Formatter.new
@formatter = nil
@logdev = nil
super(nil)

if logdev
@logdev = LocklessLogDevice.new(logdev)
end
Expand Down
18 changes: 6 additions & 12 deletions test/mri_logger_test.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# coding: US-ASCII
require 'simplecov'
SimpleCov.start do
add_filter do |source_file|
source_file.filename =~ /test/
end
end

require 'coveralls'
Coveralls.wear!

require 'minitest/autorun'
require 'mono_logger'
Expand Down Expand Up @@ -112,16 +103,19 @@ def test_progname
end

def test_datetime_format
# We use strip because we don't care about the upstream changes that
# happened to whitespace, and this makes the test behave the same
# regardless of Ruby/Logger version.
dummy = STDERR
logger = Logger.new(dummy)
log = log_add(logger, INFO, "foo")
assert_match(/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\s*\d+ $/, log.datetime)
assert_match(/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\s*\d+$/, log.datetime.strip)
logger.datetime_format = "%d%b%Y@%H:%M:%S"
log = log_add(logger, INFO, "foo")
assert_match(/^\d\d\w\w\w\d\d\d\d@\d\d:\d\d:\d\d$/, log.datetime)
assert_match(/^\d\d\w\w\w\d\d\d\d@\d\d:\d\d:\d\d$/, log.datetime.strip)
logger.datetime_format = ""
log = log_add(logger, INFO, "foo")
assert_match(/^$/, log.datetime)
assert_match(/^$/, log.datetime.strip)
end

def test_formatter
Expand Down