Skip to main content

A lightweight and highly customizable package that can ouput colored logs to the console.

Project description

MSColorLog

A highly customizable package that can ouput colored logs to the console.


example

Usage:

Importing the package:

import mscolorlog as cl

Initializing the logger:

logger = cl.Logging([LOGGING LEVEL], [LOGGING ELEMENT1], [LOGGING ELEMENT2], ...)

Logging Levels:

  • Logging.DEBUG
  • Logging.INFO
  • Logging.WARNING
  • Logging.ERROR
  • Logging.CRITICAL

NOTICE that the Logger will only output logs that are equal to or higher than the logging level.

Logging Elements:

Format: "&MODE:BACKGROUND:FOREGROUND:$VALUE" or "&MODE:BACKGROUND:FOREGROUND:TEXT"

Modes:

  • default
  • highlight
  • underline
  • blink
  • reverse
  • invisible

NOTICE that the modes may not compatible for all consoles

Leave blank to use default mode

Back/Foreground colors:

  • black
  • red
  • green
  • yellow
  • blue
  • purple
  • cyan
  • white

Leave blank to use default color

Values:

  • $info.processName
  • $info.pid
  • $info.time
  • $type.type (Log level name)
  • $message.message (Log message)

Next, more values will be updated

You can also put your own text in the value section and the logger will output the text instead of the value.

NOTICE that "$" means the value is a variable, and the logger will output the value of the variable. and "$$" means a "$" sign.

Also, color section can be omitted, and the logger will use the default color.

For example:

&underline::yellow:$$123
&::red:$$123
&:::$$123
$$123

The logger will output: $123 but with different colors and patterns.

Change the color of log level:

The Color of the Log Level can be changed by: If the function isn't called, the logger will use the default color.

logger.setColor(MODE=PATTERN, MODEMsgToo=True/False, ...)

The PATTERN can be any color in the color list above, the format is the same as the logging elements.

The MODEMsgToo means whether the logger will change the pattern of the log message too.

For example:

logger.setColor(info="&::red:", infoMsgToo=True)

The logger will change the color of the log level INFO to red, and the color of the log message to red too. If you have set the color of the log message, this will override the previous setting. You can call the function multiple times.

Change the level of logger:

You can use the following code to change the level of the logger:

 logger.setMode(MODE)

Output Log Messages:

Use the following code to output log messages:

logger.pdebug(MESSAGE)
logger.pinfo(MESSAGE)
logger.pwarning(MESSAGE)
logger.perror(MESSAGE)
logger.pcritical(MESSAGE)

Example:

Use the following code to output log messages like the image above:

import mscolorlog as cl

if __name__ == "__main__":
    log = cl.Logging(cl.Logging.WARNING,
                     "&::yellow:[", "&::green:$info.time", "&::yellow:] ",
                     "&::blue:$info.processName",
                     "&::blue:(", "&::blue:$info.pid", "&::blue:) ",
                     "$type.type", "&::cyan:> ", "&:black:white:$message.message")

    log.pdebug("debugMessage")
    log.pinfo("infoMessage")
    log.pwarning("warningMessage")
    log.perror("errorMessage")
    log.pcritical("criticalMessage")

    log.setMode(cl.Logging.DEBUG)
    log.setColor(critical="&::purple:", criticalMsgToo=False)

    log.pdebug("debugMessage")
    log.pinfo("infoMessage")
    log.pwarning("warningMessage")
    log.perror("errorMessage")
    log.pcritical("criticalMessage")

Life is short, I use Python.

HAVE FUN!

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

mscolorlog-1.0.1.tar.gz (79.9 kB view details)

Uploaded Source

Built Distribution

mscolorlog-1.0.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file mscolorlog-1.0.1.tar.gz.

File metadata

  • Download URL: mscolorlog-1.0.1.tar.gz
  • Upload date:
  • Size: 79.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.6

File hashes

Hashes for mscolorlog-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3414b0dd869460102f3f082966ef490663cfc5c817f16cb1c415ebd021c9bfde
MD5 427fae15f87e21c0e183674d1ac756cf
BLAKE2b-256 4f14484df9a3add790b2aaa33b7b733064c87bb4cf16a42f04fbd60aaf860381

See more details on using hashes here.

Provenance

File details

Details for the file mscolorlog-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mscolorlog-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.6

File hashes

Hashes for mscolorlog-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d747317cd886f032d4fcd44608027dbfc5c02060e6109ec825e410faa132fdc
MD5 275164b3713ee67471e9fc48f518c16f
BLAKE2b-256 fb2e6a337b4744625345c58edf5ceef685d2723be95abc8bd2fe5ebced62c1be

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