1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-06-15 04:42:26 -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
LOG_LEVELS = {
"CRITICAL": logging.CRITICAL,
"ERROR": logging.ERROR,
"WARNING": logging.WARNING,
"INFO": logging.INFO,
"DEBUG": logging.DEBUG,
'CRITICAL': logging.CRITICAL,
'ERROR': logging.ERROR,
'WARNING': logging.WARNING,
'INFO': logging.INFO,
'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 = (
"[%(asctime)s] [%(threadName)-20.20s] [%(levelname)-5.5s]"
" %(message)s - [%(pathname)s:%(lineno)d]"
'[%(asctime)s] [%(threadName)-20.20s] [%(levelname)-5.5s]'
' %(message)s - [%(pathname)s:%(lineno)d]'
)
DEFAULT_LOG_FORMAT = (
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | "
"<yellow>{thread.name: <18}</yellow> | "
"<level>{level: <8}</level> | "
"<level>{message}</level> | "
"<cyan>{name}</cyan>:<cyan>{function:}</cyan>:<magenta>{line:}</magenta>"
'<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | '
'<yellow>{thread.name: <18}</yellow> | '
'<level>{level: <8}</level> | '
'<level>{message}</level> | '
'<cyan>{name}</cyan>:<cyan>{function:}</cyan>:<magenta>{line:}</magenta>'
)
logging_group = cfg.OptGroup(
name="logging",
title="Logging options",
name='logging',
title='Logging options',
)
logging_opts = [
cfg.StrOpt(
"logfile",
'logfile',
default=None,
help="File to log to",
help='File to log to',
),
cfg.StrOpt(
"logformat",
'logformat',
default=DEFAULT_LOG_FORMAT,
help="Log file format, unless rich_logging enabled.",
help='Log file format, unless rich_logging enabled.',
),
cfg.StrOpt(
"log_level",
default="INFO",
'log_level',
default='INFO',
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,
'serialize': False,
'format': CONF.logging.logformat,
'colorize': True,
'colorize': CONF.logging.enable_color,
'level': log_level,
},
]