{"id":29596234,"url":"https://github.com/surfhawk/sl4p","last_synced_at":"2025-07-20T09:13:07.428Z","repository":{"id":57699403,"uuid":"247312386","full_name":"surfhawk/sl4p","owner":"surfhawk","description":"SL4P : simplest logging for your python","archived":false,"fork":false,"pushed_at":"2025-07-18T00:59:27.000Z","size":440,"stargazers_count":11,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-18T05:26:24.544Z","etag":null,"topics":["log","logger","logging","logging-library","python"],"latest_commit_sha":null,"homepage":"https://github.com/surfhawk/sl4p","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/surfhawk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-03-14T16:28:44.000Z","updated_at":"2025-07-18T00:59:30.000Z","dependencies_parsed_at":"2022-09-26T21:12:17.085Z","dependency_job_id":"3283210c-c1b9-4716-8d9b-65ee7fa6490b","html_url":"https://github.com/surfhawk/sl4p","commit_stats":{"total_commits":20,"total_committers":3,"mean_commits":6.666666666666667,"dds":0.09999999999999998,"last_synced_commit":"c73b0524489b16819bff97898a90ab4d8f18514f"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/surfhawk/sl4p","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surfhawk%2Fsl4p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surfhawk%2Fsl4p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surfhawk%2Fsl4p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surfhawk%2Fsl4p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/surfhawk","download_url":"https://codeload.github.com/surfhawk/sl4p/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surfhawk%2Fsl4p/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266094083,"owners_count":23875571,"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":["log","logger","logging","logging-library","python"],"created_at":"2025-07-20T09:13:05.468Z","updated_at":"2025-07-20T09:13:07.415Z","avatar_url":"https://github.com/surfhawk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SL4P : simplest logging for your python\n\n[![](https://img.shields.io/badge/pypi-1.4.5-007ec6?logo=PyPI\u0026logoColor=white)](https://pypi.org/project/sl4p/)\n[![](https://img.shields.io/badge/python-Min%203.0%20%7C%20Rec'd%203.6%2B-blue?logo=Python\u0026logoColor=white)](https://pypi.org/project/sl4p/)\n[![](https://img.shields.io/badge/license-BSD%20License-lightgrey)](https://pypi.org/project/sl4p/)\n[![](https://img.shields.io/badge/build-passing-brightgreen)](https://pypi.org/project/sl4p/)  \n\n**sl4p** is a logging library that makes it easy to introduce more production-focused logging into your python applications.    \nsl4p users need not know anything about the slightly complex built-in python logging, although sl4p uses built-in Python's logging internally.  \nQuite simply, **you can start logging right in any code with the three lines** below.\n\n```python\nfrom sl4p import *\n\nlog = sl4p.getLogger(__file__)\nlog.info(\"Hello Sl4p logger !\")\n```\n\nThen, a log file with the contents below will be created in the folder `./sl4p_logs` in the same location as your code.\n```\nINFO   | 2023.03.22-17:19:13 - embedding.py (  86) :: OPERATING TIMEZONE: +9:00\nINFO   | 2023.03.22-17:19:13 - embedding.py (  87) :: Program  @c8abb11e  started.  \u003c\u003cex1.py\u003e\u003e\nDEBUG  | 2023.03.22-17:19:13 - embedding.py (  88) ::          @@-- argv[0] = C:\\path\\to\\your\\python\\app.py\nINFO   | 2023.03.22-17:19:13 - ex1.py   (   4) :: Hello Sl4p logger !\nINFO   | 2023.03.22-17:19:13 - embedding.py ( 105) :: Program  c8abb11e  finished  \u003c\u003cex1.py\u003e\u003e  -----  Elapsed    0.0010 s\n```\nDon't waste your time learning logging. Just enjoy this!\n\n## Main Features\nHere are the main features that are very easy to use:\n\n**Basic**\n- Logging that can be used right away with little to no setup required (by default config)\n- **Colored console log**: Warning, Error, and Exception are output in progressively more emphasized colors (Python 3.6+)\n- ConfigFile: Single/multi-application logger settings by JSON files and python dictionary\n- **Auto purging**: log files can be divided and recorded by specified time period or filesize, and old ones can be automatically deleted\n- **Snippet log**: Logging to separate files for specific modules or subset of your Python program package\n- **Logging in multi-threaded/multi-process** (internally, without IPC, with recording to a same file)\n- Log of program context info: Timezone info, program execution path, total program run time, etc.\n\n**Utils \u0026 Advanced**\n- **SimpleTimer**: a stopwatch logging utility that supports start and multiple checks\n- `@sl4p_time()` records the time taken for function execution (optional user tag)\n- `@sl4p_try`, `@sl4p_try_exit` automatically log traceback using Try~Except statements\n- **Profiling**: record CPU and memory usage as a separate CSV file during program life\n- **ExceptionHook**: Register your function to execute in the event of an abnormal program termination\n\n\n## Installation\nThe **'sl4p'** package can be easily installed using pip.\n```\n$ pip install sl4p\n```\n\nOr download the appropriate .whl file for your Python version from the 'dist' folder on GitHub.\n```\n$ pip install sl4p-{pkg_ver}-{py_ver}-none-any.whl\n```\n\n## Configuration (Single App)\nSl4p has key concepts of **'configuration'** and **'logging'**.  \nConfiguration decides sl4p logger's behavior including logging level, message format, logfile savedir and so on.  \nYou can use Python dictionary or .cfg Yaml file to configuring as you want. \n\nThe following table describes the available keys and their corresponding values (default values indicated with an asterisk):\n```Yaml\n# Configured example\n{\n    \"__configver__\": \"C4\",  # For .cfg Yaml file, you must specify __configver__ \n\n    \"LOG\": {\n        \"use_console_print\": true,\n        \"console_level\": \"WARNING\",\n        \n        \"logging_level\": \"DEBUG\",\n        \"logging_format\": \"basic\",\n\n        \"logfile_savedir\": \"logs\",\n        \"logfile_name\": \"EXAMPLE_1\",\n    }\n}\n```\n| Key                 | Description                                                                                                                                       | Available value (*default)                                                                                                                                  |\n|---------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `use_console_print` | Whether to print log messages to the console.                                                                                                     | **Bool** (*) True, False                                                                                                                                    |\n| `console_level`     | The minimum level of logs to be printed in console.\u003cbr/\u003e Logs below this level will not be printed. If not be assigned, follow the logging_level. | (*) \"DEBUG\", \"INFO\", \"WARNING\",  \"ERROR\", \"CRITICAL\"                                                                                                        |\n| `console_format`    | The level of detail to include in the log message in console.  If not be assigned, follow the logging_format.                                     | \"simple\", (*) \"basic\", \"detail\", \"adap\"                                                                                                                     |\n| `console_stdout`    | Whether to send console output to stdout, otherwise to stderr which is the default of logging. (Output in red text in some IDEs)                  | **Bool** True, (*) False                                                                                                                                    |\n| `logging_level`     | The minimum level of logs to be recorded.\u003cbr/\u003e Logs below this level will not be recorded.                                                        | (*) \"DEBUG\", \"INFO\", \"WARNING\",  \"ERROR\", \"CRITICAL\"                                                                                                        |\n| `logging_format`    | The level of detail to include in the log message in file.                                                                                        | \"simple\", (*) \"basic\", \"detail\", \"adap\"                                                                                                                     |\n| `logfile_savedir`   | The absolute path to the directory where log files will be saved. \u003cbr/\u003e The path should be in either Windows or Linux format.                     | **String** : The OS-specific folder path \u003cbr/\u003ewindows ex) \"E:\\\\\\\\Workspace\\\\\\\\sl4p_logs\\\\\\\\app-abc\" \u003cbr/\u003e linux ex) \"/opt/my_appvar/data/sl4p_logs/app_abc\" |\n| `logfile_name`      | The log file name for your application. \u003cbr/\u003e(default: based on your python program's name)\u003cbr/\u003e Sl4p will use this prefix to identify and purge old log files.                        | **String** : OS-supported filename. \u003cbr/\u003e ex) \"LOG.your_app_name\"                                                                                           |\n| `save_period_type` | The time or size can be set as the criterion for dividing and saving log files. | **String** : \"B\", \"KB\", (*) \"MB\", \"GB\" by filesize\u003cbr/\u003e\"S\", \"M\", \"H\", \"D\" by time |\n| `save_period_interval` | Specifies the magnitude to use for the selected save_period_type | **Int** (*) 100 |\n| `save_files_nlimit` | Whether to split and save logs up to a maximum number of files. (Delete excess ones from oldest to newest) | **Int** (*) 20 |\n| `purge_window_hours` | A window hours that deletes old log files (as much as the hours before the current time) | **Int** (*) 8800 |\n| `console_colorlog_kwargs` | The dictionary that is passed into initializing colorlog's ColoredFormatter as \\*\\*kwargs | **Dictionary** (*) colorlog's default (reference: https://github.com/borntyping/python-colorlog) |\n| . . . | _There are many other options, see sl4p_examples in this branch._ |\n\u003cbr/\u003e\n\n## Make logging\n\n### 1. Load your configuration\nIt is important to load your configuration before using your application. \nI recommend placing this loading config phase at the beginning of your application's main function. \nPlease note that this loading phase only needs to be executed once for the entire application package.\n\nWhen loading your configuration, you can pass your config (dict or Yaml file's path) as second parameter of getLogger().\nAdditionally, you can use the optional parameter debugprt=True to display sl4p's initialization info.\n\nHere are three ways to load your configuration:\n\n\nA. **'get-logger' style loading**\n```python\nlog = sl4p.getLogger(__file__, cfg=\"./applog.cfg\", debugprt=True)  #debugprt param is optional!\nlog.info(\"hello sl4p!\")\n```\n\nB. **'with-block' style loading**\n```python\nwith sl4p(__file__, cfg=logcfg_dict) as log:\n    log.info(\"hello sl4p!\")\n    log.error(\"Error occured! #%d\" % (400))\n    # log.error(\"Error occured! \", 400)  --\u003e Not support this 'print()' style, Please formatting.\n```\n\nC. **How to load logger in Jupyter**  \n`__file__`, the first argument of getLogger, is used as an identifier in Snippet logging.  \nInstead, enter any string in Jupyter.\n```python\nlog = sl4p.getLogger('jupyter', cfg=logcfg_dict):\nlog.info('Hello sl4p in jupyter!')\n```\n\n\u003cbr/\u003e\n\n### 2. Write a log message\nAfter loading your configuration, you can log messages anywhere in your application, even in another file or modules, without passing the second parameter into getLogger.  \nHere are two ways to use logging:\n\nA. **'get-logger' style logging**\n```python\nlog = sl4p.getLogger(__file__)\nlog.debug(\"Just pass only __file__\")\n```\n\nB. **'with-block' style logging**\n```python\nwith sl4p(__file__) as log:\n    log.warning(\"warn msg! : you should not pass 2nd parameter to sl4p() after configuration completed\")\n```\n\u003cbr/\u003e\n\nThat's it! Enjoy logging your application :)  \nRemember to load your configuration only once (initial entry-point, recommended) and log your messages everywhere !\n\n\u003cbr/\u003e\n\n\n\n## Utils \u0026 Advanced\n\nThe 'with-block' logging feature can measure elapsed time as DEBUG log and can also include a custom tag using `tag={TAG_NAME}`.  \nHere is an example:\n\n```python\nimport time\nwith sl4p(__file__, tag='myTag') as log:\n    time.sleep(1.0)\n    log.info('with-block time measuring and tagging feature!')\n```\nThis is the output log:\n```text\nDEBUG  | 2019.11.14-22:03:43 - example2.py #myTag @adfd08e4 started\nINFO   | 2019.11.14-22:03:44 - with-block time measuring and tagging feature!\nDEBUG  | 2019.11.14-22:03:44 - example2.py #myTag @adfd08e4 finished  ----  Elapsed    1.0001 s\n```\n\u003cbr/\u003e\n\n**Decorator - @sl4p_time(tag={TAG_NAME})**\u003cbr/\u003e\nYou can also use the `@sl4p_time(tag={TAG_NAME})` decorator to measure the execution time of a function and log it with DEBUG level:\n```python\n@sl4p_time()  # Although you do not use tagging, l4p_time decorator must be written with () brackets.\ndef my_function1():\n    time.sleep(1.5)\n    log.error('not yet...')\n```\nThis is the output log:\n```text\nDEBUG  | 2019.11.14-22:12:43 - example3.py f`my_function1() @19f19de9 started\nERROR  | 2019.11.14-22:12:44 - not yet...\nDEBUG  | 2019.11.14-22:12:44 - example3.py f`my_function1 @19f19de9 finished  ----  Elapsed    1.5038 s\n```\n\u003cbr/\u003e\n\n**Decorator - @sl4p_try, @sl4p_try_exit**\u003cbr/\u003e\nyou can use the `@sl4p_try` and `@sl4p_try_exit` decorator to try-except your function and log the traceback of the exception.\n```python\n@sl4p_try\ndef take_exception():\n    a = 'ABCD' + None\n```\nThis is the output log:\n```text\nERROR  | 2019.11.14-22:12:44 - can only concatenate str (not \"NoneType\") to str\nTraceback (most recent call last):\n  File \"D:\\Devel_Workspace\\py27_9\\devel_logger\\sl4p\\decorators.py\", line 21, in wrapped\n    return func(*args, **kwargs)\n  File \"D:/Devel_Workspace/py27_9/devel_logger/example3.py\", line 15, in take_exception\n    a = 'ABCD' + None\nTypeError: can only concatenate str (not \"NoneType\") to str\n```\nRemember `@sl4p_try` will continue the program when excepted, but `@sl4p_try_exit` will terminate it.\n\u003cbr/\u003e\u003cbr/\u003e\n\n\n## About\n\n### Dependencies\n* json\n* psutil\n* colorlog\n* pywin32 _(only in windows)_\n* colorama _(only in windows)_\n\n### License\nBSD 3\n\n### Getting Help / Discussion / Contributing\nRight here, please be active in this GitHub repository.  \nAll contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.  \n\u003cbr/\u003e\n\n***\n## Release Note\n\n**(*) ver1.4.5 :: Define pywin32 as static depd to comply PEP 508**  \nver1.4.4 :: Deprecate `imp` and replace it with `importlib` (imp is removed from python 3.12)  \nver 1.4.3 :: Prevented logfile name starting with . (period)  \nver 1.4.2 :: Coloring console log (by colorlog) and add related configs, Support console stdout'  \nver 1.4.1 :: Correct the docs, Change default config (console config has no initial values)  \nver 1.4.0 :: Layered apps-config, Support console level\u0026format, IndLogger, Enhance stability  \nver 1.3.3linux :: excluding 'psutil' in requires for linux   \nver 1.3.3 :: override_dict bugfix (support python 3.9+)  \nver 1.3.2 :: Add log_level for SimpleTimer: logger.create_simpleTimer(), config bugfix  \nver 1.3.1 :: Add log_level for @sl4p_time decorator  \nver 1.2.0 :: Add stopwatch(SimpleTimer), Profiling stats(CPU \u0026 MEM), Recording TimeZone  \nver 1.0.1 :: Supports multi-byte msg, update config and constants / Patch debugprt, start_ts  \nver 1.0.0 :: First deployed release version  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurfhawk%2Fsl4p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurfhawk%2Fsl4p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurfhawk%2Fsl4p/lists"}