Skip to main content

Colored Logger for Python

Project description

https://img.shields.io/pypi/v/coloredlogger.svg https://img.shields.io/badge/wheel-yes-brightgreen.svg https://travis-ci.org/fmakdemir/colored-logger.svg?branch=master

Colored Logger for Python that uses clorama for colorful output with timestamp and customizable format. Colored Logger has timestamp, colored header or full line, and custom time format

Colored Logger for Python that uses clorama for colorful output with timestamp and customizable format

Setup

Use pip install coloredlogger to install using pip or use source code and install requirements with pip install -r requirements.txt

get a logger with:

from coloredlogger import ColoredLogger
logger = ColoredLogger(name=OPTIONAL_LOGGER_NAME)

or get logger with optional config name and config

import coloredlogger
logger = coloredlogger.get_logger(name=OPTIONAL_LOGGER_NAME, OPTIONAL_CONFIG_LIST)

log using pre-setup methods:

logger.wtf('WTF??')
logger.error('Omg red as rose error')
logger.success('Such success much green wow')
logger.info('just a blue info')
logger.verbose('some log here')

And you should see:

https://github.com/Fmakdemir/colored-logger/blob/master/assets/coloredlog-1.png?raw=true

or make your own log method using a name prefix color level and whether only header will be colored or the whole line:

logger.add_config('my-log', {'prefix': "ROCK!",'color': ColoredLogger.COLORS.CYAN, 'header-only': True})
logger.log('my-log', 'YOU!')
logger.log('my-log', 'ALL!')
logger.log('my-log', 'test', 'with', 'at', 'symbols', sep='@')

And you should see:

https://github.com/Fmakdemir/colored-logger/blob/master/assets/coloredlog-2.png?raw=true

You can also overwrite previous configs by:

logger.add_config('error', {'prefix': 'Custom error with {{TIME}}: ', 'timestamp': '[%Hh:%Mm:%Ss]', 'header-only': True})

This will overwrite error config’s properties with given ones which are prefix, timestamp and header-only

https://github.com/Fmakdemir/colored-logger/blob/master/assets/coloredlog-3.png?raw=true

Adding a new config using logger name and init configs is done as in following:

logger = get_logger('MY LOG', [{'config_name': 'custom-log', 'config': {'timestamp': '%Y/%m/%d %H:%M:%S'}}])
logger.info('This should have [MY LOG] [?] as prefix')
logger.success('This should have [MY LOG] [+] as prefix')
logger.verbose('Yeey')
logger.log('custom-log', 'This custom log should have overwritten timestamp')
https://github.com/Fmakdemir/colored-logger/blob/master/assets/coloredlog-4.png?raw=true

Config object

All keys are optional and if not given will be overridden by defaults

{
    'level': 10, # integer
    'timestamp': '%Y-%m-%d %H:%M:%S', # timestamp format used with strftime
    'prefix': '[ ]', # prefix which can include {{TIME}} to put timestamp with
    'color': coloredlogger.COLORS.WHITE, # one of coloredlogger.COLORS
    'header-only': False # whether or not color whole line or just header
}

COLORS Object

Following colors are supported:

Normal: BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW

Light: LIGHTBLACK_EX, LIGHTBLUE_EX, LIGHTCYAN_EX, LIGHTGREEN_EX, LIGHTMAGENTA_EX, LIGHTRED_EX, LIGHTWHITE_EX, LIGHTYELLOW_EX

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

coloredlogger-1.3.12.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file coloredlogger-1.3.12.tar.gz.

File metadata

File hashes

Hashes for coloredlogger-1.3.12.tar.gz
Algorithm Hash digest
SHA256 449368a0fa5cf36f80e5d27504e99d9d36153bfe611e750a38da7c3cc94eb3e6
MD5 ba67631ce70b2e6f8840a21b8c1508ee
BLAKE2b-256 689837a75cd9fdd8998b31f997ad46737f3d0028c9048ce04e3082ae8e4d1fa5

See more details on using hashes here.

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