Skip to content

Commit

Permalink
try to print in file
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Fievet committed Aug 20, 2024
1 parent 6e33bfe commit e863aac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions LIReC/jobs/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,41 @@
import sys
from LIReC.jobs.config import configuration
from LIReC.lib.pool import WorkerPool
import logging


MOD_PATH = 'LIReC.jobs.job_%s'


def setup_logging():
# Create a logger object
logger = logging.getLogger('LIReC')
logger.setLevel(logging.DEBUG) # Set the logging level to debug to capture all messages

# Create handlers for writing to file and stderr
file_handler = logging.FileHandler('logs/stdout.log')
stream_handler = logging.StreamHandler()

# Set the level and format for both handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
stream_handler.setFormatter(formatter)

# Add both handlers to the logger
logger.addHandler(file_handler)
logger.addHandler(stream_handler)

return logger


def main() -> None:
os.makedirs(os.path.join(os.getcwd(), 'logs'), exist_ok=True)
logger = setup_logging() # Set up logging configuration

# Log to both file and stderr
logger.info("logger.info Running run.main()")
logger.error("logger.error This is an error message with details.")

sys.stderr.write('Starting instance of WorkerPool...')
worker_pool = WorkerPool()
sys.stderr.write('worker_pool.start([(MOD_PATH % name, config) for name, config in configuration["jobs_to_run"]]):')
Expand Down
2 changes: 2 additions & 0 deletions run_lirec.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def run_lirec():
# from LIReC.jobs import run
# print("Running run.main()")
sys.stderr.write("Running run.main()\n")
print("Running run.main() from file=sys.stderr", file=sys.stderr)

run.main()

def main():
Expand Down

0 comments on commit e863aac

Please sign in to comment.