Class: Ougai::Formatters::Base
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Ougai::Formatters::Base
- Defined in:
- lib/ougai/formatters/base.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#trace_indent ⇒ Object
Returns the value of attribute trace_indent.
-
#trace_max_lines ⇒ Object
Returns the value of attribute trace_max_lines.
Instance Method Summary collapse
-
#initialize(app_name = nil, hostname = nil) ⇒ Base
constructor
A new instance of Base.
- #serialize_exc(ex) ⇒ Object
- #serialize_trace(trace) ⇒ Object
Constructor Details
#initialize(app_name = nil, hostname = nil) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 |
# File 'lib/ougai/formatters/base.rb', line 11 def initialize(app_name = nil, hostname = nil) @app_name = app_name || File.basename($0, ".rb") @hostname = hostname || Socket.gethostname.force_encoding('UTF-8') @trace_indent = 2 @trace_max_lines = 100 end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
9 10 11 |
# File 'lib/ougai/formatters/base.rb', line 9 def app_name @app_name end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
9 10 11 |
# File 'lib/ougai/formatters/base.rb', line 9 def hostname @hostname end |
#trace_indent ⇒ Object
Returns the value of attribute trace_indent.
8 9 10 |
# File 'lib/ougai/formatters/base.rb', line 8 def trace_indent @trace_indent end |
#trace_max_lines ⇒ Object
Returns the value of attribute trace_max_lines.
8 9 10 |
# File 'lib/ougai/formatters/base.rb', line 8 def trace_max_lines @trace_max_lines end |
Instance Method Details
#serialize_exc(ex) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ougai/formatters/base.rb', line 18 def serialize_exc(ex) err = { name: ex.class.name, message: ex.to_s } if ex.backtrace err[:stack] = serialize_trace(ex.backtrace) end err end |
#serialize_trace(trace) ⇒ Object
29 30 31 32 |
# File 'lib/ougai/formatters/base.rb', line 29 def serialize_trace(trace) sp = "\n" + ' ' * @trace_indent trace.slice(0, @trace_max_lines).join(sp) end |