Simple logging
Project description
CCA Logging
Easy python logging module
Installing
# install into users system site-packages
pip install ccalogging --user
# install into a virtual environment
pip install ccalogging
# as part of your own package, add to setup.py
setup(
...,
install_requires=[
'...',
'ccalogging',
'...',
],
...,
)
Usage
Import this module, set logging output, optionally set logging level,
set a script level variable pointing to this modules log
variable,
then issue log.debug() etc.
You only need to set the output destination and logging level once, so
if you have multiple files in your project, set the output destination
and the logging level in the first one. In all the others just point a
script level variable to ccalogging.log
.
When using a log file, if the file already exists, new log messages are appended to it.
The default logging level is WARNING.
# first (or only) project file
import ccalogging # import the module
ccalogging.setConsoleOut() # set global logging destination
ccalogging.setDebug() # set global log level
log = ccalogging.log # point a script-level variable to the logger
log.info("Logging has been started")
# subsequent project files
import ccalogging # import the module
log = ccalogging.log # point a script-level variable to the logger
log.warning("continuing to log to the same location as setup in the first file")
Options
It is possible to log to the console and/or to a file. When logging to the
console logs go to stderr
by default.
setDebug()
Sets the global loglevel to be logging.DEBUG
setInfo()
Sets the global loglevel to be logging.INFO
setWarn()
Sets the global loglevel to be logging.WARNING. This is the default level, if you don't set a level.
setError()
Sets the global loglevel to be logging.ERROR
setLogFile(fqfn)
Sends log output to a file
parameters:
fqfn
: the fully qualified path name of the log file
fformat
: message format - defaults to: "%(asctime)s [%(levelname)-5.5s] %(message)s"
datefmt
: date format - defaults to: "%d/%m/%Y %H:%M:%S"
rotation
: default: None - set this to the number of days to keep the log file for
older logs will be compressed and numbered (up to this value)
setConsoleOut()
Sends log output to the console
parameters:
STDOUT
: if True
send to stdout
- defaults to False (stderr
)
cformat
: message format - defaults to: "%(asctime)s [%(levelname)-5.5s] %(message)s"
datefmt
: date format - defaults to: "%d/%m/%Y %H:%M:%S"
toggle()
This toggles between DEBUG and INFO modes
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
Built Distribution
File details
Details for the file ccalogging-0.5.3.tar.gz
.
File metadata
- Download URL: ccalogging-0.5.3.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/6.6.8-2-MANJARO
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeb4f63347cd9c0a8bbcb8e8e24e838361ca4595c0c2c5dd56d07a436efa4996 |
|
MD5 | f46c2d545bbdae0afef0235b407394cb |
|
BLAKE2b-256 | 0c70bf9e4f32c4ec98da0d9f87601316904d57445ad6b93ab7f04fd338a8b361 |
File details
Details for the file ccalogging-0.5.3-py3-none-any.whl
.
File metadata
- Download URL: ccalogging-0.5.3-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/6.6.8-2-MANJARO
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 765a74ea74d7f11af9ae64aeac8b299ee0beddc156945e0fe7e39fbdfee8285d |
|
MD5 | c369bc90b563836fd714ba7335eb1bc0 |
|
BLAKE2b-256 | 4d819b89ab6c5707cd2edac41c1d7a7583b5e0c75fa39e97d9296e4faec259cb |