Package: pcs-log
pcs_log1.6.137.221205144037UsageLogP reference**pcs_log»pcs_log 1.6.137 documentationWelcome to pcs_log’s documentation!Document version: 1.6.137.221205144037NoteThis project is under active development.SourceYou can get the complete source-code fromGitHub
repositoryDetailed documentationThe detailed documentation is onRead the
DocsTable of contentsUsageInstallationTo use pcs_log, first install it using pip:(.venv) $ pip install pcs_logUse in your programThis module handles the most often used logging options:log to consolelog to sysloglog to file with autorotationadditional a standalone logging server accessible via telnetmultiprocessing logsmutithreading logsenhanced formatting optionsnormally imported asimport logging
from pcs_alog.Logp import LogPLogP referenceNoteNormally you import only “LogP” from this module.import logging
from pcs_log.LogP import LogPThis is a “singleton” and used for all your code-modules. You should
insert this two lines in every module using logging, but callSetupLogging()only once. (except you make your program or parts of it
to “daemons”, in this case you MUST call this functionAFTERdaemonizing within the daemonized codeblock again, because all the
file-handles are deleted on daemonizing)classLogP._LogPpropertyGetLogging:tupleReturn logging functionsReturnsThe logging functions in order logging.error,
logging.status, logging.warning, logging.msg, logging.info,
logging.debug, logging.traceReturn typetuplePollRestart()→NonePrüfe ob der Logserver neu gestartet werden mussSetupLogging(*,AppName:str,Verbose:int=0,NoDaemon:bool=True,StdErr:bool=False,StdErrIsStdOut:bool=False,LogPath:str='',LogFileInterval:int=86400,LogFileCount:int=14,Quiet:bool=False,LogProcInfo:bool=False,LogProcInfoModLen:int=15,LogProcInfoFuncLen:int=15,LogLevelType:int=2,LogMultiProc:bool=False,LogMultiProcLen:int=15,LogMultiThread:bool=False,LogMultiThreadLen:int=15,LogStackOnDebug:str='NONE',LogLongLevel:str='DEBUG',LogStackDepth:int=5,LogDebugIp:str='127.0.0.1',LogDebugPort:int=0,LogDebugCacheSize:int=100,NoReset:bool=False,TimeOnSyslog:bool=True,translation:Optional[dict]=None,**kwargs)→NoneCreates a defined Log-setting with rich options.NoteAll arguments are named arguments - NO positional arguments!param AppNameName of applicationtype AppNamestrparam VerboseDetail of logging. Defaults to 0. Possible values: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, ERRORtype Verboseint, optionalparam NoDaemonIs this an terminal-task. Defaults to True. If this is
False => I am a daemon.On deamons output to StdErr do not make any sense, so this
is ignored and “syslog” or “logfile” is used.type NoDaemonbool, optionalparam StdErrLog to StdErr. Defaults to False. If this is set the log
goes to StdErr. Ignored if we are a daemon.type StdErrbool, optionalparam StdErrIsStdOutRedirect StdErr-Logging to StdOut. Defaults to False.type StdErrIsStdOutbool, optionalparam TimeOnSyslogShow timestamp if logging to StdErr. Defaults to True.type TimeOnSyslogbool, optionalparam LogPathLog 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 filestype LogPathstr, optionalparam LogFileIntervalNumber of seconds a logfile lasts until it is rotated.
Defaults to 60*60*24 => one day.type LogFileIntervalint, optionalparam LogFileCountNumber of log-file kept. Defaults to 14.type LogFileCountint, optionalparam QuietOutput only errors. Defaults to False.type Quietbool, optionalparam LogProcInfoShow process and thread. Defaults to False.type LogProcInfobool, optionalparam LogLevelTypeFormat of LevelInfo. Defaults to 2.0=None,
1=Number,
2=Name,
3=Both.type LogLevelTypeint, optionalparam LogMultiProcShow process-names. Defaults to False.type LogMultiProcbool, optionalparam LogMultiThreadShow thread-names. Defaults to False.type LogMultiThreadbool, optionalparam LogProcInfoModLenLength 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.type LogProcInfoModLenint, optionalparam LogProcInfoFuncLenLength 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.type LogProcInfoFuncLenint, optionalparam LogMultiProcLenLength 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.type LogMultiProcLenint, optionalparam LogMultiThreadLenLength 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.type LogMultiThreadLenint, optionalparam LogStackOnDebugLog-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.type LogStackOnDebugstr, optionalparam LogLongLevelLog-level below or equal a long info is included.Above this level except the ERROR-level the fieldsprocessname,
threadname,
module,
line-no and
levelinfoare 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.type LogLongLevelstr, optionalparam LogStackDepthMaximum number of call-stack entries to display. Defaults
to 5.type LogStackDepthint, optionalparam LogDebugPortIf 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 theStop()function of
the LogP-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.NoteThis port has to be free.Defaults to 0.type LogDebugPortint, optionalparam LogDebugIpThe 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’,type LogDebugIpstr, optionalparam LogDebugCacheSizeOnly 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.type LogDebugCacheSizeint, optionalparam NoResetDo not reset logger on init. Defaults to False.NoteUse with care. Could tend to mess up the logging.type NoResetbool, optionalparam translationIf 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 = {}type translationdict, optionalAfter calling this function the new logging is set up. Use
the standard functionslogger.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, TRACEAt 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')Stop()Stop the Log-Server© Copyright 2022, Ing. Rainer Pietsch.Built withSphinxusing athemeprovided byRead the Docs.