1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-12-19 16:15:57 -05:00

Added log format and dateformat to config file

This patch moves the default log format string and date format string
to the config file, so users can format the logs as they see fit.
The default log format also includes the file and line number that
posted the log entry.

The new entries in the config are here:
aprsd:
  logformat: "String here"
  dateformat: "string here"
This commit is contained in:
Hemna 2021-02-25 13:32:50 -05:00
parent 239e784d51
commit 0a038dae44
2 changed files with 11 additions and 2 deletions

View File

@ -177,8 +177,8 @@ def signal_handler(sig, frame):
def setup_logging(config, loglevel, quiet): def setup_logging(config, loglevel, quiet):
log_level = LOG_LEVELS[loglevel] log_level = LOG_LEVELS[loglevel]
LOG.setLevel(log_level) LOG.setLevel(log_level)
log_format = "[%(asctime)s] [%(threadName)-12s] [%(levelname)-5.5s]" " %(message)s" log_format = config["aprsd"].get("logformat", utils.DEFAULT_LOG_FORMAT)
date_format = "%m/%d/%Y %I:%M:%S %p" date_format = config["aprsd"].get("dateformat", utils.DEFAULT_DATE_FORMAT)
log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format) log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
log_file = config["aprsd"].get("logfile", None) log_file = config["aprsd"].get("logfile", None)
if log_file: if log_file:

View File

@ -11,6 +11,13 @@ from aprsd import plugin
import click import click
import yaml import yaml
DEFAULT_LOG_FORMAT = (
"[%(asctime)s] [%(threadName)-12s] [%(levelname)-5.5s]"
" %(message)s - [%(pathname)s.%(funcName)s:%(lineno)d]"
)
DEFAULT_DATE_FORMAT = "%m/%d/%Y %I:%M:%S %p"
# an example of what should be in the ~/.aprsd/config.yml # an example of what should be in the ~/.aprsd/config.yml
DEFAULT_CONFIG_DICT = { DEFAULT_CONFIG_DICT = {
"ham": {"callsign": "CALLSIGN"}, "ham": {"callsign": "CALLSIGN"},
@ -22,6 +29,8 @@ DEFAULT_CONFIG_DICT = {
}, },
"aprsd": { "aprsd": {
"logfile": "/tmp/aprsd.log", "logfile": "/tmp/aprsd.log",
"logformat": DEFAULT_LOG_FORMAT,
"dateformat": DEFAULT_DATE_FORMAT,
"trace": False, "trace": False,
"plugin_dir": "~/.config/aprsd/plugins", "plugin_dir": "~/.config/aprsd/plugins",
"enabled_plugins": plugin.CORE_PLUGINS, "enabled_plugins": plugin.CORE_PLUGINS,