Skip to content

Commit

Permalink
🔊 Cut out the logger configuration to an external config.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
futabato committed Jun 11, 2024
1 parent caadf95 commit 1df5865
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
24 changes: 24 additions & 0 deletions config/logger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 1
formatters:
simple:
format: '%(asctime)s:%(name)s:%(levelname)s:%(message)s'
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
file:
class: logging.FileHandler
level: INFO
filename: '/workspace/outputs/main.log'
mode: 'w'
formatter: simple
loggers:
Logger:
level: DEBUG
handlers: [console, file]
propagate: no
root:
level: DEBUG
handlers: [console]
16 changes: 6 additions & 10 deletions src/federatedlearning/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python

import copy
import logging
import math
import os
import pickle
import time
from logging import getLogger
from logging.config import dictConfig

import hydra
import matplotlib
Expand All @@ -15,6 +16,7 @@
import pandas as pd
import torch
import torch.nn as nn
import yaml
from nptyping import Int, NDArray, Shape
from omegaconf import DictConfig, OmegaConf
from tqdm import tqdm
Expand All @@ -40,12 +42,8 @@ def main(cfg: DictConfig) -> float: # noqa: C901
# Record the start time for run duration
start_time: float = time.time()

logging.basicConfig(
level=logging.INFO,
format="%(levelname)s - %(asctime)s - %(message)s",
filename="/workspace/outputs/main.log",
)
logger = logging.getLogger(__name__)
dictConfig(yaml.safe_load(open("/workspace/config/logger.yaml").read()))
logger = getLogger("Logger")

# Setup paths and logging utilities
mlflow.set_tracking_uri(
Expand Down Expand Up @@ -403,9 +401,7 @@ def main(cfg: DictConfig) -> float: # noqa: C901
logger.info(
"\n Total Run Time: {0:0.4f}".format(time.time() - start_time)
)
mlflow.log_artifact(
f"/workspace/outputs/{EXPERIMENT_ID}_{RUN_ID}_{cfg.mlflow.run_name}.log"
)
mlflow.log_artifact("/workspace/outputs/main.log")
return test_acc


Expand Down

0 comments on commit 1df5865

Please sign in to comment.