Class: SemanticLogger::Formatters::Base
- Inherits:
-
Object
- Object
- SemanticLogger::Formatters::Base
- Defined in:
- lib/semantic_logger/formatters/base.rb
Direct Known Subclasses
Constant Summary collapse
- CONTROL_CHAR_ESCAPES =
Printable escapes for the most common control characters. Any other ASCII control character is escaped to its hexadecimal
\xHHform by #escape_control_characters, and a Unicode one (see UNICODE_CONTROL_CHARS) to its\uXXXXform. Utils.make_shareable( { "\n" => "\\n", "\r" => "\\r", "\t" => "\\t", "\e" => "\\e" }.freeze )
- CONTROL_CHARS =
Matches C0 control characters (including newlines and the ANSI escape) and DEL.
/[\x00-\x1f\x7f]/- UNICODE_CONTROL_CHARS =
Matches the characters of CONTROL_CHARS, and the Unicode characters that control how text is shown: the C1 control characters (U+0080 to U+009F, including the next line U+0085), which some terminals act on, the line and paragraph separators (U+2028, U+2029), at which editors, browsers, and some log viewers start a new line, and the bidirectional controls (U+202A to U+202E, U+2066 to U+2069), which can make logged text read in a different order than it was written. Escaped in the
\uXXXXform. /[\x00-\x1f\x7f\u0080-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]/- PRECISION =
Time precision varies by Ruby interpreter JRuby 9.1.8.0 supports microseconds
if defined?(JRuby) if JRUBY_VERSION.to_f >= 9.1 maint = JRUBY_VERSION.match(/\A\d+\.\d+\.(\d+)\./)[1].to_i (maint >= 8) || (JRUBY_VERSION.to_f > 9.1) ? 6 : 3 else 3 end else 6 end
Instance Attribute Summary collapse
-
#backtrace_cleaner ⇒ Object
Returns [true|false|Object] the
backtrace_cleaneroption. -
#escape_control_chars ⇒ Object
Returns the value of attribute escape_control_chars.
-
#log ⇒ Object
Returns the value of attribute log.
-
#log_application ⇒ Object
Returns the value of attribute log_application.
-
#log_environment ⇒ Object
Returns the value of attribute log_environment.
-
#log_exception_details ⇒ Object
Returns the value of attribute log_exception_details.
-
#log_host ⇒ Object
Returns the value of attribute log_host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#precision ⇒ Object
Returns the value of attribute precision.
-
#time_format ⇒ Object
Returns [String|Symbol] the
time_formatoption.
Class Method Summary collapse
-
.build_time_format(precision = PRECISION) ⇒ Object
Return default time format string.
Instance Method Summary collapse
-
#initialize(time_format: nil, log_host: true, log_application: true, log_environment: true, precision: PRECISION, escape_control_chars: false, log_exception_details: default_log_exception_details, backtrace_cleaner: default_backtrace_cleaner) ⇒ Base
constructor
Parameters time_format: [String|Symbol|nil] See Time#strftime for the format of this string.
-
#pid ⇒ Object
Process ID.
-
#time ⇒ Object
Date & time.
Constructor Details
#initialize(time_format: nil, log_host: true, log_application: true, log_environment: true, precision: PRECISION, escape_control_chars: false, log_exception_details: default_log_exception_details, backtrace_cleaner: default_backtrace_cleaner) ⇒ Base
Parameters
time_format: [String|Symbol|nil]
See Time#strftime for the format of this string.
:iso_8601 Outputs an ISO8601 Formatted timestamp.
:ms Output in miliseconds since epoch.
:notime Returns an empty string for time ( no time is output ).
Default: '%Y-%m-%d %H:%M:%S.%#clean or #call (see
SemanticLogger.backtrace_cleaner=).
Default: true for the text formatters (Default and those built on it) and the Json
formatters, false otherwise.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/semantic_logger/formatters/base.rb', line 96 def initialize(time_format: nil, log_host: true, log_application: true, log_environment: true, precision: PRECISION, escape_control_chars: false, log_exception_details: default_log_exception_details, backtrace_cleaner: default_backtrace_cleaner) self.time_format = time_format || self.class.build_time_format(precision) @log_host = log_host @log_application = log_application @log_environment = log_environment @precision = precision @escape_control_chars = escape_control_chars @log_exception_details = log_exception_details self.backtrace_cleaner = backtrace_cleaner end |
Instance Attribute Details
#backtrace_cleaner ⇒ Object
Returns [true|false|Object] the backtrace_cleaner option. See #initialize.
127 128 129 |
# File 'lib/semantic_logger/formatters/base.rb', line 127 def backtrace_cleaner @backtrace_cleaner end |
#escape_control_chars ⇒ Object
Returns the value of attribute escape_control_chars.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def escape_control_chars @escape_control_chars end |
#log ⇒ Object
Returns the value of attribute log.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def log @log end |
#log_application ⇒ Object
Returns the value of attribute log_application.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def log_application @log_application end |
#log_environment ⇒ Object
Returns the value of attribute log_environment.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def log_environment @log_environment end |
#log_exception_details ⇒ Object
Returns the value of attribute log_exception_details.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def log_exception_details @log_exception_details end |
#log_host ⇒ Object
Returns the value of attribute log_host.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def log_host @log_host end |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def logger @logger end |
#precision ⇒ Object
Returns the value of attribute precision.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def precision @precision end |
#time_format ⇒ Object
Returns [String|Symbol] the time_format option. See #initialize.
115 116 117 |
# File 'lib/semantic_logger/formatters/base.rb', line 115 def time_format @time_format end |
Class Method Details
.build_time_format(precision = PRECISION) ⇒ Object
Return default time format string
Parameters precision: [Integer] How many fractional digits to log times with. Default: PRECISION (6, except on older JRuby, where 3)
148 149 150 |
# File 'lib/semantic_logger/formatters/base.rb', line 148 def self.build_time_format(precision = PRECISION) "%Y-%m-%d %H:%M:%S.%#{precision}N" end |
Instance Method Details
#pid ⇒ Object
Process ID
158 159 160 |
# File 'lib/semantic_logger/formatters/base.rb', line 158 def pid $$ end |
#time ⇒ Object
Date & time
153 154 155 |
# File 'lib/semantic_logger/formatters/base.rb', line 153 def time format_time(log.time) if time_format end |