Class: Logging::Layouts::UBSafeLoggerLayout
- Inherits:
-
Logging::Layout
- Object
- Logging::Layout
- Logging::Layouts::UBSafeLoggerLayout
- Defined in:
- lib/ubsafe/extensions/ubsafe_logging_extensions.rb
Overview
Layout to be shared among all StandardizedLogger logging classes
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
Instance Method Summary collapse
-
#format(event) ⇒ Object
call-seq: format( event ).
-
#hostname ⇒ Object
Get the (cached) hostname for this machine.
-
#initialize(configuration) ⇒ UBSafeLoggerLayout
constructor
A new instance of UBSafeLoggerLayout.
Constructor Details
#initialize(configuration) ⇒ UBSafeLoggerLayout
Returns a new instance of UBSafeLoggerLayout.
8 9 10 11 |
# File 'lib/ubsafe/extensions/ubsafe_logging_extensions.rb', line 8 def initialize(configuration) @configuration = configuration @app_name = configuration[:log_identifier] end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
6 7 8 |
# File 'lib/ubsafe/extensions/ubsafe_logging_extensions.rb', line 6 def app_name @app_name end |
Instance Method Details
#format(event) ⇒ Object
call-seq:
format( event )
Returns a string representation of the given loggging event. See the
26 27 28 29 30 31 32 33 34 |
# File 'lib/ubsafe/extensions/ubsafe_logging_extensions.rb', line 26 def format( event ) msg = format_obj(event.data) severity_text = ::Logging::LNAMES[event.level] preamble = "#{Time.now.utc.strftime("%Y-%m-%d %H:%M:%S")}\tUTC\t[#{severity_text}]\t[#{hostname}]\t[#{app_name}]\t[#{$$}]\t" = preamble + (msg || '[nil]') .gsub!(/\n/,' ') += "\n" unless =~ /\n$/ return end |
#hostname ⇒ Object
Get the (cached) hostname for this machine
14 15 16 17 18 19 |
# File 'lib/ubsafe/extensions/ubsafe_logging_extensions.rb', line 14 def hostname unless defined?(@@hostname) @@hostname = `hostname`.chomp.strip.downcase end return @@hostname end |