Created
October 18, 2017 14:27
-
-
Save bibikovilya/48ab80eb26669aa48ce8d92d2aebfc07 to your computer and use it in GitHub Desktop.
Logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SoapService | |
class SoapLogger | |
attr_accessor :logger | |
class << self | |
attr_accessor :class_logger | |
delegate :info, :warn, :debug, :error, to: :class_logger | |
end | |
def initialize | |
log = Logger.new('log/soap_service.log') | |
log.formatter = formatter | |
@logger = ActiveSupport::TaggedLogging.new(log) | |
end | |
def formatter | |
Proc.new do |severity, time, progname, msg| | |
formatted_severity = sprintf('%-5s', severity.to_s) | |
formatted_time = time.strftime('%Y-%m-%d %H:%M:%S') | |
"[#{formatted_severity} #{formatted_time} #{$$}] #{msg}\n" | |
end | |
end | |
def info(msg, vacation = nil) | |
@logger.tagged(message_header(vacation)) { @logger.info(msg) } | |
end | |
def warn(msg, vacation = nil) | |
@logger.tagged(message_header(vacation)) { @logger.warn(msg) } | |
end | |
def debug(msg, vacation = nil) | |
@logger.tagged(message_header(vacation)) { @logger.debug(msg) } | |
end | |
def error(msg, vacation = nil) | |
@logger.tagged(message_header(vacation)) { @logger.error(msg) } | |
end | |
def message_header(vacation) | |
vacation ? "< vacation_id: #{vacation.id} >" : '' | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SoapService::SoapLogger.class_logger = SoapService::SoapLogger.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SoapLogger.info("Message for log") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment