Generic logger
Project description
Module LogP
Set up a logging-environment for daemons or console-programs Usage:
import logging
from pcs_log.LogP import LogP
.... you have to import this both in all your modules you like to use this logging. But you only need to SetupLogging once.
.... Later within your program call this function: (You can call it more than once to change to another format)
LogP.SetupLogging( AppName, Verbose, NoDaemon, StdErr, LogPath,
LogFileInterval, LogFileCount, Quiet,
LogProcInfo, LogProcInfoModLen,
LogProcInfoFuncLen, LogLevelType,
LogMultiProc, LogMultiProcLen,
LogMultiThread, LogMultiThreadLen,
LogStackOnDebug, LogStackDepth, LogDebugIp,
LogDebugPort, LogDebugCacheSize, NoReset,
LogLongLevel, StdErrIsStdOut,
TimeOnSyslog, translation)
All arguments are named arguments - NO positional arguments!
Args:
AppName (str): Name of application
Verbose (int, optional): Detail of logging. Defaults to 0.
0 = ERROR and STATUS
1 = MSG, WARNING, STATUS, ERROR
2 = INFO, MSG, WARNING, STATUS, ERROR
3 = DEBUG, INFO, MSG, WARNING, STATUS, ERROR
4 = TRACE, DEBUG, INFO, MSG, WARNING, STATUS, ERROR
NoDaemon (bool, optional): Is this an terminal-task. Defaults to True.
If this is false => i am a daemon.
On deamons output to StdErr do not make sense, so this is ignored
and "syslog" or "logfile" is used.
StdErr (bool, optional): Log to StdErr. Defaults to False.
If this is set the log goes to StdErr.
Ignored if we are a daemon.
StdErrIsStdOut (bool, optional): Redirect StdErr-Logging to StdOut. Defaults to False.
TimeOnSyslog (bool, optional): Show timestamp if logging to StdErr. Defaults to True.
LogPath (str, optional): Log to a Log-file. Defaults to ''.
Log to the file which is given as the argument.
this file is rotated on a daily base and holded up to 14 files
LogFileInterval (int, optional): Number of seconds a logfile lasts until it is rotated.
Defaults to 60*60*24 => one day.
LogFileCount (int, optional): Number of log-file kept. Defaults to 14.
Quiet (bool, optional): Output only errors. Defaults to False.
LogProcInfo (bool, optional): Show process and thread. Defaults to False.
LogLevelType (int, optional): Format of LevelInfo. 0=None, 1=Number, 2=Name, 3=Both.
Defaults to 2.
LogMultiProc (bool, optional): Show process-names. Defaults to False.
LogMultiThread (bool, optional): Show thread-names. Defaults to False.
LogProcInfoModLen (int, optional): Length of the 'module' part of the log. Defaults to 15.
Set to 0 for not alligning this part. Optimally this is
the length of the longest modulename in your program.
This is only used to allign the log-lines to make the
rading easier. This names are NEVER truncated.
LogProcInfoFuncLen (int, optional): Length of the 'function' part of the log. Defaults to 15.
Set to 0 for not alligning this part. Optimally this is
the length of the longest functionname in your program.
This is only used to allign the log-lines to make the
rading easier. This names are NEVER truncated.
LogMultiProcLen (int, optional): Length of the 'procedure' part of the log. Defaults to 15.
Set to 0 for not alligning this part. Optimally this is
the length of the longest procedurename in your program.
This is only used to allign the log-lines to make the
rading easier. This names are NEVER truncated.
LogMultiThreadLen (int, optional): Length of the 'thread' part of the log. Defaults to 15.
Set to 0 for not alligning this part. Optimally this is
the length of the longest threadname in your program.
This is only used to allign the log-lines to make the
rading easier. This names are NEVER truncated.
LogStackOnDebug (str, optional): Log-level below or equal a call-stack trace is included.
Defaults to "NONE" => Disabled.
The levels are:
"ERROR"
"STATUS"
"WARNING"
"MSG"
"INFO"
"DEBUG"
"TRACE"
"NONE"
All other values are interpretet as "NONE".
Value is not case-sensitive.
LogLongLevel (str, optional): Log-level below or equal a long info is included.
Above this level except the ERROR-level the fields
processname, threadname,module, line-no and levelinfo
are not within the output.
Alternative this can be a comma-separated list of levelnames
in this case for this log-levels long infos are provided.
Within this list "NONE" is ignored.
Defaults to "DEBUG".
The levels are:
"ERROR"
"STATUS"
"WARNING"
"MSG"
"INFO"
"DEBUG"
"TRACE"
"NONE"
All other values are interpretet as "NONE".
Value is not case-sensitive.
LogStackDepth (int, optional): Maximum number of call-stack entries to display.
Defaults to 5.
LogDebugPort (int, optional): If 0 no debug-server is started. Else the value has to be
between 1024 and 65535. A log-server is started on 'LogDebugIp'
at port 'LogDebugPort'.
It is possible to connect to this port (e.g with telnet) to
receive ALL log-messages from this program. ALL means really
all, no mather which loglevel is set. This output also
includes all possible information about process, thread,
module and function. The stacktrace ('LogStackOnDebug') is also
honored. This output can be really heavy, but can help to debug
already running programs without the need to restart with
another loglevel.
This server runs as a separated process and you have to
terminate it by calling the'Stop' and afterward 'Join' or
'Kill'-function of the returned 'PortLogServer'-object,
otherwise this process may block the termination of your
program. This server will restart himselve if it is terminated
by any means except you call the above mentioned functions.
This port has to be free. Defaults to 0.
LogDebugIp (str, optional): The IP-address to bind to. This address must exist on the host
this program is running. '0.0.0.0' for 'all IPs' is also
valid. Only examined if 'LogDebugPort' > 0.
Defaults to '127.0.0.1',
LogDebugCacheSize (int, optional): Only used if 'LogDebugPort' > 0. This is the number of
log-messages cached for use at a new connection to the
server. So if someone connects to the server he receives the
last 'LogDebugCacheSize' log messages and after them all new
messages.
This is like a history. if set to 0 this function is disabled.
Defaults to 100.
NoReset (bool, optional): Do not reset logger on init. Defaults to False.
Use with care. Could tend to mess up the logging.
transation (dict, optional): If given the programmer can overwrite the error-messages used.
There are 2 functions to help creating this dict:
LogP._PrintInitTranslation()
LogP._PrintActualTranslation()
they do exactly what their name says: they print either the
default value for the translationtable or the actual value after
overwriting some or all values with this dict.
default = {}
After calling this function the new logging is set up. Use the standard functions logger.error, logger.warning, etc and additional you can use logger.msg, logger.status and logger.trace. The severity is in descending order: ERROR, STATUS, WARNING, MSG, INFO, DEBUG, TRACE
At the end of your program call:
LogP.Stop()
this will stop the optional logger-process which send the output to a telnet-connection if LogDebugPort is not 0.
Output format:
General overview:
2022-06-22 07:37:42,494 Appname:MainProcess:MainThread LogP:main:461 - 40= ERROR - Message
^ ^ ^ ^ ^ ^ ^
| | | | | | |
Name of application ----+ | | | | | |
only if not StdErr | | | | | |
Name of process ----------------+ | | | | |
if LogMultiProc = true | | | | |
Name of thread if --------------------------+ | | | |
LogMultiThread = true | | | |
Module, function and linenumber -----------------------+ | | |
only if LogProcInfo = true | | |
Level-number of message if LogLevelType = 1 or 3 ----------------------+ | |
Level-name of message if LogLevelType = 2 or 3 ------------------------------+ |
The message given to the log-call ---------------------------------------------------+
The minimal log entry for StdErr is:
2022-06-22 07:37:42,494 Errormessage
The maximal log entry is shown above.
The output format to StdErr is like this:
2022-06-22 07:37:42,494 MainProcess:MainThread LogP:main:461 - 40= ERROR - Message
No "Appname" because you know whitch program is running.
The timestamp is only written if 'TimeOnSyslog' is True.
REMEMBER: this is send to StdErr or to StdOut if 'StdErrIsStdOut' is True.
The output format to sylog like this:
Appname:MainProcess:MainThread LogP:main:461 - 40= ERROR - Errormessage
No timestamp because syslogg adds his own timestamp.
The output format to a logfile is like this:
2022-06-22 07:37:42,494 Appname:MainProcess:MainThread LogP:main:461 - 40= ERROR - Message
if a call-stack trace is requested lines like these are appended:
File "./LogP.py", line 471, in <module>
main()
File "./LogP.py", line 448, in main
abc()
File "./LogP.py", line 411, in abc
LogP.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
Built Distribution
File details
Details for the file pcs_log-1.6.74.220820104710.tar.gz
.
File metadata
- Download URL: pcs_log-1.6.74.220820104710.tar.gz
- Upload date:
- Size: 54.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | baf2d236fe0338a01db2e9884e200348de5bb9521d87003647c52b8ade2b25ea |
|
MD5 | 55052803179ed1f93399726206045b98 |
|
BLAKE2b-256 | 002ccde687d36d0914c87ad6c2dbc59c28a386a8596c13ebff9356153e6475fb |
File details
Details for the file pcs_log-1.6.74.220820104710-py3-none-any.whl
.
File metadata
- Download URL: pcs_log-1.6.74.220820104710-py3-none-any.whl
- Upload date:
- Size: 82.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29879ed308cfd7b3c553753f3beb024acb628e320d9972270ac0c08ca91129a5 |
|
MD5 | 56479b5a0fc901724d496bfe0c9890b3 |
|
BLAKE2b-256 | 45d04917fd2a41ebc34a570c32be529e143c73cb6f38d1ea5ebb069741edddb6 |