Skip to main content

Simple Logging Utility

Project description

SimpleLogger is a simple logging utility for Python. I find the default Python logging module powerful, but extremely clunky and difficult to setup quickly. SimpleLogger supports basics such as output redirection, custom logging format, and logging levels.

Usage:

Log Levels and Threshold:

The current threshold that determines what level of log entries can be seen is set through Logger.set_threshold, passing a constant as the argument. Level constants include DEBUG, INFO, WARNING, ERROR, and CRITICAL. Changing the threshold only affects future entries.

Logging Formats:

Logging formats are set through Logger.set_format, passing a string of valid characters and substitution directives as arguments.

Valid subsitution directives include:

Directive

Substitution

{time}

The current time

{datetime}

The current date and time

{date}

The current date

{level}

The level of the entry

{text}

The text to be logged

Installation:

Recommended:

pip install simplelogger

The Hard Way:

python setup.py install

Examples:

Basic usage::

import simplelogger

# make a new logger that outputs to output_file.log, has a threshold of DEBUG, and the entry format is just the text to be logged
logger = simplelogger.Logger(stream=output_file.log, threshold=simplelogger.DEBUG, format="{text}")

logger.info("Log at the info level")
logger.warning("Log at the warning level")

if (foo > bar):
    # change the logging threshold to INFO
    logger.set_threshold(simplelogger.INFO)
else:
    # change the format to output the logged text, the date and time, and the time separated by characters
    logger.set_format("{text}: {datetime} - {time}")

License

Copyright (C) 2013 Tayler Mulligan

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

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

SimpleLogger-1.4.8.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file SimpleLogger-1.4.8.tar.gz.

File metadata

  • Download URL: SimpleLogger-1.4.8.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for SimpleLogger-1.4.8.tar.gz
Algorithm Hash digest
SHA256 adba696bdc186e752e2d9d5d6ebb9e113d8ecaf2b60c2384008841d56d592aac
MD5 8b0ac4ccd6e8bca0541a21f7155196ff
BLAKE2b-256 8112f88b51d77e6f299575d2aa0976bfb3b23ed1afed5bc69a9ed7d148f34b51

See more details on using hashes here.

Supported by

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