Skip to main content
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

Metadata

Release files for coloredlogger 1.3.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coloredlogger 1.3.12
File Size Uploaded
coloredlogger-1.3.12.tar.gz 4.6 kB Details

Release files / coloredlogger-1.3.12.tar.gz

Download URL coloredlogger-1.3.12.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
449368a0fa5cf36f80e5d27504e99d9d36153bfe611e750a38da7c3cc94eb3e6
BLAKE2b-256 checksum
How to use checksums
689837a75cd9fdd8998b31f997ad46737f3d0028c9048ce04e3082ae8e4d1fa5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.3.12 This release

1 release file

1.3.5

1 release file

1.3.4

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page