{"id":17128701,"url":"https://github.com/cm-bf/cilog","last_synced_at":"2025-04-13T07:10:39.328Z","repository":{"id":62562195,"uuid":"283391816","full_name":"CM-BF/CiLog","owner":"CM-BF","description":"CiLog is a flexible integrated logging tool with color and custom bold font base on package logging.","archived":false,"fork":false,"pushed_at":"2023-02-17T00:13:40.000Z","size":105,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-13T07:09:38.324Z","etag":null,"topics":["colored-terminal","logging","replace-print","task-auxiliary"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CM-BF.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-07-29T03:49:09.000Z","updated_at":"2023-09-09T21:14:50.000Z","dependencies_parsed_at":"2022-11-03T15:30:48.012Z","dependency_job_id":"38117cd7-6bd8-4e5c-abdb-1669070d2dd8","html_url":"https://github.com/CM-BF/CiLog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CM-BF%2FCiLog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CM-BF%2FCiLog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CM-BF%2FCiLog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CM-BF%2FCiLog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CM-BF","download_url":"https://codeload.github.com/CM-BF/CiLog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675422,"owners_count":21143768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["colored-terminal","logging","replace-print","task-auxiliary"],"created_at":"2024-10-14T19:07:46.070Z","updated_at":"2025-04-13T07:10:39.263Z","avatar_url":"https://github.com/CM-BF.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CiLog\r\n\r\nCiLog is a flexible integrated logging tool with color and custom bold font base on package logging.\r\n\r\n## Feature\r\n\r\n* Colored console outputs\r\n* Setting stack info output level\r\n* Easier way to custom format for each level\r\n* Substitute builtins.print: a new print grammar to use log!\r\n* Command line script to substitute `nohup cmd \u0026` with a \"task\r\ncompleted reminder\" feature.\r\n\r\n## Install\r\n\r\n```bash\r\n$ pip install cilog\r\n```\r\n\r\n## New Features\r\n\r\n### 1.2.0\r\n* Add SUPPORT for excel table filling.\r\nUsage:\r\n```python\r\nfrom cilog import fill_table\r\n\r\n\r\ntable_format = [['A', 'B', 'C', 'D', 'E', 'F', 'G'],\r\n                ['da', 'db', 'dc', 'de'],\r\n                ['sa', 'sb', 'sc', 'sd', 'sf']]\r\n\r\nfill_table('./excel_test.xlsx', value='0.4013', x='C', y='db', z='sd', table_format=table_format)\r\n```\r\n![fill_table](./figures/fill_table.png)\r\n\r\n### 1.1.5\r\n* Add SUPPORT for error logging(such as `raise ***`), all the error message will go though the\r\nlogger.error process. Note that you have to use set flag `sub_print=True` in `create_logger()`\r\nto use this function.\r\n* Fix bug with package tqdm\r\n\r\n### 1.1.4\r\n* Tabular print SUPPORT: `print(f'#T#!latex{table_list}')` for latex format table string \r\nor `print(f'#T#{table_list}')` for markdown format table string.\r\n\r\n### 1.1.3\r\n* Bug fixed\r\n\r\n### 1.1.2\r\n* Automatically install dependencies when first running.\r\n\r\n### 1.1.1\r\n* bug fixed\r\n\r\n### 1.1.0\r\n* Add origin level. When we use sub_print=True, `print(f'string')` will act like normal builtin print\r\nfunction. Other levels like `info`, `debug` and `mail`, etc, should be specified by special notation\r\nlike `#IN#`, `#D#` and `#M#`, etc.\r\n* Support Table print in markdown format or latex format for data scientists.\r\n\r\n### 1.0.2\r\n* Bug fixed\r\n\r\n### 1.0.1\r\n* Bug fixed\r\n\r\n### 1.0.0\r\n* Develop print function substitute function. Now you can directly\r\nsend parameter `sub_print=True` to `create_logger` for substituting print.\r\n* A command line TOOL: cilog is available NOW! You don't have\r\nto use `nohup cmd \u0026` any more! It will even send a EMAIL to you when your task\r\ncompleted! Please refer to the main document for how to use it.\r\n\r\n\r\n### 0.3.0\r\n* Substitute builtins.print using logger.substitute_print()\r\n* A brand NEW way to use logger! You can just use print()!\r\n* By using print, you need to know the easier logger grammar. \r\nPlease refer to the main document. \r\n\r\n### 0.2.1\r\n\r\n* Bug fixed: Now the logger can automatically create the directory for log file.\r\n\r\n### 0.2.0\r\n\r\n* Eliminate ipt_info, instead you can use logger.important() to log important info.\r\n* adding feature of sending email. By Default, after setting enable_mail and mail_setting, all message log by\r\nlogger.mail() will be sent to the specific email address according to mail_setting.\r\n\r\n### 0.1.1\r\n\r\n* After log file's line_length is greater than 1e+4, it will automatically backup the log file with localtime then new \r\na log file.\r\n\r\n### 0.1.0\r\n\r\n* new parameter ipt_info\r\n\r\n## Basic Usage\r\n\r\n```python\r\nfrom cilog import create_logger\r\n\r\n\r\ndef call_error():\r\n    logger.error('Exception')\r\n\r\n'''\r\nmail_setting = {\r\n            mailhost:   string or tuple - YourMailHost or (host, port),\r\n            fromaddr:   string          - YourSenderAddress,\r\n            toaddrs:    list(string)    - List of YourTargetAddresses,\r\n            subject:    string          - Mail Subject,\r\n            credentials:tuple           - (YourUsername, YourPassword),\r\n            secure:     tuple           - () or (KeyfileName) or (KeyfileName, CertificatefileName)\r\n                                            use the secure protocol (TLS),\r\n            timeout:    float           - Default 1.0\r\n        }\r\n'''\r\n# New Feature\r\nmail_setting = {\r\n    'mailhost': ('*****', int(**)),\r\n    'fromaddr': '****@*****',\r\n    'toaddrs': ['****@****', '***@***'],\r\n    'subject': 'CiLog test',\r\n    'credentials': ('***@**', '****')\r\n}\r\nlogger = create_logger(name='l1', file='./log.log', use_color=True, enable_mail=True,\r\n                       mail_setting=mail_setting)\r\nlogger.info('start')\r\nlogger.debug('here')\r\nlogger.warning('warn')\r\ncall_error()\r\nlogger.critical('Program exit.')\r\nlogger.important('lal')\r\nlogger.mail('test') # you will receive an email after using this function.\r\n```\r\n\r\n\"*\" means new features\r\n\r\n`create_logger` keywords:\r\n\r\nname : str - logger name\r\n\r\nfile : str - File path\r\n\r\nfile_mode : str - File open mode. Default: 'a'\r\n\r\nfile_level : Literal['DEBUG', 'INFO', 'WARNING', 'IMPORTANT', 'ERROR', 'CRITICAL', 'MAIL'] - Default 'INFO'\r\n\r\nenable_mail : bool - Default False\r\n\r\nmail_level : Literal['DEBUG', 'INFO', 'WARNING', 'IMPORTANT', 'ERROR', 'CRITICAL', 'MAIL'] - Default 'MAIL'\r\n\r\nmail_setting : dir - Required if enable_mail == True\r\n```\r\n    {\r\n        mailhost:   string or tuple - YourMailHost or (host, port),\r\n        fromaddr:   string          - YourSenderAddress,\r\n        toaddrs:    list(string)    - List of YourTargetAddresses,\r\n        subject:    string          - Mail Subject,\r\n        credentials:tuple           - (YourUsername, YourPassword),\r\n        secure:     tuple           - () or (KeyfileName) or (KeyfileName, CertificatefileName)\r\n                                        use the secure protocol (TLS),\r\n        timeout:    float           - Default 1.0\r\n    }\r\n```\r\nuse_color : bool - Signal for using colored info. Default True\r\n\r\nstack_level : Literal['DEBUG', 'INFO', 'WARNING', 'IMPORTANT', 'ERROR', 'CRITICAL', 'MAIL'] - Default 'ERROR'\r\n\r\nmsg_fmt : Dict{'DEBUG': debug_fmt, 'INFO': info_fmt, 'WARNING': warning_fmt, 'IMPORTANT': important_fmt,\r\n'ERROR': error_fmt, 'CRITICAL': critical_fmt, 'MAIL': mail_fmt} - Custom design massage format.\r\n\r\n(Specially, you can use $BOLD **text** $RESET to use bold font)\r\nPlease refer to CustomFormatter and url: https://docs.python.org/3/library/logging.html#logrecord-attributes\r\n\r\nreturn: logger : CustomLogger\r\n\r\n## Advance Usage\r\n\r\n### Substitute builtins.print\r\nThe only step you shoud do is:\r\n```python\r\nfrom cilog import create_logger\r\ncreate_logger(sub_print=True)\r\n\r\n# Then: you can even execute the following scripts \r\n# in other files if only you have run these two lines\r\n# in the same system process\r\n\r\n# Let us just try!\r\n\r\n\r\nprint('i=1') # info: i=1\r\nprint('i', '=', '1') # info: i = 1\r\nprint('#D#Here!') # Debug: Here! [#d#, #DEbu#, #dEBug#, ... are all valid!]\r\nprint('#W#warning') # Warning ...\r\n# Similarly, #e# #ER# ...: error, #I# #IM# ...: important,\r\n# #C# #CRE# ...: critical, #M# #MA# #Mail# ...: mail.\r\n```\r\n**Grammar**: The way to use `logger.info` is just use `print`, and the way\r\nto use other level is to **type the first several characters of the level \r\nname between simbol `#`**. \r\n\r\nYou can use print everywhere which actually use the logger\r\nyou created to output! Meanwhile, you can use any `print` features,\r\nlike `end=*` or `sep=* ...` but do not use `file=*`, because the logger\r\nonly monitor the standard output.\r\n\r\n**Elaborate Example:**\r\n\r\n```python\r\nfrom cilog import create_logger\r\n\r\n\r\ndef call_error():\r\n    print('#E#Exception')\r\n\r\n'''\r\nmail_setting = {\r\n            mailhost:   string or tuple - YourMailHost or (host, port),\r\n            fromaddr:   string          - YourSenderAddress,\r\n            toaddrs:    list(string)    - List of YourTargetAddresses,\r\n            subject:    string          - Mail Subject,\r\n            credentials:tuple           - (YourUsername, YourPassword),\r\n            secure:     tuple           - () or (KeyfileName) or (KeyfileName, CertificatefileName)\r\n                                            use the secure protocol (TLS),\r\n            timeout:    float           - Default 1.0\r\n        }\r\n'''\r\nmail_setting = {\r\n    'mailhost': ('*****', int(**)),\r\n    'fromaddr': '****@*****',\r\n    'toaddrs': ['****@****', '***@***'],\r\n    'subject': 'CiLog test',\r\n    'credentials': ('***@**', '****')\r\n}\r\ncreate_logger(name='l1', file='./log.log', enable_mail=True,\r\n                       mail_setting=mail_setting, sub_print=True)\r\n# The simplest usage `create_logger(sub_print=True)`\r\nprint('origin')\r\ntable_list = [['Tox21', 'Clintox'], [1, 2], [3, 4]]\r\nprint(f'#t#{table_list}')   # print table in markdown format\r\n# |   Tox21 |   Clintox |\r\n# |--------:|----------:|\r\n# |       1 |         2 |\r\n# |       3 |         4 |\r\n\r\nprint(f'#t#!latex{table_list}') # latex format table\r\n# \\begin{tabular}{rr}\r\n# \\toprule\r\n#  Tox21 \u0026  Clintox \\\\\r\n# \\midrule\r\n#      1 \u0026        2 \\\\\r\n#      3 \u0026        4 \\\\\r\n# \\bottomrule\r\n# \\end{tabular}\r\n\r\nprint('#IN#start')\r\nprint('#D#here')\r\nprint('#W#warn')\r\ncall_error()\r\nprint('#C#Program exit.')\r\nprint('#IM#lal')\r\n# print('#M#test')\r\n```\r\n\r\n### Command line usage\r\n\r\n#### First step\r\nRun `$ cilog [any cmd]` to create default config file at\r\n`$HOME$/.cilog/config.json` then modify it with your custom\r\nsetting.\r\n\r\n#### Run a cmd\r\nFor example:\r\n\r\n```bash\r\n$ cilog python my_algorithm.py --lr 0.01 --epoch 100\r\n```\r\nit is equal to:\r\n```bash\r\n$ nohup python my_algorithm.py --lr 0.01 --epoch 100 \u003e cilog.log 2\u003e\u00261 \u0026\r\n```\r\n\r\n`-e` usage:\r\n```bash\r\n$ cilog -e python my_algorithm.py --lr 0.01 --epoch 100\r\n```\r\nThere is no different to the previous example but will send you\r\nA EMAIL when the task finished [Using your default setting]. \r\nIt is especially useful when your program is time comsuming.\r\n\r\n`-c [config_file]`: use your own config file instead of the default one.\r\n\r\n`-r [redirect_file]`: redirect the output to a file instead of `cilog.log`.\r\n\r\nPs: Do not use the same cmdline parameters `-c -e -r` in your program,\r\nor it will cause an error.\r\n\r\nHelp: `cilog --help`\r\n\r\n\r\n## LICENSE\r\n\r\nSee [MIT LICENSE](https://github.com/CM-BF/CiLog/blob/master/LICENSE)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcm-bf%2Fcilog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcm-bf%2Fcilog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcm-bf%2Fcilog/lists"}