# frozen_string_literal: false require 'logger' require 'luna_park/extensions/severity_levels' require 'luna_park/notifiers/log/formatters' require 'luna_park/errors' module LunaPark module Notifiers # Developers need a tool to help them analyze the application. Mostly they use loggers that display messages # in files or in STDOUT. But if you have a lot of microservices, analyzing the logs stored in files on different # servers can be a problem. You can use some real-time error tracking and debugging tools such as # Bugsnag, Rollbar, etc. # # Notifiers are an abstraction that breaks the dependency on a particular implementation of a developer's tool. # Current notifier implement abstraction over ruby logger. # # For example output to log file message at json format # # Define logger and output destination file or STDOUT\STDERR # logger = Logger.new('./log/app.log') # # # Set output format and minimum level output level # notifier = LunaPark::Notifiers::Logger.new(logger: logger, format: :json, min_lvl: :debug) # notifier.info 'Answer to the Ultimate Question of Life, the Universe and Everything', hint: '21 * 2' # # And you will get to './log/app.log' # I, [2020-06-13T21:53:00.824304 #37992] INFO -- : {"message":"Answer to the Ultimate Question of Life, # the Universe and Everything","details":{"hint":"21 * 2"}} class Log include Extensions::SeverityLevels # Callable object to format log messages. # # pretty_formatter = ->(klass, message, details) { "#{klass} - #{message} - #{details}" } # notifier = LunaPark::Notifiers::Log.new(formatter: pretty_formatter) # 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"}} # attr_reader :formatter # Logger which used for output all notify. Should be instance of Logger class. # You can define it in two ways. # - On class # class Stderr < LunaPark::Notifier::Log # logger Logger.new('example.log') # end # # stderr = Stderr.new # stderr.logger # => # #