Simple File Logger
This python package provides a Logger class which is easy to use
for basic logging to files.
Install
pip install simple-file-logger
Usage
from simple_file_logger import Logger
logger = Logger("my_log_file", "path/to/log/directory")
logger.info("Hello!")
# writes to `my_log_file_YYYYMMDD_HHMM_SS.log`
# 2022-01-26 11:57:14,182 - INFO - Hello!
The constructor provides various options to configure the logger.
logfile_name: str,
log_dir: Union[Path, str, None]=None,
level=logging.DEBUG,
mode="w",
add_timestamp_to_filename=True,
log_to_console=False,
is_null_handler=False,
is_rolling_handler=False,
process: str = None,
-
To disable to console in addition to the file (default behavior), pass
log_to_console=False. -
The
is_rolling_handlerparameter controls whether the logger automatically writes to a new file when the existing one becomes larger than5mb. It will archive the current log with a serial number and transition to a new file automatically. The limit of archived files is5so the oldest one will get deleted when archiving for the 6th time. -
The
is_null_handlerparameter initializes a logger that does nothing. This is useful for unit testing libraries where functions log messages but you don't want any actual logging to take place. -
The
processparameter is a little addition to provide some info about what process the currently running script represents. It can be any arbitrary string, such asdownloading_dataormonitoring_filesetc. This process will also appear on each log line. As the script executes, you can set theprocessin the logger object to a new value. This is helpful for producing files which facilitate easy line extraction related to a specific process when the file is big.logger.process = "downloading_file" # ... logic to download some file which does some logging. # The lines will have `downloading_file` before the log message. # update file contents logger.process = "update_contents" # set process to indicate the context of log messages to follow # ... logic to update file contents and do some logging. # no need for further process logs, and just want to log messages. logger.process = "" # prevents addition of process string to log message.
Metadata
Release files for simple-file-logger 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simple-file-logger-0.1.6.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_file_logger-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.8 kB
Release files / simple-file-logger-0.1.6.tar.gz
| Download URL | simple-file-logger-0.1.6.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f47cb8f03e1d07f429770074bef47c937e053cd9b7008890054d0b6f256826af
|
|
BLAKE2b-256 checksum How to use checksums |
a7b42e8d36fa500de69367e911d444274a8d50915b3a76a8fe2fb2980808b523
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.10 Windows/10
|
Release files / simple_file_logger-0.1.6-py3-none-any.whl
| Download URL | simple_file_logger-0.1.6-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cbf6ea99d04eeee20d0f85d9d33bdcd6680ccff2560ceacdcdc79779a0308046
|
|
BLAKE2b-256 checksum How to use checksums |
f9c74cca787b927c28b57d08477cacc20281b530fac10a9d81e953a91c964eb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.10 Windows/10
|