Skip to content

Commit

Permalink
Merge pull request #38 from kchason/37-logger-handling
Browse files Browse the repository at this point in the history
Resolve #37: Logger Handler
  • Loading branch information
dc3-tsd authored Mar 21, 2024
2 parents 1de063f + f79de2a commit 68c569d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions sqlite_dissect/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import uuid
import warnings
from logging import CRITICAL
from logging import DEBUG
from logging import ERROR
from logging import INFO
from logging import WARNING
from logging import basicConfig
from logging import getLogger
from logging import CRITICAL, ERROR, WARNING, INFO, DEBUG, basicConfig, getLogger, StreamHandler, FileHandler
from os import path
from os.path import basename
from os.path import join
Expand Down Expand Up @@ -66,6 +60,7 @@ def main(arguments, sqlite_file_path, export_sub_paths=False):
raise SqliteError("Error in setting up logging: no log level determined.")

# Get the logging level
logger = getLogger(LOGGER_NAME)
logging_level_arg = arguments.log_level
logging_level = logging_level_arg
if logging_level_arg != "off":
Expand All @@ -81,14 +76,15 @@ def main(arguments, sqlite_file_path, export_sub_paths=False):
logging_level = DEBUG
else:
raise SqliteError("Invalid option for logging: {}.".format(logging_level_arg))
else:
logging_level = None

# Setup logging
logging_format = '%(levelname)s %(asctime)s [%(pathname)s] %(funcName)s at line %(lineno)d: %(message)s'
logging_data_format = '%d %b %Y %H:%M:%S'
basicConfig(level=logging_level, format=logging_format, datefmt=logging_data_format,
filename=arguments.log_file)
# Setup logging
basicConfig(level=logging_level,
format='%(levelname)s %(asctime)s [%(pathname)s] %(funcName)s at line %(lineno)d: %(message)s',
datefmt='%d %b %Y %H:%M:%S',
filename=arguments.log_file if arguments.log_file else None)

logger = getLogger(LOGGER_NAME)
logger.debug("Setup logging using the log level: {}.".format(logging_level))
logger.info("Using options: {}".format(arguments))

Expand Down
2 changes: 1 addition & 1 deletion sqlite_dissect/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def parse_args(args=None):
default=None,
metavar="LOG_FILE",
env_var="SQLD_LOG_FILE",
help="log file to write too, default is to write to console, ignored if log level set to off "
help="log file to write to; default is to write to console, ignored if log level set to off "
"(appends if file already exists)")

parser.add_argument("--warnings",
Expand Down

0 comments on commit 68c569d

Please sign in to comment.