# @(#) MQMBID sn=pkoa-L150203 su=BCAC7F69-80BD-4CA4-AF88-E07D09E380A0 pn=appmsging/ruby/mqlight/lib/mqlight/logging.rb # # # Licensed Materials - Property of IBM # # 5725-P60 # # (C) Copyright IBM Corp. 2014, 2015 # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with # IBM Corp. # module Mqlight # Internal class that handles logging module Logging require 'logger' def logger Logging.logger end def self.logger @logger ||= MqlightLogger.new(STDERR) end # The logger used by all internal MQ Light classes class MqlightLogger < Logger # Logging severity. module Severity ALL = -Float::INFINITY PROTON_DATA = -Float::INFINITY PROTON_EXIT = -Float::INFINITY PROTON_ENTRY = -Float::INFINITY PROTON = -Float::INFINITY DATA_OFTEN = 100 EXIT_OFTEN = 100 ENTRY_OFTEN = 100 OFTEN = 100 RAW = 200 DETAIL = 300 DEBUG = 500 EMIT = 800 DATA = 1000 PARMS = 1200 HEADER = 1500 EXIT = 1500 ENTRY = 1500 ENTRY_EXIT = 1500 ERROR = 1800 FFDC = 2000 # an unknown message that should always be logged UNKNOWN = 3000 end include Severity # The identifier used when a log entry is not associated with a # particular client. NO_CLIENT_ID = '*' # Define a method for logging each sev Severity.constants.each do |sev| define_method(sev.to_s.downcase) do |progname = NO_CLIENT_ID, &block| progname = NO_CLIENT_ID unless progname add(Severity.const_get(sev.to_s), nil, (sev.to_s.downcase + ' ' + progname), &block) end end def initialize(logdev, shift_age = 0, shift_size = 1048576) super(logdev, shift_age = 0, shift_size = 1048576) if ENV['MQLIGHT_RUBY_LOG'] \ && Severity.const_defined?(ENV['MQLIGHT_RUBY_LOG'].upcase) self.level = Severity.const_get(ENV['MQLIGHT_RUBY_LOG'].upcase) else self.level = FFDC end end def format_message(severity, datetime, progname, msg) "#{datetime.strftime('%H:%M:%S.%L')} "\ "[#{Process.pid}:#{Thread.current.object_id}] #{progname} #{msg}\n" end # Log an exception being thrown. # # @param name [String] The name of the method throwing the exception # @param err [String] The exception being thrown # @param id [String] The id of the client logging the exception def throw(name, err, id = NO_CLIENT_ID) id = NO_CLIENT_ID unless id.is_a? String add(ERROR, '* Thrown exception: ' + err.class.to_s \ + ': ' + err.to_s, ('error ' + id)) add(EXIT, (name.to_s + ' Exception thrown'), ('exit ' + id)) end def ffdc # TODO: this end end end end