A simple logging library for Python 3
Project description
justlog
A simple library for logging with Python3
Basics
For a quick example, refer to the test.py on the github repository
With justlog, everything is handled within a single class: Logger
Spawn an instance of this class to start logging quickly.
from justlog import justlog, settings
logger = justlog.Logger(settings.Settings())
Instances must be initialized with a Settings instance that can be customized before or after instantiation.
Syntax
Logger
log(message)- message: The message to log
- Will use the current log level set within the
Settingsclass:logger.settings.current_log_level
debug(message)- message: The message to log
- Sets the
current_log_leveltoSeverity.DBGand calls thelog()function
info(message)- message: The message to log
- Sets the
current_log_leveltoSeverity.INFand calls thelog()function
warning(message)- message: The message to log
- Sets the
current_log_leveltoSeverity.WRNand calls thelog()function
error(message)- message: The message to log
- Sets the
current_log_leveltoSeverity.ERRand calls thelog()function
Settings
appname: str- Used as a default for various other settings like the log path
current_log_level: Severity- Sets the current log level. Influences colors and fields.
- Log levels:
DBGINFWRNERR
colorized_logs: Bool- Enables or disables the log coloration for different
Severity
- Enables or disables the log coloration for different
log_format: Format- Sets the log format type
TEXTJSON
log_output: [Output]- Defines where the logs are output. Must be a list, can include many.
STDOUTSTDERRTCPFILESYSLOGHTTP
string_format: str- Defines the template and fields for logs output in the
TEXTformat
- Defines the template and fields for logs output in the
timestamp_format- Sets the
$TIMESTAMPvariable format using stfrtime codes
- Sets the
update_field(key: str, value: str)- Adds or updates a field that will be output to the logs. Fields can be reffered using the
$symbol within thestring_format
- Adds or updates a field that will be output to the logs. Fields can be reffered using the
delete_field(key: str)- Removes a field
tcp_output_host(host: str)- Sets the tcp output host
tcp_output_port(port: int)- Sets the tcp output port
http_url(url: str)- Sets the http output url
http_headers(header: dict)- Optional headers to pass to the post request
http_print_response(bool)- Prints the http call response to stdout when True
Builtin Variables
$TIMESTAMP- Will print the current time in the format defined by the
timestamp_formatsetting using stfrtime codes
- Will print the current time in the format defined by the
$CURRENT_LOG_LEVEL- Will print the current log level based on the
current_log_levelsetting at the moment of the call.
- Will print the current log level based on the
$message- Will print the message.
Quickstart
from justlog import justlog, settings
from justlog.classes import Severity, Output, Format
logger_stdout = justlog.Logger(settings.Settings())
logger_stdout.settings.colorized_logs = True
logger_stdout.settings.log_output = [Output.STDOUT]
logger_stdout.settings.update_field("application", "sample")
logger_stdout.settings.update_field("timestamp", "$TIMESTAMP")
logger_stdout.settings.update_field("level", "$CURRENT_LOG_LEVEL")
logger_stdout.settings.string_format = "[ $timestamp ] :: Level: $CURRENT_LOG_LEVEL, application: $application :: $message"
logger_stdout.info("Information")
logger_stdout.error("Error")
logger_stdout.warning("Warning")
logger_stdout.debug("Debug")
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
justlog-0.1.1.5.tar.gz
(5.2 kB
view details)
File details
Details for the file justlog-0.1.1.5.tar.gz.
File metadata
- Download URL: justlog-0.1.1.5.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
023c55a0807045afad55ad408162250da1c57e876b06441b08737b798a01cf84
|
|
| MD5 |
8b55175497e1390f4abfc1535a37cccd
|
|
| BLAKE2b-256 |
01891ecee36fae5da1660d9460c3df86c156298c8d38491060f20cee4e7b0add
|