1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-07-19 00:35:16 -04:00

CONF.logging.enable_color option added

This allows the user to turn off ANSI color output for
logging to the console.
This commit is contained in:
Hemna 2025-02-20 12:44:16 -05:00
parent 4fd64a3c25
commit 06bdb34642
2 changed files with 28 additions and 23 deletions

View File

@ -7,47 +7,52 @@ import logging
from oslo_config import cfg from oslo_config import cfg
LOG_LEVELS = { LOG_LEVELS = {
"CRITICAL": logging.CRITICAL, 'CRITICAL': logging.CRITICAL,
"ERROR": logging.ERROR, 'ERROR': logging.ERROR,
"WARNING": logging.WARNING, 'WARNING': logging.WARNING,
"INFO": logging.INFO, 'INFO': logging.INFO,
"DEBUG": logging.DEBUG, 'DEBUG': logging.DEBUG,
} }
DEFAULT_DATE_FORMAT = "%m/%d/%Y %I:%M:%S %p" DEFAULT_DATE_FORMAT = '%m/%d/%Y %I:%M:%S %p'
DEFAULT_LOG_FORMAT = ( DEFAULT_LOG_FORMAT = (
"[%(asctime)s] [%(threadName)-20.20s] [%(levelname)-5.5s]" '[%(asctime)s] [%(threadName)-20.20s] [%(levelname)-5.5s]'
" %(message)s - [%(pathname)s:%(lineno)d]" ' %(message)s - [%(pathname)s:%(lineno)d]'
) )
DEFAULT_LOG_FORMAT = ( DEFAULT_LOG_FORMAT = (
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | " '<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | '
"<yellow>{thread.name: <18}</yellow> | " '<yellow>{thread.name: <18}</yellow> | '
"<level>{level: <8}</level> | " '<level>{level: <8}</level> | '
"<level>{message}</level> | " '<level>{message}</level> | '
"<cyan>{name}</cyan>:<cyan>{function:}</cyan>:<magenta>{line:}</magenta>" '<cyan>{name}</cyan>:<cyan>{function:}</cyan>:<magenta>{line:}</magenta>'
) )
logging_group = cfg.OptGroup( logging_group = cfg.OptGroup(
name="logging", name='logging',
title="Logging options", title='Logging options',
) )
logging_opts = [ logging_opts = [
cfg.StrOpt( cfg.StrOpt(
"logfile", 'logfile',
default=None, default=None,
help="File to log to", help='File to log to',
), ),
cfg.StrOpt( cfg.StrOpt(
"logformat", 'logformat',
default=DEFAULT_LOG_FORMAT, default=DEFAULT_LOG_FORMAT,
help="Log file format, unless rich_logging enabled.", help='Log file format, unless rich_logging enabled.',
), ),
cfg.StrOpt( cfg.StrOpt(
"log_level", 'log_level',
default="INFO", default='INFO',
choices=LOG_LEVELS.keys(), choices=LOG_LEVELS.keys(),
help="Log level for logging of events.", help='Log level for logging of events.',
),
cfg.BoolOpt(
'enable_color',
default=True,
help='Enable ANSI color codes in logging',
), ),
] ]

View File

@ -89,7 +89,7 @@ def setup_logging(loglevel=None, quiet=False):
'sink': sys.stdout, 'sink': sys.stdout,
'serialize': False, 'serialize': False,
'format': CONF.logging.logformat, 'format': CONF.logging.logformat,
'colorize': True, 'colorize': CONF.logging.enable_color,
'level': log_level, 'level': log_level,
}, },
] ]