Class: Logging::Layouts::UBSafeLoggerLayout

Inherits:
Logging::Layout
  • Object
show all
Defined in:
lib/ubsafe/extensions/ubsafe_logging_extensions.rb

Overview

Layout to be shared among all StandardizedLogger logging classes

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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"
  full_message =  preamble + (msg || '[nil]')
  full_message.gsub!(/\n/,' ')
  full_message += "\n" unless full_message =~ /\n$/
  return full_message
end

#hostnameObject

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