Skip to content

Commit a9cfe03

Browse files
author
thang
committed
refactor documentation
1 parent 3bb401d commit a9cfe03

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# json-logging
22
Python logging library to emit JSON log that can be easily indexed and searchable by logging infrastructure such as [ELK](https://www.elastic.co/webinars/introduction-elk-stack).
3-
If you're using Cloud Foundry, it worth to check out the library [SAP/cf-python-logging-support](https://github.com/SAP/cf-python-logging-support) which I'm also original author and contributor.
3+
4+
If you're using Cloud Foundry, it worth to check out the library [SAP/cf-python-logging-support](https://github.com/SAP/cf-python-logging-support) which I'm also original author and contributor.
45
# Content
56
1. [Features](#1-features)
67
2. [Usage](#2-usage)
@@ -17,27 +18,28 @@ If you're using Cloud Foundry, it worth to check out the library [SAP/cf-python-
1718

1819
# 1. Features
1920
1. Lightweight, no dependencies. Tested with Python 2.7 & 3.5.
20-
2. 100% compatible with **logging** module. Minimal configuration needed.
21-
3. Emit JSON logs, see here for what kind of log will be emitted. [\[0\]](#0-full-logging-format-references)
21+
2. 100% compatible with built-in **logging** module. Minimal configuration needed.
22+
3. Emit JSON logs, see here for detailed log format. [\[0\]](#0-full-logging-format-references)
2223
4. Support **correlation-id** [\[1\]](#1-what-is-correlation-idrequest-id)
23-
5. Support request instrumentation. Built in support for [Flask](http://flask.pocoo.org/) & [Sanic](http://flask.pocoo.org/). Extensible to support others.
24-
6. Support adding extra properties to JSON log object.
24+
5. Support request instrumentation. Built in support for [Flask](http://flask.pocoo.org/) & [Sanic](http://flask.pocoo.org/). Extensible to support others. Pull Request welcome to add other frameworks' support.
25+
6. Support inject arbitrary extra properties to JSON log message.
2526

2627
# 2. Usage
27-
This library is very intrusive, once configured library will try to configure all loggers (existing and newly created) to emit log in JSON format.
2828
Install by running this command:
2929
> pip install json-logging
30-
31-
The most important method is **init(framework_name)**.
3230
33-
TODO: update guide on how to use ELK stack to view log
31+
By default log will be emitted in normal format to ease the local development. To enable it on production set either json_logging.ENABLE_JSON_LOGGING or ENABLE_JSON_LOGGING environment variable to true.
32+
33+
To configure, call json_logging.init(framework_name). Once configured library will try to configure all loggers (existing and newly created) to emit log in JSON format. See each use case for more detail.
3434

35+
TODO: update guide on how to use ELK stack to view log
3536
## 2.1 Non-web application log
3637
This mode don't support **correlation-id**.
3738
```python
3839
import json_logging, logging, sys
3940

4041
# log is initialized without a web framework name
42+
json_logging.ENABLE_JSON_LOGGING = True
4143
json_logging.init()
4244

4345
logger = logging.getLogger("test-logger")
@@ -54,6 +56,7 @@ logger.info("test logging statement")
5456
import datetime, logging, sys, json_logging, flask
5557

5658
app = flask.Flask(__name__)
59+
json_logging.ENABLE_JSON_LOGGING = True
5760
json_logging.init(framework_name='flask')
5861
json_logging.init_request_instrument(app)
5962

@@ -76,6 +79,7 @@ if __name__ == "__main__":
7679
import logging, sys, json_logging, sanic
7780

7881
app = sanic.Sanic()
82+
json_logging.ENABLE_JSON_LOGGING = True
7983
json_logging.init(framework_name='sanic')
8084
json_logging.init_request_instrument(app)
8185

0 commit comments

Comments
 (0)