Package: cilog
CiLogCiLog is a flexible integrated logging tool with color and custom bold font base on package logging.FeatureColored console outputsSetting stack info output levelEasier way to custom format for each levelSubstitute builtins.print: a new print grammar to use log!Command line script to substitutenohup cmd &with a "task
completed reminder" feature.Install$pipinstallcilogNew Features1.2.0Add SUPPORT for excel table filling.
Usage:fromcilogimportfill_tabletable_format=[['A','B','C','D','E','F','G'],['da','db','dc','de'],['sa','sb','sc','sd','sf']]fill_table('./excel_test.xlsx',value='0.4013',x='C',y='db',z='sd',table_format=table_format)1.1.5Add SUPPORT for error logging(such asraise ***), all the error message will go though the
logger.error process. Note that you have to use set flagsub_print=Trueincreate_logger()to use this function.Fix bug with package tqdm1.1.4Tabular print SUPPORT:print(f'#T#!latex{table_list}')for latex format table string
orprint(f'#T#{table_list}')for markdown format table string.1.1.3Bug fixed1.1.2Automatically install dependencies when first running.1.1.1bug fixed1.1.0Add origin level. When we use sub_print=True,print(f'string')will act like normal builtin print
function. Other levels likeinfo,debugandmail, etc, should be specified by special notation
like#IN#,#D#and#M#, etc.Support Table print in markdown format or latex format for data scientists.1.0.2Bug fixed1.0.1Bug fixed1.0.0Develop print function substitute function. Now you can directly
send parametersub_print=Truetocreate_loggerfor substituting print.A command line TOOL: cilog is available NOW! You don't have
to usenohup cmd &any more! It will even send a EMAIL to you when your task
completed! Please refer to the main document for how to use it.0.3.0Substitute builtins.print using logger.substitute_print()A brand NEW way to use logger! You can just use print()!By using print, you need to know the easier logger grammar.
Please refer to the main document.0.2.1Bug fixed: Now the logger can automatically create the directory for log file.0.2.0Eliminate ipt_info, instead you can use logger.important() to log important info.adding feature of sending email. By Default, after setting enable_mail and mail_setting, all message log by
logger.mail() will be sent to the specific email address according to mail_setting.0.1.1After log file's line_length is greater than 1e+4, it will automatically backup the log file with localtime then new
a log file.0.1.0new parameter ipt_infoBasic Usagefromcilogimportcreate_loggerdefcall_error():logger.error('Exception')'''mail_setting = {mailhost:   string or tuple - YourMailHost or (host, port),fromaddr:   string          - YourSenderAddress,toaddrs:    list(string)    - List of YourTargetAddresses,subject:    string          - Mail Subject,credentials:tuple           - (YourUsername, YourPassword),secure:     tuple           - () or (KeyfileName) or (KeyfileName, CertificatefileName)use the secure protocol (TLS),timeout:    float           - Default 1.0}'''# New Featuremail_setting={'mailhost':('*****',int(**)),'fromaddr':'****@*****','toaddrs':['****@****','***@***'],'subject':'CiLog test','credentials':('***@**','****')}logger=create_logger(name='l1',file='./log.log',use_color=True,enable_mail=True,mail_setting=mail_setting)logger.info('start')logger.debug('here')logger.warning('warn')call_error()logger.critical('Program exit.')logger.important('lal')logger.mail('test')# you will receive an email after using this function."*" means new featurescreate_loggerkeywords:name : str - logger namefile : str - File pathfile_mode : str - File open mode. Default: 'a'file_level : Literal['DEBUG', 'INFO', 'WARNING', 'IMPORTANT', 'ERROR', 'CRITICAL', 'MAIL'] - Default 'INFO'enable_mail : bool - Default Falsemail_level : Literal['DEBUG', 'INFO', 'WARNING', 'IMPORTANT', 'ERROR', 'CRITICAL', 'MAIL'] - Default 'MAIL'mail_setting : dir - Required if enable_mail == True{
        mailhost:   string or tuple - YourMailHost or (host, port),
        fromaddr:   string          - YourSenderAddress,
        toaddrs:    list(string)    - List of YourTargetAddresses,
        subject:    string          - Mail Subject,
        credentials:tuple           - (YourUsername, YourPassword),
        secure:     tuple           - () or (KeyfileName) or (KeyfileName, CertificatefileName)
                                        use the secure protocol (TLS),
        timeout:    float           - Default 1.0
    }use_color : bool - Signal for using colored info. Default Truestack_level : Literal['DEBUG', 'INFO', 'WARNING', 'IMPORTANT', 'ERROR', 'CRITICAL', 'MAIL'] - Default 'ERROR'msg_fmt : Dict{'DEBUG': debug_fmt, 'INFO': info_fmt, 'WARNING': warning_fmt, 'IMPORTANT': important_fmt,
'ERROR': error_fmt, 'CRITICAL': critical_fmt, 'MAIL': mail_fmt} - Custom design massage format.(Specially, you can use $BOLDtext$RESET to use bold font)
Please refer to CustomFormatter and url:https://docs.python.org/3/library/logging.html#logrecord-attributesreturn: logger : CustomLoggerAdvance UsageSubstitute builtins.printThe only step you shoud do is:fromcilogimportcreate_loggercreate_logger(sub_print=True)# Then: you can even execute the following scripts# in other files if only you have run these two lines# in the same system process# Let us just try!print('i=1')# info: i=1print('i','=','1')# info: i = 1print('#D#Here!')# Debug: Here! [#d#, #DEbu#, #dEBug#, ... are all valid!]print('#W#warning')# Warning ...# Similarly, #e# #ER# ...: error, #I# #IM# ...: important,# #C# #CRE# ...: critical, #M# #MA# #Mail# ...: mail.Grammar: The way to uselogger.infois just useprint, and the way
to use other level is totype the first several characters of the level
name between simbol#.You can use print everywhere which actually use the logger
you created to output! Meanwhile, you can use anyprintfeatures,
likeend=*orsep=* ...but do not usefile=*, because the logger
only monitor the standard output.Elaborate Example:fromcilogimportcreate_loggerdefcall_error():print('#E#Exception')'''mail_setting = {mailhost:   string or tuple - YourMailHost or (host, port),fromaddr:   string          - YourSenderAddress,toaddrs:    list(string)    - List of YourTargetAddresses,subject:    string          - Mail Subject,credentials:tuple           - (YourUsername, YourPassword),secure:     tuple           - () or (KeyfileName) or (KeyfileName, CertificatefileName)use the secure protocol (TLS),timeout:    float           - Default 1.0}'''mail_setting={'mailhost':('*****',int(**)),'fromaddr':'****@*****','toaddrs':['****@****','***@***'],'subject':'CiLog test','credentials':('***@**','****')}create_logger(name='l1',file='./log.log',enable_mail=True,mail_setting=mail_setting,sub_print=True)# The simplest usage `create_logger(sub_print=True)`print('origin')table_list=[['Tox21','Clintox'],[1,2],[3,4]]print(f'#t#{table_list}')# print table in markdown format# |   Tox21 |   Clintox |# |--------:|----------:|# |       1 |         2 |# |       3 |         4 |print(f'#t#!latex{table_list}')# latex format table# \begin{tabular}{rr}# \toprule#  Tox21 &  Clintox \\# \midrule#      1 &        2 \\#      3 &        4 \\# \bottomrule# \end{tabular}print('#IN#start')print('#D#here')print('#W#warn')call_error()print('#C#Program exit.')print('#IM#lal')# print('#M#test')Command line usageFirst stepRun$ cilog [any cmd]to create default config file at$HOME$/.cilog/config.jsonthen modify it with your custom
setting.Run a cmdFor example:$cilogpythonmy_algorithm.py--lr0.01--epoch100it is equal to:$nohuppythonmy_algorithm.py--lr0.01--epoch100>cilog.log2>&1&-eusage:$cilog-epythonmy_algorithm.py--lr0.01--epoch100There is no different to the previous example but will send you
A EMAIL when the task finished [Using your default setting].
It is especially useful when your program is time comsuming.-c [config_file]: use your own config file instead of the default one.-r [redirect_file]: redirect the output to a file instead ofcilog.log.Ps: Do not use the same cmdline parameters-c -e -rin your program,
or it will cause an error.Help:cilog --helpLICENSESeeMIT LICENSE