Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init():
if len(logging.getLogger("").handlers) > 1:
return
shandler = logging.StreamHandler(stream=sys.stdout)
shandler.setFormatter(colorlog.LevelFormatter(
fmt = {
"DEBUG": "{log_color}[{levelname}] {message}",
"INFO": "{log_color}[{levelname}] {message}",
"WARNING": "{log_color}[{levelname}] {message}",
"ERROR": "{log_color}[{levelname}] {message}",
"CRITICAL": "{log_color}[{levelname}] {message}"
},
log_colors = {
"DEBUG": "cyan",
"INFO": "white",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "bold_red"
},
style = "{",
datefmt = ""
def init():
if len(logging.getLogger("").handlers) > 1:
return
shandler = logging.StreamHandler(stream=sys.stdout)
shandler.setFormatter(colorlog.LevelFormatter(
fmt = {
"DEBUG": "{log_color}[{levelname}] {message}",
"INFO": "{log_color}[{levelname}] {message}",
"WARNING": "{log_color}[{levelname}] {message}",
"ERROR": "{log_color}[{levelname}] {message}",
"CRITICAL": "{log_color}[{levelname}] {message}"
},
log_colors = {
"DEBUG": "cyan",
"INFO": "white",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "bold_red"
},
style = "{",
datefmt = ""
lfile_formatter = logging.Formatter(
'[%(asctime)s] [%(levelname)s]\t%(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
uu = uuid.uuid4()
# Temporary log file path, to be changed later.
lfile_path = os.path.abspath(f'/tmp/{user_name}_{uu}_elektronn3.log')
lfile_level = logging.DEBUG
lfile_handler = logging.FileHandler(lfile_path)
lfile_handler.setLevel(lfile_level)
lfile_handler.setFormatter(lfile_formatter)
logger.addHandler(lfile_handler)
lstream_handler = colorlog.StreamHandler(sys.stdout)
lstream_handler.setFormatter(
colorlog.LevelFormatter(fmt=log_level_formats,
log_colors=log_colors))
# set this to logging.DEBUG to enable output for logger.debug() calls
lstream_level = logging.INFO
lstream_handler.setLevel(lstream_level)
logger.addHandler(lstream_handler)
logger.propagate = False
if False: # Test log levels:
logger.critical('== critical')
logger.error('== error')
logger.warning('== warn')
logger.info('== info')
logger.debug('== debug')
def _setup_logging(self):
if len(logging.getLogger(__package__).handlers) > 1:
log.debug("Skipping logger setup, already set up")
return
shandler = logging.StreamHandler(stream=sys.stdout)
shandler.setFormatter(colorlog.LevelFormatter(
fmt = {
'DEBUG': '{log_color}[{levelname}:{module}] {message}',
'INFO': '{log_color}{message}',
'WARNING': '{log_color}{levelname}: {message}',
'ERROR': '{log_color}[{levelname}:{module}] {message}',
'CRITICAL': '{log_color}[{levelname}:{module}] {message}',
'EVERYTHING': '{log_color}[{levelname}:{module}] {message}',
'NOISY': '{log_color}[{levelname}:{module}] {message}',
'VOICEDEBUG': '{log_color}[{levelname}:{module}][{relativeCreated:.9f}] {message}',
'FFMPEG': '{log_color}[{levelname}:{module}][{relativeCreated:.9f}] {message}'
},
log_colors = {
'DEBUG': 'cyan',
'INFO': 'white',
'WARNING': 'yellow',
def _setup_logging(self):
if len(logging.getLogger(__package__).handlers) > 1:
log.debug("Skipping logger setup, already set up")
return
shandler = logging.StreamHandler(stream=sys.stdout)
shandler.setFormatter(colorlog.LevelFormatter(
fmt = {
'DEBUG': '{log_color}[{levelname}:{module}] {message}',
'INFO': '{log_color}{message}',
'WARNING': '{log_color}{levelname}: {message}',
'ERROR': '{log_color}[{levelname}:{module}] {message}',
'CRITICAL': '{log_color}[{levelname}:{module}] {message}',
'EVERYTHING': '{log_color}[{levelname}:{module}] {message}',
'NOISY': '{log_color}[{levelname}:{module}] {message}',
'VOICEDEBUG': '{log_color}[{levelname}:{module}][{relativeCreated:.9f}] {message}',
'FFMPEG': '{log_color}[{levelname}:{module}][{relativeCreated:.9f}] {message}'
},
log_colors = {
'DEBUG': 'cyan',
'INFO': 'white',
'WARNING': 'yellow',
logger.setLevel(logging.DEBUG)
lfile_formatter = logging.Formatter(
'[%(asctime)s] [%(levelname)s]\t%(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
lfile_path = os.path.abspath('/tmp/{}_elektronn2.log'.format(user_name))
lfile_level = logging.DEBUG
lfile_handler = logging.FileHandler(lfile_path)
lfile_handler.setLevel(lfile_level)
lfile_handler.setFormatter(lfile_formatter)
logger.addHandler(lfile_handler)
if colorize:
lstream_handler = colorlog.StreamHandler(sys.stdout)
lstream_handler.setFormatter(
colorlog.LevelFormatter(fmt=log_level_formats,
log_colors=log_colors))
else:
lstream_handler = logging.StreamHandler(sys.stdout)
# set this to logging.DEBUG to enable output for logger.debug() calls
lstream_level = logging.INFO
lstream_handler.setLevel(lstream_level)
logger.addHandler(lstream_handler)
logger.propagate = False
if False: # Test log levels:
logger.critical('== critical')
logger.error('== error')
logger.warning('== warn')
logger.info('== info')
logger.debug('== debug')