{"id":20677749,"url":"https://github.com/clivern/pylogging","last_synced_at":"2025-04-19T21:03:52.265Z","repository":{"id":62581490,"uuid":"41494370","full_name":"Clivern/PyLogging","owner":"Clivern","description":":rugby_football: Python Logging Library","archived":false,"fork":false,"pushed_at":"2024-02-29T20:27:29.000Z","size":55,"stargazers_count":12,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-16T03:14:41.918Z","etag":null,"topics":["email-notification","flask","logging","python"],"latest_commit_sha":null,"homepage":"http://clivern.github.io/PyLogging/","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/Clivern.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}},"created_at":"2015-08-27T15:16:38.000Z","updated_at":"2021-10-17T12:47:08.000Z","dependencies_parsed_at":"2024-02-29T21:51:01.833Z","dependency_job_id":null,"html_url":"https://github.com/Clivern/PyLogging","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FPyLogging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FPyLogging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FPyLogging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FPyLogging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clivern","download_url":"https://codeload.github.com/Clivern/PyLogging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224969894,"owners_count":17400294,"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":["email-notification","flask","logging","python"],"created_at":"2024-11-16T21:16:56.031Z","updated_at":"2024-11-16T21:16:56.590Z","avatar_url":"https://github.com/Clivern.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"PyLogging\n=========\n\nPyLogging is a light-weight python logging library. It provides ability to write logs in your own customized format. It is also provides support for custom log filters, custom log actions and email notifications.\n\n*Current version: [v1.0.2]*\n\n[![Build Status](https://travis-ci.org/Clivern/PyLogging.svg?branch=master)](https://travis-ci.org/Clivern/PyLogging)\n[![PyPI version](https://badge.fury.io/py/PyLogging.svg)](https://badge.fury.io/py/PyLogging)\n\nInstallation\n------------\nTo install PyLogging run this command:\n```\npip install pylogging\n```\nor [download](https://github.com/Clivern/pylogging/archive/1.0.2.zip) Package then run this command:\n```\npip install PyLogging-1.0.2.zip\n```\n\nUsage\n-----\nAfter installing the library, Read the following usage criteria:\n\n### Basic Usage\n\nThe typical usage of this library is like the following:\n```\nimport pylogging\nimport os\n\n# Logs Dir Absolute Path\nlogs_path = os.path.dirname(os.path.abspath(__file__)) + '/logs/'\n# Create Logger Instance\nlogger = pylogging.PyLogging(LOG_FILE_PATH = logs_path)\n# Log Info Message\nlogger.info(\"Info Message\")\n# Log Warning Message\nlogger.warning(\"Warning Message.\")\n# Log Error Message\nlogger.error(\"Error Message.\")\n# Log Critical Message\nlogger.critical(\"Critical Message.\")\n# Log Normal Message\nlogger.log(\"Normal Log Message.\")\n```\n\n### Custom Configs\n\nA list of a vailable configs are:\n\n * `LOG_FILE_FORMAT`: Log file format (default:`%Y-%m-%d`).\n * `LOG_FILE_PATH`: Logs dir absolute path and it is required (default:` `).\n * `LOG_MESSAGE_FORMAT`: Log message format (default:`{TYPE}: \u003c{DATETIME}\u003e  {MESSAGE}`).\n * `DATES_FORMAT`: Dates format (default:`%Y-%m-%d`).\n * `DATETIME_FORMAT`: Datetimes format (default:`%Y-%m-%d %H:%M`).\n * `PLATFORM_DATA`: Whether to activate platform data (default:`False`).\n * `ALERT_STATUS`: Email notification status (default:`False`).\n * `ALERT_SUBJECT`: Email notification subject (default:`My APP Alert`).\n * `ALERT_EMAIL`: Receiver Email or emails (format:`you@gmail.com` or `you@gmail.com,other@gmail.com,..`).\n * `ALERT_TYPES`: Message types which will delivered to email (default:`['critical', 'error']`).\n * `MAILER_HOST`: SMTP server (default:`smtp.gmail.com`).\n * `MAILER_PORT`: SMTP server port (default:`587`).\n * `MAILER_USER`: SMTP server user (default:`None`).\n * `MAILER_PWD`: SMTP server password (default:`None`).\n * `MAILER_FROM`: Sender email (default:`you@gmail.com`).\n\nTo set configs in initialization:\n```\nimport pylogging\nimport os\n\n# Logs dir absolute path\nlogs_path = os.path.dirname(os.path.abspath(__file__)) + '/logs/'\n# Create a logger instance with custom configs\nlogger = pylogging.PyLogging(LOG_FILE_PATH = logs_path, LOG_FILE_FORMAT='%Y-%m-%d', DATES_FORMAT='%Y-%m-%d',..,..)\n# So the form will be\nlogger = pylogging.PyLogging(LOG_KEY_1 = 'value', LOG_KEY_2='value',..,..)\n```\n\nTo set a config value:\n```\nlogger.setConfig('CONFIG_KEY', 'config_value')\n```\n\nTo get a config value:\n```\nlogger.getConfig('CONFIG_KEY')\n```\n\n### Custom Filters\n\nTo define a filter:\n```\ndef customFilter(type, msg):\n\t# Filter message text here\n\treturn msg\n\nfilterIden = logger.addFilter(customFilter)\n```\n\nTo remove a filter:\n```\nlogger.removeFilter(filterIden)\n```\n\n### Custom Actions\n\nTo define an action:\n```\ndef customAction(type, msg):\n\t# Perform any custom action here\n\tpass\n\nactionIden = logger.addAction(customAction)\n```\n\nTo remove an action:\n```\nlogger.removeAction(actionIden)\n```\n\n### Email Notifications\n\nTo enable email notifications:\n```\nimport pylogging\nimport os\n\n# Logs Dir Absolute Path\nlogs_path = os.path.dirname(os.path.abspath(__file__)) + '/logs/'\n# Create Logger Instance\nlogger = pylogging.PyLogging(LOG_FILE_PATH = logs_path)\n# Activate email alerting\nlogger.setConfig('ALERT_STATUS', True)\n```\n\nThen set your own configurations like so\n```\n# Set default message subject\nlogger.setConfig('ALERT_SUBJECT', \"My APP Alert\")\n# Email to send message to\nlogger.setConfig('ALERT_EMAIL', 'you@gmail.com')\n# OR send message to many emails\nlogger.setConfig('ALERT_EMAIL', 'you@gmail.com,alex@gmail.com,mary@gmail.com')\n# Message types to receive alerts for\nlogger.setConfig('ALERT_TYPES', ['critical', 'error'])\n\n# our own SMTP server (Library uses gmail)\nlogger.setConfig('MAILER_HOST', 'smtp.gmail.com')\n# SMTP server port\nlogger.setConfig('MAILER_PORT', 587)\n# SMTP server username (your gmail email)\nlogger.setConfig('MAILER_USER', 'you@gmail.com')\n# SMTP server password (your gmail password)\nlogger.setConfig('MAILER_PWD', 'gmailpass')\n\n# Message from\nlogger.setConfig('MAILER_FROM', 'you@gmail.com')\n```\n\nWhen you log messages, Messages of critical and error types will be delivered to emails:\n```\n# Log Info Message\nlogger.info(\"Info Message\")\n# Log Normal Message\nlogger.log(\"Normal Log Message.\")\n# Log Warning Message\nlogger.warning(\"Warning Message.\")\n# Log Error Message (with email notification)\nlogger.error(\"Error Message.\")\n# Log Critical Message (with email notification)\nlogger.critical(\"Critical Message.\")\n```\n\nSo if you like to send alert to `you@gmail.com` and your email password is `dummypass` the library configs will be:\n```\nlogs_path = os.path.dirname(os.path.abspath(__file__)) + '/logs/'\nlogger = pylogging.PyLogging(LOG_FILE_PATH = logs_path)\nlogger.setConfig('ALERT_STATUS', True)\nlogger.setConfig('ALERT_SUBJECT', \"My APP Alert\")\nlogger.setConfig('ALERT_EMAIL', 'you@gmail.com')\nlogger.setConfig('ALERT_TYPES', ['critical', 'error'])\nlogger.setConfig('MAILER_HOST', 'smtp.gmail.com')\nlogger.setConfig('MAILER_PORT', 587)\nlogger.setConfig('MAILER_USER', 'you@gmail.com')\nlogger.setConfig('MAILER_PWD', 'dummypass')\nlogger.setConfig('MAILER_FROM', 'you@gmail.com')\n\nlogger.info(\"Info Message\")\nlogger.log(\"Normal Log Message.\")\nlogger.warning(\"Warning Message.\")\nlogger.error(\"Error Message.\")\nlogger.critical(\"Critical Message.\")\n```\n\nCustomizing\n===========\n\nLog File\n--------\nSince log file name passes through `strftime(format)`, You can change file name into any valid time format string. For more info about [format strings](https://docs.python.org/2/library/time.html#time.strftime).\n```\nlogger.setConfig('LOG_FILE_FORMAT', '%y-%m-%d')\n```\n\nLog Message\n-----------\nBy default you can use combination of available vars in log message format:\n\n * `{TYPE}`: Log message type.\n * `{DATE}`: Log time date.\n * `{DATETIME}`: Log time datetime.\n * `{MESSAGE}`: Log message content.\n\nThe default format is `{TYPE}: \u003c{DATETIME}\u003e  {MESSAGE}`, You can change like the following:\n```\nlogger.setConfig('LOG_MESSAGE_FORMAT', '{DATE}: {TYPE}-{MESSAGE}')\n```\n\nTo add additional platform vars. You need to activate them:\n```\nlogger.setConfig('PLATFORM_DATA', True)\n```\n\nThis will allow usage of:\n\n * `PL_TYPE`: The machine type, e.g. `i386`\n * `PL_NAME`: The computer’s network name.\n * `PL_PROCESSOR`: The (real) processor name, e.g. `amdk6`.\n * `PL_PY_BUILD_DATE`: The Python build number.\n * `PL_PY_COMPILER`: A string identifying the compiler used for compiling Python.\n * `PL_PY_RELEASE`: The system’s release, e.g. `2.2.0`.\n * `PL_OS`: The system/OS name, e.g. `Linux`, `Windows`\n * `PL_TIMEZONE`: The system timezone.\n\nFor example we can customize message format into:\n```\nlogger.setConfig('PLATFORM_DATA', True)\nlogger.setConfig('LOG_MESSAGE_FORMAT', '{DATE}-{PL_OS}: {TYPE} - {MESSAGE}')\n```\nand so on.\n\n\nMisc\n====\n\nChangelog\n---------\nVersion 1.0.2:\n```\nBug Fixes and docs enhancements.\n```\nVersion 1.0.1:\n```\nMailer class fixed.\n```\nVersion 1.0.0:\n```\ninitial release\n```\n\nAcknowledgements\n----------------\n\n© 2015, Clivern. Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).\n\n**PyLogging** is authored and maintained by [@clivern](http://github.com/clivern).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclivern%2Fpylogging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclivern%2Fpylogging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclivern%2Fpylogging/lists"}