-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ruby/divide-classes-modules
split logger classes/modules into separate files
- Loading branch information
Showing
9 changed files
with
312 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# not used after 1.2.7. just for compat. | ||
class Logger | ||
class Error < RuntimeError # :nodoc: | ||
end | ||
class ShiftingError < Error # :nodoc: | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.