Welcome to pyzlog’s documentation!¶
Contents:
pyzlog¶
Simple python module to standardize logging for applications
- Free software: ISC license
- Documentation: https://pyzlog.readthedocs.org.
Features¶
- Standard json logging
- Support for custom fields property
- Log file rotation at specified file size
- Configurable number of backup log files
Installation¶
At the command line:
$ easy_install pyzlog
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv pyzlog
$ pip install pyzlog
Usage¶
To use pyzlog in a project:
import pyzlog
# initialize the zlogger
pyzlog.init_logs(
path='/var/log',
target='foo_app.log',
level=logging.DEBUG,
server_hostname='foo.app.io',
fields={'custom_1': None, 'custom_2': None})
# then, log something
pyzlog.info(extra={'custom_1': 42, 'custom_2': 'foo'})
# log an error
try:
raise_value_error()
except ValueError:
pyzlog.error(extra={'custom_1': 'oh noes'})
To write tests for an application using pyzlog:
import os
import json
import app
import pyzlog
import unittest2
class TestApp(unittest2.TestCase, pyzlog.LogTest):
def setUp(self):
self.path = os.path.abspath('.')
self.target = 'foo.log'
self.remove_log()
self.init_logs()
def tearDown(self):
self.remove_log()
def test_log(self):
app.something_that_logs()
events = self.get_log_messages()
self.assertEqual(1, len(events))
expected_event = {
'event_name': 'foo.event',
# ...
}
self.assertEqual(expected_event, json.loads(events[0]))
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/zeeto/pyzlog/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
pyzlog could always use more documentation, whether as part of the official pyzlog docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/zeeto/pyzlog/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up pyzlog for local development.
Fork the pyzlog repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/pyzlog.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv pyzlog $ cd pyzlog/ $ pip install -r requirements_dev.txt
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests:
$ flake8 pyzlog tests $ python setup.py test
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.6, and 2.7. Check https://travis-ci.org/zeeto/pyzlog/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- Matt Maybeno <m.maybeno@zeeto.io>
- Herb Johnson <herb@zeeto.io>
Contributors¶
None yet. Why not be the first?
History¶
0.1.0 (2015-10-13)¶
- First release on PyPI.
0.1.1 (2015-10-30)¶
- Added a class to help make testing easier.
0.1.2 (2016-01-07)¶
- Properly resolve hostname in log messages.
0.1.3 (2016-01-07)¶
- Fallback to hostname resolution in init_logs