-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
151 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'logger' | ||
|
||
module Datadog | ||
LOG_PREFIX = 'ddtrace'.freeze | ||
|
||
# A custom logger with minor enhancements: | ||
# - progname defaults to ddtrace to clearly identify Datadog dd-trace-rb related messages | ||
# - adds last caller stack-trace info to know where the message comes from | ||
class Logger < ::Logger | ||
def initialize(*args, &block) | ||
super | ||
self.progname = LOG_PREFIX | ||
end | ||
|
||
def add(severity, message = nil, progname = nil, &block) | ||
return super unless debug? | ||
|
||
# We are in debug mode, add stack trace to help debugging | ||
where = '' | ||
c = caller | ||
where = "(#{c[1]}) " if c.length > 1 | ||
|
||
if block_given? | ||
super(severity, message, progname) do | ||
"#{where}#{yield}" | ||
end | ||
else | ||
super(severity, message, "#{where}#{progname}") | ||
end | ||
end | ||
|
||
alias log add | ||
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
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