Helper for logging to files
Project description
fileloghelper
A simple helper for logging content to files (and displaying it)
Installation
pip3 install fileloghelper
Methods
set_context(context)
Specifies context which will be added to all outputs (file & terminal) in front
parameter | description |
---|---|
context: str | string to be added to output of other functions |
set_verbose(verbose)
Sets verbose mode for whole logger. If true, a info whether the text is success/debug/warning/error information will be added to the file
parameter | description |
---|---|
verbose: bool | value to set for verbose mode |
save()
Saves the file under default/at declaration specified filename
clear()
Clear the log. Note: You have to save again to make changes to the actual file
success(text, display=True)
Writes log to file. If verbose mode active, '[SUCCESS]' will be written in addition.
parameter | description |
---|---|
display: bool | print text on console |
debug(text, display=True)
Writes log to file. If verbose mode active, '[DEBUG]' will be written in addition.
parameter | description |
---|---|
display: bool | print text on console |
warning(text, display=True, extra_context="")
Writes log to file. If verbose mode active, [{extra_context}] will be written in addition. extra_context can be used to give extra information about the warning.
parameter | description |
---|---|
display: bool | print text on console |
error(text, display=True, extra_context="")
Writes log to file. If verbose mode active, [{extra_context}] will be written in addition. extra_context can be used to give extra information about the error.
parameter | description |
---|---|
display: bool | print text on console |
plain(text, display=False, extra_long=False, very_plain=False)
Writes log without any colors to file. If display==True, the text will be displayed. If extra_long==True, milliseconds will be added to the timestamp. If very_plain==True, the timestamp will be omitted.
show_warning(warning: Warning, display=True)
Extracts class from warning and uses it to invoke warning() with extra_context
show_error(error: Exception, display=True)
Extracts class from error and uses it to invoke error() with extra_context
handle_exception(exception: Exception)
Automatically categorizes exception to invoke show_warning() or show_error()
header(sys_stat=False, date=False, description="", display=0)
Use plain() to output certain information:
parameter | description |
---|---|
sys_stat | write system information to the log |
date | write date information to the log |
description | write the specified description to the log |
display | also display certain information in the console (see table below) |
Modes for display:
mode number | information printed |
---|---|
0 (standard) | none |
1 | description only |
2 | date only |
3 | system information only |
4 | description & date |
5 | description & system information |
6 | date & system information |
7 | all above |
progress(x=0, description='', startx=0, maxx=100, mode='=', scale=10)
Easily create a progress bar. Startx is the minimal x value, maxx the maximum possible. 'mode' specifies the style ('=' / '#'). 'scale' indicates the length of the progress bar in characters. To update the progress bar, simply run the same method again and specify x to visualize the progress.
from fileloghelper import Logger
logger = Logger(filename='log.txt', context='MyContext')
logger.progress(description="Running 'Self-Destruction'")
Running 'Self-Destruction': 0.0% [> ]
logger.progress(80)
Running 'Self-Destruction': 80.0% [=======> ]
Example
from fileloghelper import Logger
logger = Logger(filename='log.txt', context='MyLogger')
logger.header(sys_stat=True, date=True, description='A short description', display=7)
logger.debug('Hello World!', display=False)
logger.success('Successfull!', display=True)
logger.handle_exception(NotImplementedError("off to work!"))
logger.save()
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
Built Distribution
Hashes for fileloghelper-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11c9c4c015407105584deb672819dd5d5e805ee86c406930a91507b732ec7aa7 |
|
MD5 | 3382d03ab4c520a6607e7e0900358d79 |
|
BLAKE2b-256 | 97ca4546615cbaa7bb34f350062a619c8fc945165a42b5dea4d71deb58bfeea4 |