-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve printing and logging (#26)
- Loading branch information
Showing
7 changed files
with
105 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
from datetime import datetime | ||
|
||
|
||
def get_logger(name: str) -> logging.Logger: | ||
""" | ||
Create a logger instance, | ||
set its level to INFO, | ||
and configure it to write to a file in the user's home directory. | ||
Args: | ||
name: name of the logger | ||
filesize_mb: maximum size per log file in MB, defaults to 5 | ||
backupcount: number of log files to keep, defaults to 4 | ||
Returns: | ||
the logger instance | ||
""" | ||
_logger = logging.getLogger(name) | ||
_logger.setLevel(logging.INFO) | ||
formatter = logging.Formatter(fmt="{asctime} {filename: <25} {levelname: <8} {message}", style="{") | ||
formatter.default_time_format = "%Y-%m-%d %H:%M:%S" | ||
handler = logging.FileHandler( | ||
filename="logging.log", | ||
mode="a", | ||
) | ||
handler.setFormatter(formatter) | ||
_logger.addHandler(handler) | ||
return _logger | ||
|
||
|
||
def get_timestamp() -> str: | ||
return datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters