Skip to content

Commit 44fde00

Browse files
author
thang
committed
correct coding convention
1 parent b7511be commit 44fde00

File tree

14 files changed

+126
-218
lines changed

14 files changed

+126
-218
lines changed

.gitignore

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,43 @@
11
# Created by .ignore support plugin (hsz.mobi)
22
### Python template
33
# Byte-compiled / optimized / DLL files
4-
__pycache__/
5-
*.py[cod]
6-
*$py.class
7-
84
# C extensions
9-
*.so
10-
115
# Distribution / packaging
12-
.Python
13-
build/
14-
develop-eggs/
15-
dist/
16-
downloads/
17-
eggs/
18-
.eggs/
19-
lib/
20-
lib64/
21-
parts/
22-
sdist/
23-
var/
24-
wheels/
25-
*.egg-info/
26-
.installed.cfg
27-
*.egg
28-
MANIFEST
29-
306
# PyInstaller
317
# Usually these files are written by a python script from a template
328
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33-
*.manifest
34-
*.spec
35-
369
# Installer logs
37-
pip-log.txt
38-
pip-delete-this-directory.txt
39-
4010
# Unit test / coverage reports
41-
htmlcov/
42-
.tox/
43-
.coverage
44-
.coverage.*
45-
.cache
46-
nosetests.xml
47-
coverage.xml
48-
*.cover
49-
.hypothesis/
50-
5111
# Translations
52-
*.mo
53-
*.pot
54-
5512
# Django stuff:
56-
*.log
57-
.static_storage/
58-
.media/
59-
local_settings.py
60-
6113
# Flask stuff:
62-
instance/
63-
.webassets-cache
64-
6514
# Scrapy stuff:
66-
.scrapy
67-
6815
# Sphinx documentation
69-
docs/_build/
70-
7116
# PyBuilder
72-
target/
73-
7417
# Jupyter Notebook
75-
.ipynb_checkpoints
76-
7718
# pyenv
78-
.python-version
79-
8019
# celery beat schedule file
81-
celerybeat-schedule
82-
8320
# SageMath parsed files
84-
*.sage.py
85-
8621
# Environments
87-
.env
88-
.venv
89-
env/
90-
venv/
91-
ENV/
92-
env.bak/
93-
venv.bak/
94-
9522
# Spyder project settings
96-
.spyderproject
97-
.spyproject
98-
9923
# Rope project settings
100-
.ropeproject
101-
10224
# mkdocs documentation
103-
/site
104-
10525
# mypy
106-
.mypy_cache/
10726
### JetBrains template
10827
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
10928
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
11029

11130
# User-specific stuff:
112-
.idea/**/workspace.xml
113-
.idea/**/tasks.xml
114-
.idea/dictionaries
115-
11631
# Sensitive or high-churn files:
117-
.idea/**/dataSources/
118-
.idea/**/dataSources.ids
119-
.idea/**/dataSources.xml
120-
.idea/**/dataSources.local.xml
121-
.idea/**/sqlDataSources.xml
122-
.idea/**/dynamic.xml
123-
.idea/**/uiDesigner.xml
124-
12532
# Gradle:
126-
.idea/**/gradle.xml
127-
.idea/**/libraries
128-
12933
# CMake
130-
cmake-build-debug/
131-
13234
# Mongo Explorer plugin:
133-
.idea/**/mongoSettings.xml
134-
13535
## File-based project format:
136-
*.iws
137-
13836
## Plugin-specific files:
13937

14038
# IntelliJ
141-
out/
142-
14339
# mpeltonen/sbt-idea plugin
144-
.idea_modules/
145-
14640
# JIRA plugin
147-
atlassian-ide-plugin.xml
148-
14941
# Cursive Clojure plugin
150-
.idea/replstate.xml
151-
15242
# Crashlytics plugin (for Android Studio and IntelliJ)
153-
com_crashlytics_export_strings.xml
154-
crashlytics.properties
155-
crashlytics-build.properties
156-
fabric.properties
15743
.idea/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pip3 install .
175175
```
176176
# 7. References
177177
## [0] Full logging format references
178-
2 types of logging statement will be emmited by this library:
178+
2 types of logging statement will be emitted by this library:
179179
- Application log: normal logging statement
180180
e.g.:
181181
```
@@ -301,7 +301,7 @@ pip3 install json_logging --index-url https://test.pypi.org/simple/
301301
pypi
302302
```
303303
python setup.py sdist upload -r pypi
304-
python setup.py bdist_wheel --universal upload -r pypi
304+
python3 setup.py bdist_wheel --universal upload -r pypi
305305
pip3 install json_logging
306306
```
307307
bdist_wheel --universal

README.rst

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ you can install Sanic on windows by running these commands:
317317
[0] Full logging format references
318318
----------------------------------
319319

320-
2 types of logging statement will be emmited by this library:
320+
2 types of logging statement will be emitted by this library:
321321
- Application log: normal logging statement e.g.:
322322

323323
::
@@ -372,52 +372,52 @@ See following tables for detail format explanation:
372372

373373
- Common field
374374

375-
+-----------------+-----------------+-----------------+-----------------+
376-
| Field | Description | Format | Example |
377-
+=================+=================+=================+=================+
378-
| written_at | The date when | ISO 8601 | 2017-12-23T15:1 |
379-
| | this log | YYYY-MM-DDTHH:M | 4:02.208Z |
380-
| | message was | M:SS.milliZ | |
381-
| | written. | | |
382-
+-----------------+-----------------+-----------------+-----------------+
383-
| written_ts | The timestamp | long number | 145682055381684 |
384-
| | in nano-second | | 9408 |
385-
| | precision when | | |
386-
| | this request | | |
387-
| | metric message | | |
388-
| | was written. | | |
389-
+-----------------+-----------------+-----------------+-----------------+
390-
| correlation_id | The timestamp | string | db2d002e-2702-4 |
391-
| | in nano-second | | 1ec-66f5-c002a8 |
392-
| | precision when | | 0a3d3f |
393-
| | this request | | |
394-
| | metric message | | |
395-
| | was written. | | |
396-
+-----------------+-----------------+-----------------+-----------------+
397-
| type | Type of | string | |
398-
| | logging. “logs” | | |
399-
| | or “request” | | |
400-
+-----------------+-----------------+-----------------+-----------------+
401-
| component_id | Uniquely | string | 9e6f3ecf-def0-4 |
402-
| | identifies the | | baf-8fac-9339e6 |
403-
| | software | | 1d5645 |
404-
| | component that | | |
405-
| | has processed | | |
406-
| | the current | | |
407-
| | request | | |
408-
+-----------------+-----------------+-----------------+-----------------+
409-
| component_name | A | string | my-fancy-compon |
410-
| | human-friendly | | ent |
411-
| | name | | |
412-
| | representing | | |
413-
| | the software | | |
414-
| | component | | |
415-
+-----------------+-----------------+-----------------+-----------------+
416-
| component_insta | Instance’s | string | 0 |
417-
| nce | index of | | |
418-
| | horizontally | | |
419-
| | scaled service | | |
420-
+-----------------+-----------------+-----------------+-----------------+
375+
+-------------------+-----------------+-----------------+-----------------+
376+
| Field | Description | Format | Example |
377+
+===================+=================+=================+=================+
378+
| written_at | The date when | ISO 8601 | 2017-12-23T15:1 |
379+
| | this log | YYYY-MM-DDTHH:M | 4:02.208Z |
380+
| | message was | M:SS.milliZ | |
381+
| | written. | | |
382+
+-------------------+-----------------+-----------------+-----------------+
383+
| written_ts | The timestamp | long number | 145682055381684 |
384+
| | in nano-second | | 9408 |
385+
| | precision when | | |
386+
| | this request | | |
387+
| | metric message | | |
388+
| | was written. | | |
389+
+-------------------+-----------------+-----------------+-----------------+
390+
| correlation_id | The timestamp | string | db2d002e-2702-4 |
391+
| | in nano-second | | 1ec-66f5-c002a8 |
392+
| | precision when | | 0a3d3f |
393+
| | this request | | |
394+
| | metric message | | |
395+
| | was written. | | |
396+
+-------------------+-----------------+-----------------+-----------------+
397+
| type | Type of | string | |
398+
| | logging. “logs” | | |
399+
| | or “request” | | |
400+
+-------------------+-----------------+-----------------+-----------------+
401+
| component_id | Uniquely | string | 9e6f3ecf-def0-4 |
402+
| | identifies the | | baf-8fac-9339e6 |
403+
| | software | | 1d5645 |
404+
| | component that | | |
405+
| | has processed | | |
406+
| | the current | | |
407+
| | request | | |
408+
+-------------------+-----------------+-----------------+-----------------+
409+
| component_name | A | string | my-component |
410+
| | human-friendly | | |
411+
| | name | | |
412+
| | representing | | |
413+
| | the software | | |
414+
| | component | | |
415+
+-------------------+-----------------+-----------------+-----------------+
416+
| component_instance| Instance’s | string | 0 |
417+
| | index of | | |
418+
| | horizontally | | |
419+
| | scaled service | | |
420+
+-------------------+-----------------+-----------------+-----------------+
421421

