All Projects → Clivern → Pylogging

Clivern / Pylogging

Licence: mit
🏉 Python Logging Library

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pylogging

Pyrollbar
Error tracking and logging from Python to Rollbar
Stars: ✭ 169 (+1777.78%)
Mutual labels:  flask, logging
Flask Humanize
Common humanization utilities for Flask applications
Stars: ✭ 26 (+188.89%)
Mutual labels:  flask
Gpt2 App
A Flask Web App for Generating Text with GPT-2
Stars: ✭ 24 (+166.67%)
Mutual labels:  flask
Intro To Apis Flask
Starter repository for the Introductions to API course
Stars: ✭ 26 (+188.89%)
Mutual labels:  flask
Znetcs.aspnetcore.logging.entityframeworkcore
This is Entity Framework Core logger and logger provider. A small package to allow store logs in any data store using Entity Framework Core.
Stars: ✭ 24 (+166.67%)
Mutual labels:  logging
Discord Scripts
A collection of scripts to enhance your Discord experience.
Stars: ✭ 26 (+188.89%)
Mutual labels:  logging
Sls Logrus Hook
Logrus hook for aliyun sls
Stars: ✭ 23 (+155.56%)
Mutual labels:  logging
Flask Bones
An example of a large scale Flask application using blueprints and extensions.
Stars: ✭ 849 (+9333.33%)
Mutual labels:  flask
Vulpy
Vulnerable Python Application To Learn Secure Development
Stars: ✭ 25 (+177.78%)
Mutual labels:  flask
Python Json Logger
Json Formatter for the standard python logger
Stars: ✭ 931 (+10244.44%)
Mutual labels:  logging
Phildb
Timeseries database
Stars: ✭ 25 (+177.78%)
Mutual labels:  logging
Yii2 Slack Log
Pretty Slack log target for Yii 2
Stars: ✭ 24 (+166.67%)
Mutual labels:  logging
Databook
A facebook for data
Stars: ✭ 26 (+188.89%)
Mutual labels:  flask
Yii2 Telegram Log
Telegram log target for Yii 2
Stars: ✭ 24 (+166.67%)
Mutual labels:  logging
Wufei
Async Kuberenetes Namespace Log Recorder / Streamer
Stars: ✭ 27 (+200%)
Mutual labels:  logging
Hello Ai
AI, Tensorflow, Inceptionv3, AI as a Service, Flask
Stars: ✭ 23 (+155.56%)
Mutual labels:  flask
Logger
HTTP middleware for Go that logs web requests to an io.Writer.
Stars: ✭ 24 (+166.67%)
Mutual labels:  logging
Python Flask First Website
Stars: ✭ 26 (+188.89%)
Mutual labels:  flask
Social Listener
Python project used to collect tweets and social-network data from Social's API
Stars: ✭ 9 (+0%)
Mutual labels:  flask
Heroku Buildpack Python
The official Heroku buildpack for Python apps.
Stars: ✭ 849 (+9333.33%)
Mutual labels:  flask

PyLogging

PyLogging 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.

Current version: [v1.0.2]

Build Status PyPI version

Installation

To install PyLogging run this command:

pip install pylogging

or download Package then run this command:

pip install PyLogging-1.0.2.zip

Usage

After installing the library, Read the following usage criteria:

Basic Usage

The typical usage of this library is like the following:

import pylogging
import os

# Logs Dir Absolute Path
logs_path = os.path.dirname(os.path.abspath(__file__)) + '/logs/'
# Create Logger Instance
logger = pylogging.PyLogging(LOG_FILE_PATH = logs_path)
# Log Info Message
logger.info("Info Message")
# Log Warning Message
logger.warning("Warning Message.")
# Log Error Message
logger.error("Error Message.")
# Log Critical Message
logger.critical("Critical Message.")
# Log Normal Message
logger.log("Normal Log Message.")

Custom Configs

A list of a vailable configs are:

  • LOG_FILE_FORMAT: Log file format (default:%Y-%m-%d).
  • LOG_FILE_PATH: Logs dir absolute path and it is required (default:).
  • LOG_MESSAGE_FORMAT: Log message format (default:{TYPE}: <{DATETIME}> {MESSAGE}).
  • DATES_FORMAT: Dates format (default:%Y-%m-%d).
  • DATETIME_FORMAT: Datetimes format (default:%Y-%m-%d %H:%M).
  • PLATFORM_DATA: Whether to activate platform data (default:False).
  • ALERT_STATUS: Email notification status (default:False).
  • ALERT_SUBJECT: Email notification subject (default:My APP Alert).
  • ALERT_EMAIL: Receiver Email or emails (format:[email protected] or [email protected],[email protected],..).
  • ALERT_TYPES: Message types which will delivered to email (default:['critical', 'error']).
  • MAILER_HOST: SMTP server (default:smtp.gmail.com).
  • MAILER_PORT: SMTP server port (default:587).
  • MAILER_USER: SMTP server user (default:None).
  • MAILER_PWD: SMTP server password (default:None).
  • MAILER_FROM: Sender email (default:[email protected]).

To set configs in initialization:

import pylogging
import os

