Skip to main content

Use `error`, `warn`, `info`, `debug`, `log` like you use `print`

Project description

StupidLogger

This logger is as simple as it can be with the following features :

  • 5 logging levels : error, warn, info, debug, trace
  • an intuitive python-style syntax
  • easy customization for the colors and header info
  • with documentation for easy use

It's based on package colored for the default log colors and styles, but you can also use colorama or custom escape sequences to set your own colors.

Here's a usage example :

import stupidlogger as log

def test_all_levels():
    # supports multiple arguments separated by commas like print
    log.error("Division of", 54 % 27, "by", 2 - 2, "is not allowed")

    # you can optionally specify `sep` and `end`
    log.warn(*["fruit", "vegetable", "fish", "meat"],
             sep=", ", end=" weren't found in the fridge\n")
    log.info("OPERATION SUCCESS", end="\n\n")

    # you can filter the logs you want to see
    log.debug("This will not be printed")
    # default log level is `INFO`
    log.setLogLevel(log.LogLevels.TRACE)
    i = 254
    log.debug("i =", i)

    # you can output to a file (without the colors)
    file = open("stupidlog", "w")
    log.debug("This will be printed to a file", file=file)

    log.trace("Entire content of a list :", list(range(9)), end="\n\n")

test_all_levels()

5 logging levels : error, warn, info, debug, trace

You can filter out logs by using setLogLevel. The default level is LogLevels.INFO.

from stupidlogger import *

setLogLevel(LogLevels.DEBUG)

It uses Python's print syntax

Contrary to the logging module, you can print multiple arguments separated by commas.

info("This is a useful message with data", 54 + 25,
     "and other stuff", list(range(1)), end="\n\n")

Actually the log functions' signatures are exactly the same as for print (you can also print to a file!).

info(*objects, sep=' ', end='\n', file=None, flush=False)

The colors and header info are entirely customizable

The log outputs are made of two parts : the header and the message.

You can change the information in the header using setHeader, and its color using setSecondaryColor.

You can also change the 5 colors associated with the log levels using setLogColors.

Here's an example script using colorama and its output :

from stupidlogger import *
from colorama import Fore

setLogLevel(LogLevels.TRACE)
setHeader("{color}{filename}:{lineno} ({function}) {log_name}:{reset} ")
setLogColors([Fore.BLUE, Fore.CYAN, Fore.GREEN, Fore.YELLOW, Fore.BLACK])
error("error")
warn("warn")
info("info")
debug("debug")
trace("trace")

If you have questions

log.py contains the interface. It's well documented and should provide the answers about how to use the code. The structure itself is in loglib.py and should provide the answers about how it works.

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

stupidlogger-1.0.0.tar.gz (87.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stupidlogger-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file stupidlogger-1.0.0.tar.gz.

File metadata

  • Download URL: stupidlogger-1.0.0.tar.gz
  • Upload date:
  • Size: 87.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.12

File hashes

Hashes for stupidlogger-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0485f32a23a2b09549fd970a2291d201ba2ec03aef2fe5395fa3c25ed5bb7115
MD5 2e79c76685bf47a691b29b59570dc96d
BLAKE2b-256 d4bbbd4a53191a42d7416d3a765788dcde8f73cfa8dac99fa729e2f6ae1c7177

See more details on using hashes here.

File details

Details for the file stupidlogger-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: stupidlogger-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.12

File hashes

Hashes for stupidlogger-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf0f9c679cce93e749f18093e797c540573cbd14d82c0d32bcbaa663f5bfa285
MD5 9cd78abfec0d0a28077d6da63b261c6f
BLAKE2b-256 d32fbf14ba4ca26df6f6c0796386a8b607f0061c20a4015a8ce9153b00832ee2

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