Skip to main content

A python module with sensible defaults for logging

Project description

  • version number: 0.0.3

  • date: 2023.02.10

  • author: Andrew J. Todd esq.

Overview

A python module to allow you to log with minimal fuss. It’s a wrapper around the standard logging module with sensible defaults and as little configuration as possible. Documentation is on [halfcooked.com](https://halfcooked.com/code/simple_log/)

Installation

To install use pip:

$ pip install simple_log

Or clone the repo:

$ hg clone https://hg.sr.ht/~andy47/simple_log $ python setup.py install

Usage

We try and stay true to the name and make using this module as simple as possible. For the simplest case just use

>>> from simple_log import get_log
>>> my_log = get_log()
>>> my_log.info("This is an information message")
2016.11.10 22:21:51 default INFO:: This is an information message

If you want to have multiple logs just pass a name to get_log

>>> first_log = get_log("first")
>>> first_log.info("Information message to first log")
2016.11.10 22:27:30 first INFO:: Information message to first log
>>> second_log = get_log("two")
>>> second_log.debug("This is a debug message")
2016.11.10 22:28:02 two DEBUG:: This is a debug message

By default the logging level is set to ‘INFO’ (the standard module defaults to ‘WARNING’). See the [logging tutorial](https://docs.python.org/3/howto/logging.html#logging-basic-tutorial) for information on logging levels. If you would like to change the logging level, for instance to display ‘DEBUG’ messages use the setLevel method on your log object

>>> from simple_log import get_log
>>> my_log = get_log('test_log')
>>> my_log.debug('This is the first debug message')
...
>>> my_log.setLevel('DEBUG')
>>> my_log.debug('This is the second debug message')
2016.11.10 22:34:55 test_log DEBUG:: This is the second debug message

The log level values that you can pass to setLevel are ‘DEBUG’, ‘INFO’ (the default), ‘WARNING’, ‘ERROR’ or ‘CRITICAL’.

If you would like your log messages written to a file as well as the screen use the add_file function

>>> from simple_log import get_log, add_file
>>> my_log = get_log('test_log')
>>> my_log.info('This is an information message')
2016.11.12 22:48:10 test_log INFO:: This is an information message
>>> add_file('test_log', 'test_log.log')
>>> my_log.info('This is another information message')
2016.11.12 22:49:30 test_log INFO:: This is another information message
>>> cat test_log.log
2016.11.12 22:49:30 test_log INFO:: This is another information message

Contributing

If you would like to contribute please visit the project web site at - https://hg.sr.ht/~andy47/simple_log

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_log-0.0.3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

simple_log-0.0.3-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file simple_log-0.0.3.tar.gz.

File metadata

  • Download URL: simple_log-0.0.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for simple_log-0.0.3.tar.gz
Algorithm Hash digest
SHA256 556f17e8004703f14c1a0628decc77c082475f73488a5feb0b6340ce76bfde1a
MD5 4405acfcf8819d45b47673b7c840181c
BLAKE2b-256 a7547eabdc79b991b86f39c4b22cbc672f52c802d406567538f068b498a5bfd6

See more details on using hashes here.

File details

Details for the file simple_log-0.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: simple_log-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for simple_log-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 634aee821e0241a69e42caf4c807393965b132fe3e18a9348eba515f634a4852
MD5 4e88e52eec748403b598efeed4aaea56
BLAKE2b-256 73b8943757f21e3e6bb2718d15f96469a4a1d5733da6198cb8671d8aad0db4d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page