422422
- application logs
423423

@@ -549,8 +549,8 @@ See following tables for detail format explanation:
549549
| t_type | associated with | | n |
550550
| | the entity of | | |
551551
| | the response if | | |
552-
| | available/speci | | |
553-
| | fied | | |
552+
| | available or | | |
553+
| | specified | | |
554554
+-----------------+-----------------+-----------------+-----------------+
555555
| referer | For HTTP | string | /index.html |
556556
| | requests, | | |

example/non_web.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import json_logging, logging, sys
1+
import logging
2+
import sys
3+
4+
import json_logging
25

36
# log is initialized without a web framework name
47
json_logging.ENABLE_JSON_LOGGING = True

example/sanic_sample_app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json_logging
22
import logging
3+
# noinspection PyPackageRequirements
34
import sanic
45
import sys
56

@@ -14,10 +15,12 @@
1415
logger.addHandler(logging.StreamHandler(sys.stdout))
1516

1617

18+
# noinspection PyUnusedLocal
1719
@app.route("/")
1820
async def test(request):
1921
logger.info("test log statement")
2022
logger.info("test log statement", extra={'props': {"extra_property": 'extra_value'}})
23+
# noinspection PyUnresolvedReferences
2124
return sanic.response.text("hello world")
2225

2326

json_logging/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232
def get_correlation_id():
3333
"""
34-
Get current request correlation-id.
35-
In request context, if one is not present, a new one might be generated depends on CREATE_CORRELATION_ID_IF_NOT_EXISTS setting value.
34+
Get current request correlation-id. If one is not present, a new one might be generated
35+
depends on CREATE_CORRELATION_ID_IF_NOT_EXISTS setting value.
3636
3737
:return: correlation-id string
3838
"""
@@ -140,7 +140,7 @@ def init(framework_name=None):
140140

141141
def init_request_instrument(app=None):
142142
"""
143-
Sets up the current web application instance' request instrumentation logging configuration. Must be called after init method
143+
Configure the request instrumentation logging configuration for given web app. Must be called after init method
144144
145145
:param app: current web application instance
146146
"""
@@ -166,6 +166,7 @@ def __init__(self, request, **kwargs):
166166
self.request = request
167167
self.request_received_at = util.iso_time_format(utcnow)
168168

169+
# noinspection PyAttributeOutsideInit
169170
def update_response_status(self, response):
170171
"""
171172
update response information into this object, must be called before invoke request logging statement
@@ -279,6 +280,7 @@ def format(self, record):
279280
flask_support.FlaskResponseAdapter)
280281

281282
# register flask support
283+
# noinspection PyPep8
282284
from json_logging.framework.sanic import SanicAppConfigurator, SanicAppRequestInstrumentationConfigurator, \
283285
SanicRequestAdapter, SanicResponseAdapter
284286

json_logging/framework/flask/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
def is_flask_present():
12+
# noinspection PyPep8,PyBroadException
1213
try:
1314
import flask
1415
return True
@@ -37,6 +38,7 @@ def config(self, app):
3738

3839
json_logging.util.use_cf_logging_formatter([logging.getLogger('werkzeug')], JSONLogWebFormatter)
3940

41+
# noinspection PyAttributeOutsideInit
4042
self.request_logger = logging.getLogger('flask-request-logger')
4143
self.request_logger.setLevel(logging.DEBUG)
4244
self.request_logger.addHandler(logging.StreamHandler(sys.stdout))

json_logging/framework/sanic/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
def is_sanic_present():
12+
# noinspection PyBroadException
1213
try:
1314
# noinspection PyPackageRequirements
1415
from sanic import Sanic
@@ -44,6 +45,7 @@ def config(self, app):
4445
if not isinstance(app, Sanic):
4546
raise RuntimeError("app is not a valid Sanic.app.Sanic app instance")
4647

48+
# noinspection PyAttributeOutsideInit
4749
self.request_logger = logging.getLogger('sanic-request')
4850
self.request_logger.setLevel(logging.DEBUG)
4951
self.request_logger.addHandler(logging.StreamHandler(sys.stdout))

0 commit comments

Comments
 (0)