Skip to main content

Simple File Logger

This python package provides a Logger class which is easy to use for basic logging to files.

Install

pip install better-file-logger

Usage

from better_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_only to True.

  • The is_rolling_handler parameter controls whether the logger automatically writes to a new file when the existing one becomes larger than 5mb. It will archive the current log with a serial number and transition to a new file automatically. The limit of archived files is 5 so the oldest one will get deleted when archiving for the 6th time.

  • The is_null_handler parameter 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 process parameter is a little addition to provide some info about what process the currently running script represents. It can be any arbitrary string, such as downloading_data or monitoring_files etc. This process will also appear on each log line. As the script executes, you can set the process in 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.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-file-logger 0.1.4
File Size Uploaded Provenance Actions
simple-file-logger-0.1.4.tar.gz 4.3 kB Without provenance Details for simple-file-logger-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-file-logger 0.1.4
File Interpreter ABI Platform Actions
simple_file_logger-0.1.4-py3-none-any.whl Python 3 none any Details for simple_file_logger-0.1.4-py3-none-any.whl

Total release size: 8.8 kB

Release files / simple-file-logger-0.1.4.tar.gz

Download URL simple-file-logger-0.1.4.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7b0e5c9357af467bec78db525308fb0af4affd948299ab7994e6f05cff6fa95b
BLAKE2b-256 checksum
How to use checksums
d9c8490329f0c4829ed82047e364f4c77f428043647f0651cca192ca52f7de84
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.4-py3-none-any.whl

Download URL simple_file_logger-0.1.4-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8b7c53bc77a95881504e5068a6874033933f17c4fb69261bafcaf63b124cb67
BLAKE2b-256 checksum
How to use checksums
5f3dfaab7d88f1ecdcdd2092b85249518cd732185c639597c159325b3573cd18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.10 Windows/10

Security for simple-file-logger 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page