-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ansrivas/develop
Develop
- Loading branch information
Showing
8 changed files
with
155 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,3 +97,5 @@ ENV/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include README.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
pylogging | ||
~~~~~~~~~ | ||
|
||
A simple python logger which writes logs to disk with some default | ||
configs. | ||
|
||
Compatible with: | ||
~~~~~~~~~~~~~~~~ | ||
|
||
Python 2.7 and 3.5 | ||
|
||
Current stable version: | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
:: | ||
|
||
0.2.3 | ||
|
||
Installation: | ||
~~~~~~~~~~~~~ | ||
|
||
Install using pip | ||
^^^^^^^^^^^^^^^^^ | ||
|
||
:: | ||
|
||
pip install git+https://github.com/ansrivas/pylogging.git --upgrade | ||
|
||
Install by adding to requirements.txt of your project | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
- Add the following lines to your ``requirements.txt`` file. | ||
``git+https://github.com/ansrivas/pylogging.git`` | ||
|
||
- Install all packages in your ``requirements.txt`` file by running the | ||
command: ``$ pip install -r requirements.txt`` | ||
|
||
Install by adding to setup.py of your project | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
- Add the following to the ``install_requires`` parameter of your setup | ||
function: ``install_requires=['pylogging==0.1.0'],`` | ||
|
||
- Add the following to the ``dependency_links`` parameter of your setup | ||
function: | ||
``dependency_links=['https://github.com/ansrivas/pylogging/tarball/master#egg=pylogging-0.1.0'],`` | ||
|
||
- Install your project along with ``pylogging`` by running the command: | ||
``python setup.py install`` | ||
|
||
Usage: | ||
~~~~~~ | ||
|
||
- ``setup_logger`` sets up the global logger with the provided | ||
settings. After calling it once, simply ``import logging`` and create | ||
a logger for that module ``logger = logging.getLogger(__name__)`` and | ||
use it at shown below. | ||
|
||
:: | ||
|
||
from pylogging import HandlerType, setup_logger | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
if __name__ == '__main__': | ||
setup_logger(log_directory='./logs', file_handler_type=HandlerType.ROTATING_FILE_HANDLER, allow_console_logging=True) | ||
|
||
logger.error("Error logs") | ||
logger.debug("Debug logs") | ||
logger.info("Info logs") | ||
|
||
Important arguments to ``setup_logger`` function: | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
:: | ||
|
||
log_directory (str) :directory to write log files to. Applicable only when `allow_file_logging` = True | ||
file_handler_type :object of logging handler from HandlerType class. Applicable only when `allow_file_logging` = True | ||
allow_console_logging (bool) :Turn off/on the console logging. | ||
allow_file_logging (bool) :Turn off/on if logs need to go in files as well. | ||
backup_count (int) :Number of files to backup before rotating the logs. | ||
max_file_size_bytes (int) :Size of file in bytes before rotating the file. Applicable only to ROTATING_FILE_HANDLER. | ||
when_to_rotate (str) :Duration after which a file can be rotated. Applicable only to TIME_ROTATING_FILE_HANDLER | ||
Accepts following values: | ||
'S' Seconds | ||
'M' Minutes | ||
'H' Hours | ||
'D' Days | ||
'W0'-'W6' Weekday (0=Monday) | ||
'midnight' Roll over at midnight | ||
change_log_level (dict) :A dictionary of handlers with corresponding log-level ( for eg. {'requests':'warning'} ) | ||
console_log_level (dict) :Change the LogLevel of console log handler, default is INFO | ||
gelf_handler :An external handler for graylog data publishing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
"""Initialize module utils.""" | ||
|
||
from .create_logger import setup_logger | ||
__all__ = ['setup_logger', 'HandlerType', 'Formatters'] | ||
from ._create_logger import setup_logger | ||
from .handler_types import HandlerType | ||
from .formatters import Formatters | ||
|
||
__version__ = '0.2.0' | ||
__version__ = '0.2.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,46 @@ | ||
import re | ||
from os import path | ||
|
||
from codecs import open # To use a consistent encoding | ||
from setuptools import find_packages, setup | ||
|
||
here = path.abspath(path.dirname(__file__)) | ||
|
||
# Get the long description from the relevant file | ||
with open(path.join(here, 'README.rst'), encoding='utf-8') as f: | ||
long_description = f.read() | ||
|
||
|
||
def get_version(): | ||
with open('pylogging/__init__.py') as version_file: | ||
return re.search(r"""__version__\s+=\s+(['"])(?P<version>.+?)\1""", | ||
version_file.read()).group('version') | ||
|
||
|
||
setup(name='pylogging', | ||
version='0.2.0', | ||
version=get_version(), | ||
description='File logging for Python', | ||
long_description=long_description, | ||
author='Ankur Srivastava', | ||
author_email='[email protected]', | ||
url='https://github.com/ansrivas/pylogging', | ||
download_url='https://github.com/ansrivas/pylogging/tarball/0.2.0', | ||
download_url='https://github.com/ansrivas/pylogging/tarball/{0}'.format(get_version()), | ||
include_package_data=True, | ||
license='MIT', | ||
install_requires=['future', 'requests', 'requests-futures', 'ujson', 'graypy'], | ||
zip_safe=False, | ||
install_requires=['future', 'requests-futures', 'ujson', 'graypy'], | ||
extras_require={ | ||
'dev': [ | ||
'pytest', | ||
'pytest-pep8', | ||
'pytest-cov', | ||
] | ||
}, | ||
classifiers=[ | ||
"Programming Language :: Python :: 2", | ||
"Programming Language :: Python :: 2.7", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.4", | ||
"Programming Language :: Python :: 3.5", | ||
"Programming Language :: Python :: 3.6", ], | ||
packages=find_packages()) |