KeckObservatoryArchive / dep-rti

KOA Data Evaluation and Processing for Real Time Ingestion
0 stars 1 forks source link

Merge updates in Dev into Master, primarily for fix in hanging monitor on database select/insert. #89

Closed lfuhrman closed 1 year ago

tylertucker202 commented 1 year ago

On giving this a good second look, I'm not sure that log_msg is necessary. If configured correctly, the logger should be formatted to output to sdout. Furthermore it introduces some potentially confusing log level codes. We can most likely accomplish what log_msg sets out to do by setting up the logger correctly e.g.

import logging
import db_conn

def create_logger(fileName, logName):
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch = logging.StreamHandler()
    ch.setLevel(logging.INFO)
    ch.setFormatter(formatter)
    fl = logging.FileHandler(fileName)
    fl.setLevel(logging.INFO)
    fl.setFormatter(formatter)
    logger = logging.getLogger(logName)
    logger.addHandler(ch)
    logger.addHandler(fl)
    logger.setLevel(logging.INFO)
    return logger

logger = create_logger(fileName="/path/to/logger/file/name.log", logName="db_conn")
db = db_conn.db_conn('config.live.ini', configKey='DATABASE',
                                  persist=True, log_obj=logger)

Then just use the logger directly. No need for log_msg

lfuhrman commented 1 year ago

That is in case the logger object is not passed. It currently is configured to log to stdout, but there are several files that use db_conn. The log_msg is used to avoid the need to update a lot files right now in the released version.

tylertucker202 commented 1 year ago

Understood. In that case I will approve this pull request.