Colored Logger for Python
Project description
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:
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:
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
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')
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file coloredlogger-1.3.12.tar.gz
.
File metadata
- Download URL: coloredlogger-1.3.12.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 449368a0fa5cf36f80e5d27504e99d9d36153bfe611e750a38da7c3cc94eb3e6 |
|
MD5 | ba67631ce70b2e6f8840a21b8c1508ee |
|
BLAKE2b-256 | 689837a75cd9fdd8998b31f997ad46737f3d0028c9048ce04e3082ae8e4d1fa5 |