# Logs dir absolute path
logs_path = os.path.dirname(os.path.abspath(__file__)) + '/logs/'
# Create a logger instance with custom configs
logger = pylogging.PyLogging(LOG_FILE_PATH = logs_path, LOG_FILE_FORMAT='%Y-%m-%d', DATES_FORMAT='%Y-%m-%d',..,..)
# So the form will be
logger = pylogging.PyLogging(LOG_KEY_1 = 'value', LOG_KEY_2='value',..,..)

To set a config value:

logger.setConfig('CONFIG_KEY', 'config_value')

To get a config value:

logger.getConfig('CONFIG_KEY')

Custom Filters

To define a filter:

def customFilter(type, msg):
	# Filter message text here
	return msg

filterIden = logger.addFilter(customFilter)

To remove a filter:

logger.removeFilter(filterIden)

Custom Actions

To define an action:

def customAction(type, msg):
	# Perform any custom action here
	pass

actionIden = logger.addAction(customAction)

To remove an action:

logger.removeAction(actionIden)

Email Notifications

To enable email notifications:

import pylogging
import os

# Logs Dir Absolute Path
logs_path = os.path.dirname(os.path.abspath(__file__)) + '/logs/'
# Create Logger Instance
logger = pylogging.PyLogging(LOG_FILE_PATH = logs_path)
# Activate email alerting
logger.setConfig('ALERT_STATUS', True)

Then set your own configurations like so

# Set default message subject
logger.setConfig('ALERT_SUBJECT', "My APP Alert")
# Email to send message to
logger.setConfig('ALERT_EMAIL', '[email protected]')
# OR send message to many emails
logger.setConfig('ALERT_EMAIL', '[email protected],[email protected],[email protected]')
# Message types to receive alerts for
logger.setConfig('ALERT_TYPES', ['critical', 'error'])

# our own SMTP server (Library uses gmail)
logger.setConfig('MAILER_HOST', 'smtp.gmail.com')
# SMTP server port
logger.setConfig('MAILER_PORT', 587)
# SMTP server username (your gmail email)
logger.setConfig('MAILER_USER', '[email protected]')
# SMTP server password (your gmail password)
logger.setConfig('MAILER_PWD', 'gmailpass')

# Message from
logger.setConfig('MAILER_FROM', '[email protected]')

When you log messages, Messages of critical and error types will be delivered to emails:

# Log Info Message
logger.info("Info Message")
# Log Normal Message
logger.log("Normal Log Message.")
# Log Warning Message
logger.warning("Warning Message.")
# Log Error Message (with email notification)
logger.error("Error Message.")
# Log Critical Message (with email notification)
logger.critical("Critical Message.")

So if you like to send alert to [email protected] and your email password is dummypass the library configs will be:

logs_path = os.path.dirname(os.path.abspath(__file__)) + '/logs/'
logger = pylogging.PyLogging(LOG_FILE_PATH = logs_path)
logger.setConfig('ALERT_STATUS', True)
logger.setConfig('ALERT_SUBJECT', "My APP Alert")
logger.setConfig('ALERT_EMAIL', '[email protected]')
logger.setConfig('ALERT_TYPES', ['critical', 'error'])
logger.setConfig('MAILER_HOST', 'smtp.gmail.com')
logger.setConfig('MAILER_PORT', 587)
logger.setConfig('MAILER_USER', '[email protected]')
logger.setConfig('MAILER_PWD', 'dummypass')
logger.setConfig('MAILER_FROM', '[email protected]')

logger.info("Info Message")
logger.log("Normal Log Message.")
logger.warning("Warning Message.")
logger.error("Error Message.")
logger.critical("Critical Message.")

Customizing

Log File

Since log file name passes through strftime(format), You can change file name into any valid time format string. For more info about format strings.

logger.setConfig('LOG_FILE_FORMAT', '%y-%m-%d')

Log Message

By default you can use combination of available vars in log message format:

  • {TYPE}: Log message type.
  • {DATE}: Log time date.
  • {DATETIME}: Log time datetime.
  • {MESSAGE}: Log message content.

The default format is {TYPE}: <{DATETIME}> {MESSAGE}, You can change like the following:

logger.setConfig('LOG_MESSAGE_FORMAT', '{DATE}: {TYPE}-{MESSAGE}')

To add additional platform vars. You need to activate them:

logger.setConfig('PLATFORM_DATA', True)

This will allow usage of:

  • PL_TYPE: The machine type, e.g. i386
  • PL_NAME: The computer’s network name.
  • PL_PROCESSOR: The (real) processor name, e.g. amdk6.
  • PL_PY_BUILD_DATE: The Python build number.
  • PL_PY_COMPILER: A string identifying the compiler used for compiling Python.
  • PL_PY_RELEASE: The system’s release, e.g. 2.2.0.
  • PL_OS: The system/OS name, e.g. Linux, Windows
  • PL_TIMEZONE: The system timezone.

For example we can customize message format into:

logger.setConfig('PLATFORM_DATA', True)
logger.setConfig('LOG_MESSAGE_FORMAT', '{DATE}-{PL_OS}: {TYPE} - {MESSAGE}')

and so on.

Misc

Changelog

Version 1.0.2:

Bug Fixes and docs enhancements.

Version 1.0.1:

Mailer class fixed.

Version 1.0.0:

initial release

Acknowledgements

© 2015, Clivern. Released under the MIT License.

PyLogging is authored and maintained by @clivern.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].