Skip to main content

An ugly, slow Logger class for python

Project description

uglylogger

An ugly, slow Logger class for python

FAQ

Why required python version is equal or greater than 3.10?

  • match .. case .. is introduced in 3.10 and I am not interested in supporting older releases

Why is it ugly?

  • I am not an expert on Python
  • It is not thread-safe
  • I don't know what happens if two instances are created with the same name, and I don't care. I'd never do that
  • The solo purpose is to have an easy to use and easy to read logger class

Why is it ugly but not that ugly?

  • it is easy to use and easy to read
  • I may keep this library up-to-date and even optimize it in the future
  • at least it has a CI/CD pipeline

Installation

pip install uglylogger

Release Notes

Release notes

Usage

Instantiate

# A logger which can log both to console and to a file
logger = Logger("name", "file.log")  

# A logger which can only log to console
logger = Logger("name")  

Release the resources

logger.release()
  • Releases the resources, it's safe to delete the log file after calling this method

Color Mode

logger.set_color_mode(LogColorMode.COLORED)
  • coloroed output if the console/terminal supports it
logger.set_color_mode(LogColorMode.MONO)
  • no color used for the console/terminal output

Log to console

logger.console("Message", color=LogColor.BLACK, level=LogLevel.DEBUG)
  • color and level are optional
  • if not provided, default color is BLACK
  • if not provided, default level is DEBUG

Log to file

logger.file("Message", level=LogLevel.DEBUG)
  • level is optional
  • if not provided, default level is DEBUG
  • if instantiated without a file name, nothing happens

Log to both file and console

logger.log("Message", color=LogColor.BLACK, level=LogLevel.DEBUG, output=LogOutput.ALL)
  • color, level and output are optional
  • if not provided, default color is BLACK
  • if not provided, default level is DEBUG
  • if not provided, default output is ALL
  • if instantiated without a file name, writing to file is ignored

Other ways of logging

logger.debug("Message", color=LogColor.BLACK, output=LogOutput.ALL)
logger.info("Message", color=LogColor.BLACK, output=LogOutput.ALL)
logger.warning("Message", color=LogColor.BLACK, output=LogOutput.ALL)
logger.error("Message", color=LogColor.BLACK, output=LogOutput.ALL)
logger.critical("Message", color=LogColor.BLACK, output=LogOutput.ALL)

Available LogColor

- BLACK
- RED
- GREEN
- YELLOW
- BLUE
- MAGENTA
- CYAN
- WHITE

Available LogLevel

- DEBUG
- INFO
- WARNING
- ERROR
- CRITICAL

Available LogOutput

- NONE
- CONSOLE
- FILE
- ALL

set log format

logger.set_format([
    ...
    LogFormatBlock.XXX
    ...
])

Available LogFormatBlock

- NAME
- LEVEL
- DATETIME
- MESSAGE
- FILE
- LINE
- FUNCTION

Example Formats

logger.set_format([LogFormatBlock.MESSAGE])
logger.console("Hello World!")
# Output : Hello World!
logger.set_format([
    "[",
    LogFormatBlock.LEVEL,
    "] ",
    LogFormatBlock.MESSAGE]
)
logger.console("Hello World!")
# Output : [DEBUG] Hello World!

Move the log file to another location

logger.move(new_file: str, option: LogMoveOption)
# Output : Hello World!

Available LogMoveOption

- MOVE_AND_APPEND  
   Moves the log file to the destination
   Deletes if there's already a file in the destination
   Appends to the moved file
   Old file is obviously deleted
- COPY_AND_APPEND  
   Copies the log file to the destination
   Deletes if there's already a file in the destination
   Appends to the moved file
   Old file is obviously remains    
- KEEP_AND_APPEND  
   Keeps the old log file
   Appends if there's already a file in the destination
   Creates a new file if not
- KEEP_AND_INIT  
   Keeps the old log file
   Creates a new file in the destination    
- DELETE_AND_INIT  
   Deletes the old log file
   Creates a new file in the destination

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

uglylogger-0.6.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

uglylogger-0.6.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file uglylogger-0.6.1.tar.gz.

File metadata

  • Download URL: uglylogger-0.6.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for uglylogger-0.6.1.tar.gz
Algorithm Hash digest
SHA256 2667e0b38f4d9ae5362a917d76e8b262a24bf42df35cc46cc07d6465f13f807e
MD5 a815a7c1d0e115d48e57d52d9d430a28
BLAKE2b-256 92b3833142ec441720f1bb8c6af5035a42b60730f75d9dc29912e87eec469e42

See more details on using hashes here.

Provenance

File details

Details for the file uglylogger-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: uglylogger-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for uglylogger-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e68bf580e43b2f099a9e43d94b6893d7dac8a4bba27f1d08b8c55923942bda5e
MD5 16c43b0afd58e2fb33d6da0f5cbf23db
BLAKE2b-256 5a5b866464929572583d015073e443ebe53413ffe194638f6cfc9212d6e7813a

See more details on using hashes here.

Provenance

Supported by

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