Package: pyDecLog
pyDecLogpyDecLog: a simple and easy to use Python module for logging via decorators.🚀Quick startSay we have the following workflowfrompyDecLogimportargumentsasargfrompyDecLogimportsignatureassignfrompyDecLogimportmessageasmesfrompyDecLogimporttimingastimfrompyDecLogimportlprintfrompyDecLogimportdescriptionasdocfrompyDecLogimportmemoryasmemimporttimeimportsysdefworkflow():# Set console level to the same level of the message level so it is shown in the consolelprint(console_log_level="info").info("Workflow starts!")# Decorate function as needed@doc@sign@arg@tim@mesdefsum_two_int(first,second=2):"""Sum two numbers."""print("Some message on console")result=first+secondtime.sleep(2)print("Result is: "+str(result))returnresultsum_tow_int(1,1)# Set console level to the same level of the message so it is shown in the consolelprint(console_log_level="info").info("Workflow ends!")if__name__=="__main__":workflow()Upon execution the following is printed on console:Workflowstarts!
Workflowends!Upon execution aLOG.logfile is written:2023/06/24|18:20:50|ERRORWorkflowstarts!2023/06/24|18:20:50|DEBUGMethod's description: Sum two numbers.2023/06/24 | 18:20:50 | DEBUG Method'sname:sum_2023/06/24|18:20:50|DEBUGMethod's signature:(first, second=2)2023/06/24 | 18:20:50 | DEBUG Method'sname:sum_2023/06/24|18:20:50|DEBUGMethod's args: (1, 1)2023/06/24 | 18:20:50 | DEBUG Method'skwargs:{}2023/06/24|18:20:52|INFOSomemessageonconsole2023/06/24|18:20:52|INFOResultis:22023/06/24|18:20:52|DEBUGsum_wasexecutedin:2.006sec2023/06/24|18:20:52|ERRORWorkflowends!🚀Useful forKeep track of Python pipelines.Log info about a function during development both on python script or jupyter notebook.⚙️InstallationCreate your own virtual environment and runpip install -r requirements.txtVia pip:pip install pyDecLog🔗DependenciesPyDevLog requires Python 3.5 or higher, and the following packages:pymplernumpy🧑‍🤝‍🧑ContributionsAll contributions (bug, suggestion, new feature) are welcome.🎨Available decorators@arguments: log function's args and kwargs@comment: log all function's inner print statements@description: log function's output from the__doc__dunder method@machine: log machine OS system and hardware@memory: log function's args, kwargs and output memory usage@message: log function's print statements@profile_locals: log function's local persistent variables@signature: log function's signature@timing: log function's elapsed time@typing: log function's args, kwargs and output type@user: log user info🪄FeaturesMix and match the decorators you want.Can control logging levels as a whole or individually. Choose from the following:CRITICALERRORWARNINGINFODEBUGCan control where logging messages are piped: to log file or both log file and console. When controlling the message at the console level the following hierarchy is enforced:CRITICAL : 50
ERROR    : 40
WARNING  : 30
INFO     : 20
DEBUG    : 10
NOTSET   : 0Can add comments directly to log file even outside a function.⚠️Known issues@profile_localsdoes not write to the log file. Its output needs to be piped separately to the LOG.log file. See the following example:frompyDecLogimportprofile_localsasprofilefrompyDecLogimportlprintfrompympler.asizeofimportasizeof@profiledeffunc(x):local_1=1local_2=2return1func()forkey,valueinfunc.locals.items():msg=f"Variable:{key}| value:{value}| type:{type(value)}| size:{asizeof(value)}"lprint(console_log_level="debug").debug(msg)The followingLOG.logis the written:2023/06/28|07:04:52|DEBUGVariable:x|value:1|type:<class'int'>|size:322023/06/28|07:04:52|DEBUGVariable:local_1|value:1|type:<class'int'>|size:322023/06/28|07:04:52|DEBUGVariable:local_2|value:2|type:<class'int'>|size:32📚TutorialsSee theexamplesfolder.📚ReferencesDecorators with parameters?How to expose persistent local variables? Part#1How to expose persistent local variables? Part#2How to time your code📝Changelog0.1.6- First release (26/06/23).0.1.7- Added@machineand@user(29/06/23).📝To-doThere is no planned development.🪪LicenseMIT LicenseDevelopersDoc string were generated viaautoDocstringpackage using NumPy fomrat.Typing hints for function return type byPylance.Testing was done via unittesting.