Skip to main content

A simple logger for basic projects

Project description

ApplePyLog

A simple logging library for small projects. There are 4 Logging levels:

  • Error
  • Info
  • Warn
  • Debug

You can write to any of these levels and change the current log level of what gets printed from the logger The log levels work as the order above so a log level of Error will only print Error logs A log level of Warn will print Warn, Info and Error logs but not Debug The default log level is Warn

You can pass in any writer with type TextIO, the default is sys.stdout but you can also pass in file writers

You can also specify an alternate writer, which defaults to None, which will write the same as the main writer, this can be useful to write your logs to stdout and also save them to a file. This alternate writer also has its own log level that can be specified, also with default of WARN.

Basic Usage:

from applepylog import Logger

# Creates a logger to stdout
_logger = Logger("Test Logger")
_logger.info("test message") # logs "<timestamp> INFO Test Logger, test message"
_logger.debug("test message") # doesnt log anything because default log level is warn

Changing Log Level:

from applepylog import Logger, LogLevel

#Prints nothing because logger is in error level
_logger = Logger("Test Logger", log_level=LogLevel.ERROR)
_logger.info("test message")

Changing writer:

from applepylog import Logger
import sys

# Creates a logger to stderr
_logger = Logger("Test Logger", writer=sys.stderr)
_logger.info("test message")

# Creates a logger to a file
file = open("log_file.txt", "w+")
_other_logger = Logger("Test Logger", writer=file)
_other_logger.info("file test message")

Using the alternate writer:

from applepylog import Logger
import sys

file = open("./log_file.txt", "w+")
_logger = Logger("Test Logger", writer=sys.stdout, alt_writer=file)
# Writes same log message to both stdout and the log file
_logger.info("test message")

Using the alternate writer with a different log level:

from applepylog import Logger, LogLevel
import sys

file = open("./log_file.txt", "w+")
_logger = Logger("Test Logger", writer=sys.stdout, log_level=LogLevel.ERROR, alt_writer=file, alt_log_level=LogLevel.INFO)
# Writes to the log file but not stdout because of the Log levels of the writers
_logger.info("test message")

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

applepylog-0.1.4.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

applepylog-0.1.4-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file applepylog-0.1.4.tar.gz.

File metadata

  • Download URL: applepylog-0.1.4.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for applepylog-0.1.4.tar.gz
Algorithm Hash digest
SHA256 5572c54c7d02805a6dce4abdd72840283b9161dca11a4c0ffc2cd21b43024f8e
MD5 6d9efd91f415904f914358ce026eb1cf
BLAKE2b-256 3d433363c01111b98b53c97826571824a0fe0d3270d8b7f6d935fcdae9d71dd1

See more details on using hashes here.

File details

Details for the file applepylog-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: applepylog-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for applepylog-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b2cd16fdc8e6a5cd8ca129002d60e3b418a431434203ef3637d955df2e93381a
MD5 cd8338299eb76f80ca2491d0f1608147
BLAKE2b-256 1119564b4a93724e40df685f8fdb598d9188dca03c24bbbfe1df7704bbc70752

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