Skip to content

Commit ecd08cf

Browse files
committed
Add some documentation
1 parent 76fcb16 commit ecd08cf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
JSON logging for Python [![PyPi version](https://pypip.in/v/json-logging-py/badge.png)](https://crate.io/packages/json-logging-py/)
1+
JSON logging for Python [![PyPi version](https://img.shields.io/pypi/v/json-logging-py.svg)](https://pypi.python.org/pypi/json-logging-py/)
22
============
33

44
This library provides Python logging formatters to output JSON, 2 formatters are specific for Logstash message format version 0 or 1.

jsonlogging.py

+21
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,21 @@
1010

1111

1212
class JSONFormatter(logging.Formatter):
13+
"""
14+
JSON formatter for python logging
15+
16+
You can pass additional tags on a per message basis using the key "tags" in the extra parameter.
17+
eg: logger.error('hello world!', extra={"tags": ["hello=world"]})
18+
"""
1319

1420
def __init__(self, tags=None, hostname=None, fqdn=False, message_type='JSON', indent=None):
21+
"""
22+
:param tags: a list of tags to add to every messages
23+
:hostname: force a specific hostname
24+
:fqdn: a boolean to use the FQDN instead of the machine's hostname
25+
:message_type: the message type for Logstash formatters
26+
:indent: indent level of the JSON output
27+
"""
1528
self.message_type = message_type
1629
self.tags = tags if tags is not None else []
1730
self.extra_tags = []
@@ -111,6 +124,10 @@ def format(self, record, serialize=True):
111124

112125

113126
class LogstashFormatterV0(JSONFormatter):
127+
"""
128+
Logstash formatter version 0
129+
"""
130+
114131
version = 0
115132

116133
def format(self, record):
@@ -145,6 +162,10 @@ def format(self, record):
145162

146163

147164
class LogstashFormatterV1(JSONFormatter):
165+
"""
166+
Logstash formatter version 1
167+
"""
168+
148169
def format(self, record):
149170
# Create message dict
150171
message = {

0 commit comments

Comments
 (0)