A simple logger class to log to files
Project description
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,
is_console_only=False,
is_null_handler=False,
is_rolling_handler=False,
process: str = None,
-
To create a console-only handler, pass an empty string for the first argument, and set
is_console_onlytoTrue. -
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple-file-logger-0.1.5.tar.gz.
File metadata
- Download URL: simple-file-logger-0.1.5.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.9.10 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baea91f2ce00298bb7fd04713c56c3ab2c55be6c122a45dd637e74c74947aca3
|
|
| MD5 |
a46fcd2d01b08e817e990c3e958d796c
|
|
| BLAKE2b-256 |
478d361c70090cc5de22943ca140f5038c2955b3d0ea77eb886350ae96fbb719
|
File details
Details for the file simple_file_logger-0.1.5-py3-none-any.whl.
File metadata
- Download URL: simple_file_logger-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.9.10 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dd11eb5d600ff3bdd5c1a4fc1662f021fdf1dc8f634f8c98ddcdcef275041d7
|
|
| MD5 |
b2ebd89beda2e6b68513aa7f583f5360
|
|
| BLAKE2b-256 |
d9015ceaf1c3307f27fa08d5bb8b5f9a136eed7ea29c257fee4495fc160d1cb5
|