File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,10 @@ formatters:
1818handlers :
1919 stdout :
2020 class : logging.StreamHandler
21- formatter : json
21+ formatter : simple
2222 stream : ext://sys.stdout
2323loggers :
2424 root :
25+ level : DEBUG
2526 handlers :
2627 - stdout
Original file line number Diff line number Diff line change 11import importlib .resources as ires
22import logging .config
33import logging .handlers
4+ from pathlib import Path
45
56import yaml
67
78from autointent .custom_types import LogLevel
89
910
10- def setup_logging (level : LogLevel | str ) -> None :
11+ def setup_logging (level : LogLevel | str , log_to_filepath : Path | str | None = None ) -> None :
1112 config_file = ires .files ("autointent._logging" ).joinpath ("config.yaml" )
1213 with config_file .open () as f_in :
1314 config = yaml .safe_load (f_in )
1415
1516 level = LogLevel (level )
16- config ["loggers" ]["root" ]["level" ] = level .value
17+ config ["handlers" ]["stdout" ]["level" ] = level .value
18+
19+ if log_to_filepath is not None :
20+ config ["loggers" ]["root" ]["handlers" ].append ("file" )
21+ config ["handlers" ]["file" ] = {
22+ "class" : "logging.FileHandler" ,
23+ "level" : "DEBUG" ,
24+ "formatter" : "json" ,
25+ "filename" : str (log_to_filepath ),
26+ }
27+
1728
1829 logging .config .dictConfig (config )
You can’t perform that action at this time.
0 commit comments