You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved.
|
|
|
|
from ITOA.setup_logging import setup_logging, formatLoggerNameAndFile
|
|
|
|
# Make sure migration logger is called and initialized
|
|
# before any other import that can init global logger unexpectedly
|
|
|
|
|
|
def getMigrationLogger():
|
|
log_name, log_file = formatLoggerNameAndFile(logger_file=None, logger_name='itsi.migration')
|
|
# This call will return a separate logger object different from the singleton logger for the process.
|
|
return setup_logging(log_file, log_name)
|
|
|
|
|
|
logger = getMigrationLogger()
|
|
|
|
'''
|
|
PrefixLogger will prefix every log message
|
|
with a string specified once during logger init
|
|
'''
|
|
class PrefixLogger(object):
|
|
|
|
def __init__(self, prefix='', separator=': ', logger=getMigrationLogger()):
|
|
self.logger = logger
|
|
self.prefix = prefix
|
|
self.separator = separator
|
|
|
|
def withPrefix(self, msg):
|
|
return '%s%s%s' % (self.prefix, self.separator, msg)
|
|
|
|
def exception(self, msg, *args, **kwargs):
|
|
self.logger.exception(self.withPrefix(msg), *args, **kwargs)
|
|
|
|
def error(self, msg, *args, **kwargs):
|
|
self.logger.error(self.withPrefix(msg), *args, **kwargs)
|
|
|
|
def warning(self, msg, *args, **kwargs):
|
|
self.logger.warning(self.withPrefix(msg), *args, **kwargs)
|
|
|
|
warn = warning
|
|
|
|
def info(self, msg, *args, **kwargs):
|
|
self.logger.info(self.withPrefix(msg), *args, **kwargs)
|
|
|
|
def debug(self, msg, *args, **kwargs):
|
|
self.logger.debug(self.withPrefix(msg), *args, **kwargs)
|