Module: LunaPark::Notifiers::Log::Formatters

Defined in:
lib/luna_park/notifiers/log/formatters.rb

Constant Summary collapse

SINGLE =
  • SINGLE - output is a single line string message.

    notifier = LunaPark::Notifiers::Log.new(formatter: LunaPark::Notifiers::Log::Formatters::SINGLE)
    notifier.info('You hear', dog: 'wow', cats: {chloe: 'mow', timmy: 'mow'})
    
    # I, [2022-09-29T10:51:15.753646 #28763]  INFO -- : String - You hear {:dog=>"wow", :cats=>{:chloe=>"mow", :timmy=>"mow"}}
    
lambda do |klass, message, details = {}|
  details.empty? ? "#<#{klass}> #{message}" : "#<#{klass}> #{message} #{details}"
end
MULTILINE =
  • MULTILINE - this format may become more preferred for development mode.

    notifier = LunaPark::Notifiers::Log.new(formatter: LunaPark::Notifiers::Log::Formatters::MULTILINE)
    notifier.info('You hear', dog: 'wow', cat: {timmy:'purr'}, cow: 'moo', duck: 'quack', horse: 'yell' )
    
    # I, [2022-09-29T10:56:21.463211 #28763]  INFO -- : {:class=>String,
    # :message=>"You hear",
    # :details=>
    # {:dog=>"wow",
    # :cat=>{:timmy=>"purr"},
    # :cow=>"moo",
    # :duck=>"quack",
    # :horse=>"yell"}}
    
lambda do |klass, message, details = {}|
  PP.pp({ class: klass, message: message, details: details }, '')
end
JSON =
  • JSON - this format should be good choose for logger which be processed by external logger system

    notifier = LunaPark::Notifiers::Log.new(formatter: LunaPark::Notifiers::Log::Formatters::JSON)
    notifier.info('You hear', dog: 'wow', cats: {chloe: 'mow', timmy: 'mow'})
    
    # I, [2022-09-29T12:00:47.600052 #90508]  INFO -- : {"class":"String", "message":"You hear",
    # "details":{"dog":"wow","cats":{"chloe":"mow","timmy":"mow"}}}
    
lambda do |klass, message, details = {}|
  ::JSON.generate(class: klass, message: message, details: details)
end
PRETTY_JSON =
  • PRETTY_JSON - pretty json output

    notifier = LunaPark::Notifiers::Log.new(formatter: LunaPark::Notifiers::Log::Formatters::PRETTY_JSON)
    notifier.info('You hear', dog: 'wow', cat: {timmy:'purr'}, cow: 'moo', duck: 'quack', horse: 'yell')
    
    # I, [2022-09-29T12:02:25.236301 #90508]  INFO -- : {
    #   "class": "String",
    #   "message": "You hear",
    #   "details": {
    #   "dog": "wow",
    #    "cat": {
    #      "timmy": "purr"
    #    },
    #    "cow": "moo",
    #    "duck": "quack",
    #    "horse": "yell"
    # }
    
lambda do |klass, message, details = {}|
  ::JSON.pretty_generate(class: klass, message: message, details: details)
end