Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
452 commits
Select commit Hold shift + click to select a range
47500f2
[ruby/logger] Add support for changing severity using bang methods.
ioquatix Mar 14, 2019
1361967
[ruby/logger] Fix to use logger and test-unit in this repo with
sonots Mar 18, 2019
bbe157f
[ruby/logger] split logger classes/modules into separate files
Dec 12, 2018
7f10da9
[ruby/logger] require 'logger/errors' just for compat
sonots Mar 18, 2019
7ef0856
[ruby/logger] Update logger.gemspec
sonots Mar 18, 2019
3fdb963
[ruby/logger] Prefer require_relative, it's a little bit faster.
ioquatix Mar 20, 2019
2c22051
[ruby/logger] Enable `frozen_string_literal: true` in `logger.rb`.
ioquatix Mar 21, 2019
f4064a0
[ruby/logger] Set filename when initializing logger with a File object
jeremyevans May 17, 2019
58065b8
[ruby/logger] Add option to set the binary mode of the log device
rafaelfranca Jun 4, 2019
1b59ed9
Move helper file of logger to under the test/logger.
hsbt Jul 15, 2019
0eafa1d
Fixed inconsitency locations of default gems.
hsbt Jul 15, 2019
4b345f9
compile.c: ignore the result of COMPILE by marking with NO_CHECK
mame Jul 15, 2019
f103ed8
* expand tabs.
matzbot Jul 15, 2019
036039c
Fixed LoadError of version file.
hsbt Jul 15, 2019
5349aa2
Also fixed up with 036039c8a29d3d8045207c111f9bbc481c904998
hsbt Jul 15, 2019
f73ea33
Fixed ruby/spec for Logger::LogDevice changes.
hsbt Jul 15, 2019
3a1d355
Fix a typo of Markdown of NEWS
aycabta Jul 15, 2019
574e8a6
Add Reline section to NEWS
aycabta Jul 15, 2019
de0f192
Add features of IRB to NEWS
aycabta Jul 15, 2019
5e0d27a
Removed dead code
nobu Jul 15, 2019
5a42dca
* expand tabs.
matzbot Jul 15, 2019
c781b1b
update-deps for dependencies
nobu Jul 15, 2019
c20445a
Require Ruby 2.4 or later because needs lex_state from Ripper
aycabta Jul 15, 2019
b452c03
Always evaluate the expression RUBY_ASSERT_MESG_WHEN just once
nobu Jul 15, 2019
0c6c937
Removed duplicate highlighting
nobu Jul 15, 2019
6aab77a
Add a /* fall through */ comment
mame Jul 15, 2019
c184a1c
compile.c: add NO_CHECK for the calls to COMPILE whose result is unused
mame Jul 15, 2019
a8e4b7b
* expand tabs.
matzbot Jul 15, 2019
325d546
* 2019-07-16
matzbot Jul 15, 2019
34019a2
Expanded f_denominator
nobu Jul 15, 2019
ca524bc
Expanded f_numerator
nobu Jul 15, 2019
71d5b4c
Fixed the library path for tools
nobu Jul 15, 2019
8e37ef7
Fixed the library path for tools
nobu Jul 15, 2019
00dc0da
Removed intermediate local variables
nobu Jul 15, 2019
e2f987e
* expand tabs.
matzbot Jul 16, 2019
75fb0a9
Allow mday in Date.iso8601 to be omitted
nobu Jul 16, 2019
76c6cf2
Print debugging information when updating failed
nobu Jul 16, 2019
19d592d
Somehow `if` didn't work
nobu Jul 16, 2019
8deabcd
Constified afamily functions
nobu Jul 16, 2019
e988048
Moved the check for `exception` to rb_execarg_addopt
nobu Jul 16, 2019
d8e23a6
nil as the default of optional parameters
nobu Jul 16, 2019
d45d448
nil as the default of optional parameters
nobu Jul 16, 2019
6ab95fb
Removed twisted tests
nobu Jul 16, 2019
ed2f2b4
Named the backward compatible dump size
nobu Jul 16, 2019
f487e5b
Expanded buf to copy at once
nobu Jul 16, 2019
0965bb6
* 2019-07-17
matzbot Jul 17, 2019
af07e07
Separate pull-github from merge-github [ci skip]
nobu Jul 17, 2019
cd372f8
Get rid of LoadError with $DEBUG
nobu Jul 17, 2019
0e23e0c
Adjust indent [ci skip]
nobu Jul 17, 2019
416ead4
compile.c: add NO_CHECK for the calls to COMPILE whose result is unused
mame Jul 16, 2019
bdec1ad
* expand tabs.
matzbot Jul 17, 2019
9b28eef
Add benchmark to help diagnose performance regression.
ioquatix Jul 17, 2019
97808e2
* 2019-07-18
matzbot Jul 17, 2019
1b82c87
Make FIBER_USE_NATIVE the default and reformat code.
ioquatix Jun 1, 2019
14cf95c
Implement fiber pool for reduced fiber allocation overhead.
ioquatix Jun 2, 2019
8779382
Remove unused vm_stack recycling.
ioquatix Jun 19, 2019
91aae65
Stack copying implementation of coroutines.
ioquatix Jun 27, 2019
7291fef
Improve build process and coroutine implementation selection.
ioquatix Jun 29, 2019
b8242bc
Add `ucontext` and `copy` coroutine implementations to test matrix.
ioquatix Jun 29, 2019
47c0cab
Add details of fiber pool and coroutine selection to NEWS.
ioquatix Jul 1, 2019
77f3319
Enable `madvise` to release stack space back to OS.
ioquatix Jul 11, 2019
8ac9a7b
Limit expansion of fiber pool on 32-bit platforms.
ioquatix Jul 12, 2019
4d60a58
Add FIBER_POOL_ALLOCATION_FREE to control allocation/free strategy.
ioquatix Jul 16, 2019
385ea91
Add `struct fiber_pool {int free_stacks;}` to control usage of madvise.
ioquatix Jul 16, 2019
001f187
Make fiber_pool more conservative on platforms with limited address s…
ioquatix Jul 16, 2019
56fcf98
Add note about setting `vm.max_map_count` for Linux.
ioquatix Jul 16, 2019
311007b
Add experimental `RUBY_SHARED_FIBER_POOL_FREE_STACKS` to control madv…
ioquatix Jul 16, 2019
38e3c65
Improve `fiber_pool_expand` allocation strategy.
ioquatix Jul 18, 2019
78bc6cd
* remove trailing spaces.
matzbot Jul 18, 2019
9790b77
Ensure we don't have dangling cfp.
ioquatix Jul 18, 2019
d40d8b3
check saved_ec.cfp
ko1 Jul 18, 2019
a027c4b
Use Qnull instead of 0 and Qundef
nobu Jul 18, 2019
a036a8a
Adjust styles and indents
nobu Jul 18, 2019
d4c4029
* 2019-07-19
matzbot Jul 18, 2019
18bce99
Fixed build error with RIPPER_DEBUG
nobu Jul 18, 2019
59d6ce4
Moved RIPPER_DEBUG methods to Ripper from Kernel
nobu Jul 18, 2019
0b82641
Update before commit
nobu Jul 18, 2019
fd461de
Ripper#validate_object: check if the object is hidden
nobu Jul 18, 2019
9dda0a0
Remove `rb_vm_push_frame` as it is no longer used.
ioquatix Jul 18, 2019
d7fdf45
Ensure cfp is initialized to NULL.
ioquatix Jul 18, 2019
c8ee44f
Fix showing doc of "nil.to_s", nil doesn't have #name
aycabta Jul 18, 2019
8ca3202
Revert "Ensure cfp is initialized to NULL."
ioquatix Jul 18, 2019
4ec5b39
initialize only Fiber's cfp.
ko1 Jul 18, 2019
e644e2d
Remove doc/etc.rd.ja [ci skip]
znz Jul 19, 2019
63160a8
respect NDEBUG.
ko1 Jul 19, 2019
6eef80d
Improve ec assertions.
ioquatix Jul 19, 2019
cf93f98
Better usage of `rb_ec_clear_vm_stack` to maintain invariants.
ioquatix Jul 19, 2019
dd0e33f
Split assertions to check which one fails.
ioquatix Jul 19, 2019
e14f576
Add assertions to `coroutine_initialize_main`.
ioquatix Jul 19, 2019
547f574
In some situations, `vm_stack` can be NULL, but `cfp` is valid.
ioquatix Jul 19, 2019
182ae14
fix shared array terminology.
ko1 Jul 19, 2019
a44ad9a
* expand tabs.
matzbot Jul 19, 2019
ae75079
Use FL_TEST_RAW() to check flags.
ko1 Jul 19, 2019
fba3e76
fix debug counter for Hash counts.
ko1 Jul 19, 2019
e004afd
Ensure that madvise does not clobber vacancy data.
ioquatix Jul 19, 2019
517f7f9
Fix 32-bit build and typo.
ioquatix Jul 19, 2019
0a7093a
Add documentation to `fiber_pool_allocate_memory`.
ioquatix Jul 19, 2019
3e8d4ff
array.c: factor out `assert(RB_TYPE_P(ary, T_ARRAY))` to a function
mame Jul 19, 2019
0a16ff9
array.c: use assert in macro instead of in a function
mame Jul 19, 2019
de18328
Some keywords, "true", "false", and "nil" should be treated as a vari…
aycabta Jul 19, 2019
57b7bfa
* 2019-07-20
matzbot Jul 19, 2019
71d21f3
Document required keyword argument syntax [ci skip]
jeremyevans Jul 19, 2019
bf2f84b
Document evaluation order of arguments [ci skip]
jeremyevans Jul 19, 2019
7e26776
Remove mention of Proc.new with implicit block [ci skip]
jeremyevans Jul 19, 2019
ceeb153
Remove section on performance advantage of not using a block paramete…
jeremyevans Jul 19, 2019
c945d11
Document use of ensure and else at method level [ci skip]
jeremyevans Jul 19, 2019
d304f77
Only disable GC around reference updating
tenderlove Jul 19, 2019
77bb79b
array.c: factor out a complex condition of assert
mame Jul 20, 2019
8a38eff
Upgrade benchmark-driver.gem version
k0kubun Jul 20, 2019
56b957e
Upgrade benchmark-driver.gem again
k0kubun Jul 20, 2019
1392b82
Explain what's benchmark/lib/load.rb [ci skip]
k0kubun Jul 20, 2019
81fc3be
file.c: add a NORETURN declaration for statx_notimplement
mame Jul 20, 2019
e7b5b91
--debug was not functional either
k0kubun Jul 20, 2019
c584dd8
Move travis coroutine check to cron only.
ioquatix Jul 20, 2019
d285579
Update simplecov and doclie to the latest version.
hsbt Jul 21, 2019
523fec8
* 2019-07-21
matzbot Jul 21, 2019
24712ee
tool/test/runner.rb: support --test-target-dir option
mame Jul 21, 2019
08ea924
common.mk: `make check` now includes `make test-tool`
mame Jul 21, 2019
28ae30b
Run test-tool in the order of the tests
nobu Jul 22, 2019
f6a7b10
* 2019-07-22
matzbot Jul 22, 2019
463092b
Update rake-12.3.3.
hsbt Jul 22, 2019
f6461fa
Only the first argument can be --test-target-dir option
nobu Jul 22, 2019
d1c2b19
Fixed exception message
nobu Jul 22, 2019
f75561b
constify RHash::ifnone.
ko1 Jul 22, 2019
9095ff5
[ruby/date] Describe what is meant by valid in the Date.valid_date? rdoc
jeremyevans Jun 26, 2019
1feda1c
constify again.
ko1 Jul 22, 2019
9f9a6db
Allways fetch the latest commit from default gems repository.
hsbt Jul 22, 2019
2f6cc00
Fix documentation for Array#pack m directive count specifier [ci skip]
jeremyevans Jul 10, 2019
6b62aa7
* 2019-07-23
matzbot Jul 22, 2019
11f3da8
Stop packing rb_method_definition_t
nobu Jul 22, 2019
d2710ba
Split test/ripper/test_files.rb to run in parallel
nobu Jul 22, 2019
c1ad632
Adjust documentation for Kernel#raise [ci skip]
jeremyevans Jul 22, 2019
32ec6dd
Document encoding of string returned by Regexp.quote [ci skip]
jeremyevans Jul 22, 2019
01995df
Document BasicObject does not implement #object_id and #send [ci skip]
jeremyevans Jul 22, 2019
44cfabd
Removed duplicated entry for racc.
hsbt Jul 23, 2019
73d56d6
reline is default gems now.
hsbt Jul 23, 2019
ab087ec
Added the upstream repositories to default gems.
hsbt Jul 23, 2019
90c4bd2
Let memory sizes of the various IMEMO object types be reflected corre…
methodmissing Apr 22, 2019
33f54da
Support memsize of AST
nobu Jul 23, 2019
c25ff7b
check iseq is executable
ko1 Jul 23, 2019
6546aed
Explicitly initialise encodings on init to remove branches on encodin…
methodmissing Apr 13, 2019
009ec37
Let the index boundary check in rb_enc_from_index be flagged as unlikely
methodmissing Apr 13, 2019
0338c44
Retry to update Unicode timestamp
nobu Jul 23, 2019
e8d4f0c
Show seconds and in the modified time order
nobu Jul 23, 2019
03958a0
Relaxed target_os matching
nobu Jul 23, 2019
676df31
Reset mtime of all files on osx
nobu Jul 23, 2019
b6f07f7
Document that non-blocking mode isn't always supported on Windows [ci…
Jesus Jul 19, 2019
325f7b6
Make pkg_config in mkmf include -I cflags in return value
jeremyevans Jul 8, 2019
c9826c2
Show the caller's location
nobu Jul 23, 2019
f295e23
* 2019-07-24
matzbot Jul 23, 2019
afea8db
Test invalid offset warnings
nobu Jul 23, 2019
11662c7
Test missing Content-Type warnings
nobu Jul 23, 2019
9aba971
Make Object#singleton_methods work correctly for singleton classes of…
jeremyevans Jul 8, 2019
a4e5690
transcode.c (rb_econv_open0): remove unused code
mame Jul 23, 2019
df31715
should not free local hook_list here.
ko1 Jul 23, 2019
a39f218
Reduced duplicate commands in test-bundled-gems-run
nobu Jul 24, 2019
5108a5d
test-bundled-gems-run: Respect -k option
nobu Jul 24, 2019
3a227b9
Adjusted test runner
nobu Jul 24, 2019
99680f8
[rubygems/rubygems] Resolve `@@project_dir` from test file paths
nobu Jul 24, 2019
99fb637
[rubygems/rubygems] Make `@@project_dir` constants per files
nobu Jul 24, 2019
dc954cb
@@project_dir in Gem::TestCase is no longer used
nobu Jul 24, 2019
7b1893c
Resurrect timestamp debug log
k0kubun Jul 24, 2019
65a9d4b
Fix typo [ci skip]
k0kubun Jul 24, 2019
96b0d7c
GNU ls -T has different meaning
nobu Jul 24, 2019
538ba98
Split ls line
nobu Jul 24, 2019
1cce430
Suppress deflateParams() warnings
nobu Jul 24, 2019
3556cba
Document that Range#cover? returns false if <=> returns nil
jeremyevans Jul 24, 2019
48b4deb
* 2019-07-25
matzbot Jul 24, 2019
da76c44
Clarify Thread exception handling documentation [ci skip]
jeremyevans Jul 24, 2019
efa380b
Use PRIuSIZE instead of "%zu"
nobu Jul 24, 2019
0a63c4d
Fix errno at seeking socket/pipe on Windows
nobu Jul 24, 2019
938032a
[ruby/psych] Do not use add_development_dependency.
hsbt Jul 21, 2019
5007690
[ruby/psych] Drop to support fat gem support.
hsbt Jul 21, 2019
6ca7dc6
[ruby/psych] Deduplicate hash keys if they're strings
byroot Jul 22, 2019
698dde5
[ruby/psych] Suppress uninitialized instance variable warnings
nobu Jul 24, 2019
414d6cf
[ruby/psych] Get rid of C90 feature
nobu Jul 24, 2019
077c288
[ruby/io-console] Do not use add_development_dependency
nobu Jul 24, 2019
82ae462
Do not fetch remote tags
nobu Jul 24, 2019
a850be6
Moved NoMemoryError hook to Test::Unit::AutoRunner
nobu Jul 24, 2019
d8e90f5
Fix a typo in inspect
znz Jul 25, 2019
f5ea054
Moved NoMemoryError hook
nobu Jul 25, 2019
4c1db84
Added --base-directory option
nobu Jul 25, 2019
46771ab
Use libraries in the base directory if given
nobu Jul 25, 2019
8e53d18
Separated tool/test/runner.rb and test/runner.rb
nobu Jul 24, 2019
0f9ec4a
Check wether multibyte character is split
aycabta Jul 25, 2019
a50c844
Initialize vm_throw_data::throw_state as int
nobu Jul 25, 2019
7e33f32
Get rid of failures about coverage
nobu Jul 25, 2019
957a29f
Bump osx_image on Travis CI to xcode11
nobu Jul 26, 2019
300de6a
* 2019-07-26
matzbot Jul 26, 2019
82b02c1
pass to obj_info().
ko1 Jul 26, 2019
51f22de
Adjust the test direcotry structure of rdoc.
hsbt Jul 26, 2019
348c968
Escape parentheses for syntax hilighting for VScode.
hsbt Jul 26, 2019
071bf88
Improve the commits list for cherry-picking from default gems.
hsbt Jul 26, 2019
95aa60f
Ignore Merge commit and insufficiency commit for ruby core repository.
hsbt Jul 26, 2019
f7cbbc7
[ruby/rdoc] ClassModule#add_comment should receive RDoc::Comment
aycabta Jan 20, 2019
a86d4ee
[ruby/rdoc] Normalization of comment should check language
aycabta Jan 21, 2019
3b0f952
[ruby/rdoc] Support nesting text page URL
aycabta Jan 25, 2019
8bb4892
[ruby/rdoc] Update jQuery to 3.3.1
aycabta Apr 1, 2019
21ce8b3
[ruby/rdoc] Fix image links in rdoc.css
MaxLap May 14, 2019
4b7d7d0
Document and add spec for delegating to constants in Forwardable
jeremyevans Jun 24, 2019
b1a2edd
Document acceptance of negative pid in Process.kill [ci skip]
jeremyevans Jul 26, 2019
4f978a1
* 2019-07-27
matzbot Jul 26, 2019
5fef46a
Test SecureRandom.uuid format
jeremyevans Jul 26, 2019
bd32833
Document behavior when mixing named captures with parentheses [ci skip]
jeremyevans Jul 26, 2019
6279cf8
Restore documentation for Object#hash [ci skip]
jeremyevans Jul 26, 2019
8bccbf3
Add more documentation on #eql?/#hash relationship [ci skip]
jeremyevans Jul 27, 2019
149e414
Initialize DST flag
nobu Apr 23, 2019
012d39c
Added ignore files to sync_default_gems_with_commits and make constan…
hsbt Jul 27, 2019
58bb7f0
Skip the some of commits when sync default gems from upstream.
hsbt Jul 27, 2019
f9f02e8
Use JRuby equivalent of RubyVM.compile.
headius Jul 26, 2019
a06301b
Ignore history file without saving if permissions cannot be changed
jeremyevans Jun 24, 2019
5c276e1
Update to ruby/spec@875a09e
eregon Jul 27, 2019
7b727e3
Update to ruby/spec@0526d8f
eregon Jul 27, 2019
73530a9
tool/merger.rb: execute 'svn update' after 'svn ci' to update revisio…
nagachika Jul 27, 2019
e3b613a
Include travis osx timeout
k0kubun Jul 27, 2019
f1b76ea
Occupy match data
nobu Jul 27, 2019
adf1362
Extend travis_wait to 50min for osx
k0kubun Jul 27, 2019
1d1f98d
Reuse match data
nobu Jul 27, 2019
bce3482
* 2019-07-28
matzbot Jul 27, 2019
a6e3285
[reline] Do not escape and compile regexp for each byte
nobu Jul 28, 2019
b405898
[reline] Do not compile regexp for each line
nobu Jul 28, 2019
61f0f71
Moved osx_image
nobu Jul 29, 2019
f811a5e
* 2019-07-29
matzbot Jul 29, 2019
630eb04
[ruby/rdoc] Removed unused variable
nobu Jul 29, 2019
8c6f171
Removed unused variables and methods
nobu Jul 29, 2019
4b4d8a6
Stop isolating test_gc_compact on CI
k0kubun Jul 29, 2019
5af28fe
Resurrect -v to debug osx problems
k0kubun Jul 29, 2019
e05f397
Give up `brew update` on Travis
k0kubun Jul 29, 2019
f6a6b21
`travis_wait` silences any output
k0kubun Jul 29, 2019
a5ea55f
Actually remove travis_wait
k0kubun Jul 29, 2019
968c7b4
Fix unused variable
znz Jul 29, 2019
bef398e
Chomp html suffix literally
nobu Jul 29, 2019
3ee63cf
Match suffix for content type more precisely
nobu Jul 29, 2019
e62a609
Should match the beginning/end of string
nobu Jul 29, 2019
c2428b8
Erase only on tty
nobu Jul 29, 2019
aa97410
Warn if using return at top-level with an argument
jeremyevans Jul 26, 2019
1a759bf
Do not always taint the result of File#path
jeremyevans Jun 20, 2019
9170646
* 2019-07-30
matzbot Jul 29, 2019
177731a
Document that Timezone argument for Time uses dst? if available [ci s…
jeremyevans Jul 29, 2019
6eab49a
Revert "Do not always taint the result of File#path"
jeremyevans Jul 29, 2019
1da3a31
Use lowercase letters for IPv6 addresses.
akr Jul 30, 2019
3805ef7
Separate test_set_lineno_gets
nobu Jul 30, 2019
2e6f777
`/o` should not use with instance variable
znz Jul 30, 2019
47144f9
Separate VCS::GIT#upstream
nobu Jul 30, 2019
e250884
Hint for the dependency update [Bug #16000]
nobu Jul 30, 2019
f3b0ed3
Try giving up `brew update` in Azure as well
k0kubun Jul 30, 2019
ceb9e27
Shorten dependency hint [ci skip]
nobu Jul 30, 2019
a50bc9f
Do not always taint the result of File#path
jeremyevans Jun 20, 2019
369c36e
* 2019-07-31
matzbot Jul 30, 2019
f5adc78
Add a specialized instruction for `.nil?` calls
tenderlove Jun 4, 2019
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
Prev Previous commit
Next Next commit
[ruby/logger] split logger classes/modules into separate files
  • Loading branch information
Colby Swandale authored and hsbt committed Jul 15, 2019
commit bbe157f34046ec9ef81e6ad9ed37c86a0d9155e4
5 changes: 2 additions & 3 deletions lib/logger.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
begin
require_relative "lib/logger"
require File.expand_path("../lib/logger/version", __FILE__)
rescue LoadError
# for Ruby core repository
require_relative "logger"
require File.expand_path("../logger/version", __FILE__)
end

Gem::Specification.new do |spec|
Expand Down
295 changes: 4 additions & 291 deletions lib/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# A simple system for logging messages. See Logger for more documentation.

require 'monitor'
require 'logger/version'
require 'logger/formatter'
require 'logger/log_device'
require 'logger/severity'

# == Description
#
Expand Down Expand Up @@ -224,7 +228,6 @@
# })
#
class Logger
VERSION = "1.3.0"
_, name, rev = %w$Id$
if name
name = name.chomp(",v")
Expand All @@ -234,27 +237,6 @@ class Logger
rev ||= "v#{VERSION}"
ProgName = "#{name}/#{rev}".freeze

class Error < RuntimeError # :nodoc:
end
# not used after 1.2.7. just for compat.
class ShiftingError < Error # :nodoc:
end

# Logging severity.
module Severity
# Low-level information, mostly for developers.
DEBUG = 0
# Generic (useful) information about system operation.
INFO = 1
# A warning.
WARN = 2
# A handleable error condition.
ERROR = 3
# An unhandleable error that results in a program crash.
FATAL = 4
# An unknown message that should always be logged.
UNKNOWN = 5
end
include Severity

# Logging severity threshold (e.g. <tt>Logger::INFO</tt>).
Expand Down Expand Up @@ -596,273 +578,4 @@ def format_severity(severity)
def format_message(severity, datetime, progname, msg)
(@formatter || @default_formatter).call(severity, datetime, progname, msg)
end


# Default formatter for log messages.
class Formatter
Format = "%s, [%s#%d] %5s -- %s: %s\n".freeze

attr_accessor :datetime_format

def initialize
@datetime_format = nil
end

def call(severity, time, progname, msg)
Format % [severity[0..0], format_datetime(time), $$, severity, progname,
msg2str(msg)]
end

private

def format_datetime(time)
time.strftime(@datetime_format || "%Y-%m-%dT%H:%M:%S.%6N ".freeze)
end

def msg2str(msg)
case msg
when ::String
msg
when ::Exception
"#{ msg.message } (#{ msg.class })\n" <<
(msg.backtrace || []).join("\n")
else
msg.inspect
end
end
end

module Period
module_function

SiD = 24 * 60 * 60

def next_rotate_time(now, shift_age)
case shift_age
when 'daily'
t = Time.mktime(now.year, now.month, now.mday) + SiD
when 'weekly'
t = Time.mktime(now.year, now.month, now.mday) + SiD * (7 - now.wday)
when 'monthly'
t = Time.mktime(now.year, now.month, 1) + SiD * 32
return Time.mktime(t.year, t.month, 1)
else
return now
end
if t.hour.nonzero? or t.min.nonzero? or t.sec.nonzero?
hour = t.hour
t = Time.mktime(t.year, t.month, t.mday)
t += SiD if hour > 12
end
t
end

def previous_period_end(now, shift_age)
case shift_age
when 'daily'
t = Time.mktime(now.year, now.month, now.mday) - SiD / 2
when 'weekly'
t = Time.mktime(now.year, now.month, now.mday) - (SiD * now.wday + SiD / 2)
when 'monthly'
t = Time.mktime(now.year, now.month, 1) - SiD / 2
else
return now
end
Time.mktime(t.year, t.month, t.mday, 23, 59, 59)
end
end

# Device used for logging messages.
class LogDevice
include Period

attr_reader :dev
attr_reader :filename
include MonitorMixin

def initialize(log = nil, shift_age: nil, shift_size: nil, shift_period_suffix: nil)
@dev = @filename = @shift_age = @shift_size = @shift_period_suffix = nil
mon_initialize
set_dev(log)
if @filename
@shift_age = shift_age || 7
@shift_size = shift_size || 1048576
@shift_period_suffix = shift_period_suffix || '%Y%m%d'

unless @shift_age.is_a?(Integer)
base_time = @dev.respond_to?(:stat) ? @dev.stat.mtime : Time.now
@next_rotate_time = next_rotate_time(base_time, @shift_age)
end
end
end

def write(message)
begin
synchronize do
if @shift_age and @dev.respond_to?(:stat)
begin
check_shift_log
rescue
warn("log shifting failed. #{$!}")
end
end
begin
@dev.write(message)
rescue
warn("log writing failed. #{$!}")
end
end
rescue Exception => ignored
warn("log writing failed. #{ignored}")
end
end

def close
begin
synchronize do
@dev.close rescue nil
end
rescue Exception
@dev.close rescue nil
end
end

def reopen(log = nil)
# reopen the same filename if no argument, do nothing for IO
log ||= @filename if @filename
if log
synchronize do
if @filename and @dev
@dev.close rescue nil # close only file opened by Logger
@filename = nil
end
set_dev(log)
end
end
self
end

private

def set_dev(log)
if log.respond_to?(:write) and log.respond_to?(:close)
@dev = log
else
@dev = open_logfile(log)
@dev.sync = true
@filename = log
end
end

def open_logfile(filename)
begin
File.open(filename, (File::WRONLY | File::APPEND))
rescue Errno::ENOENT
create_logfile(filename)
end
end

def create_logfile(filename)
begin
logdev = File.open(filename, (File::WRONLY | File::APPEND | File::CREAT | File::EXCL))
logdev.flock(File::LOCK_EX)
logdev.sync = true
add_log_header(logdev)
logdev.flock(File::LOCK_UN)
rescue Errno::EEXIST
# file is created by another process
logdev = open_logfile(filename)
logdev.sync = true
end
logdev
end

def add_log_header(file)
file.write(
"# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName]
) if file.size == 0
end

def check_shift_log
if @shift_age.is_a?(Integer)
# Note: always returns false if '0'.
if @filename && (@shift_age > 0) && (@dev.stat.size > @shift_size)
lock_shift_log { shift_log_age }
end
else
now = Time.now
if now >= @next_rotate_time
@next_rotate_time = next_rotate_time(now, @shift_age)
lock_shift_log { shift_log_period(previous_period_end(now, @shift_age)) }
end
end
end

if /mswin|mingw/ =~ RUBY_PLATFORM
def lock_shift_log
yield
end
else
def lock_shift_log
retry_limit = 8
retry_sleep = 0.1
begin
File.open(@filename, File::WRONLY | File::APPEND) do |lock|
lock.flock(File::LOCK_EX) # inter-process locking. will be unlocked at closing file
if File.identical?(@filename, lock) and File.identical?(lock, @dev)
yield # log shifting
else
# log shifted by another process (i-node before locking and i-node after locking are different)
@dev.close rescue nil
@dev = open_logfile(@filename)
@dev.sync = true
end
end
rescue Errno::ENOENT
# @filename file would not exist right after #rename and before #create_logfile
if retry_limit <= 0
warn("log rotation inter-process lock failed. #{$!}")
else
sleep retry_sleep
retry_limit -= 1
retry_sleep *= 2
retry
end
end
rescue
warn("log rotation inter-process lock failed. #{$!}")
end
end

def shift_log_age
(@shift_age-3).downto(0) do |i|
if FileTest.exist?("#{@filename}.#{i}")
File.rename("#{@filename}.#{i}", "#{@filename}.#{i+1}")
end
end
@dev.close rescue nil
File.rename("#{@filename}", "#{@filename}.0")
@dev = create_logfile(@filename)
return true
end

def shift_log_period(period_end)
suffix = period_end.strftime(@shift_period_suffix)
age_file = "#{@filename}.#{suffix}"
if FileTest.exist?(age_file)
# try to avoid filename crash caused by Timestamp change.
idx = 0
# .99 can be overridden; avoid too much file search with 'loop do'
while idx < 100
idx += 1
age_file = "#{@filename}.#{suffix}.#{idx}"
break unless FileTest.exist?(age_file)
end
end
@dev.close rescue nil
File.rename("#{@filename}", age_file)
@dev = create_logfile(@filename)
return true
end
end
end
7 changes: 7 additions & 0 deletions lib/logger/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Logger
class Error < RuntimeError # :nodoc:
end
# not used after 1.2.7. just for compat.
class ShiftingError < Error # :nodoc:
end
end
35 changes: 35 additions & 0 deletions lib/logger/formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Logger
# Default formatter for log messages.
class Formatter
Format = "%s, [%s#%d] %5s -- %s: %s\n".freeze

attr_accessor :datetime_format

def initialize
@datetime_format = nil
end

def call(severity, time, progname, msg)
Format % [severity[0..0], format_datetime(time), $$, severity, progname,
msg2str(msg)]
end

private

def format_datetime(time)
time.strftime(@datetime_format || "%Y-%m-%dT%H:%M:%S.%6N ".freeze)
end

def msg2str(msg)
case msg
when ::String
msg
when ::Exception
"#{ msg.message } (#{ msg.class })\n" <<
(msg.backtrace || []).join("\n")
else
msg.inspect
end
end
end
end
Loading