Skip to content

Commit

Permalink
correct coding convention
Browse files Browse the repository at this point in the history
  • Loading branch information
thang committed Dec 24, 2017
1 parent b7511be commit 44fde00
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 218 deletions.
114 changes: 0 additions & 114 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,157 +1,43 @@
# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.static_storage/
.media/
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
.idea/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pip3 install .
```
# 7. References
## [0] Full logging format references
2 types of logging statement will be emmited by this library:
2 types of logging statement will be emitted by this library:
- Application log: normal logging statement
e.g.:
```
Expand Down Expand Up @@ -301,7 +301,7 @@ pip3 install json_logging --index-url https://test.pypi.org/simple/
pypi
```
python setup.py sdist upload -r pypi
python setup.py bdist_wheel --universal upload -r pypi
python3 setup.py bdist_wheel --universal upload -r pypi
pip3 install json_logging
```
bdist_wheel --universal
98 changes: 49 additions & 49 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ you can install Sanic on windows by running these commands:
[0] Full logging format references
----------------------------------

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

::
Expand Down Expand Up @@ -372,52 +372,52 @@ See following tables for detail format explanation:

- Common field

+-----------------+-----------------+-----------------+-----------------+
| Field | Description | Format | Example |
+=================+=================+=================+=================+
| written_at | The date when | ISO 8601 | 2017-12-23T15:1 |
| | this log | YYYY-MM-DDTHH:M | 4:02.208Z |
| | message was | M:SS.milliZ | |
| | written. | | |
+-----------------+-----------------+-----------------+-----------------+
| written_ts | The timestamp | long number | 145682055381684 |
| | in nano-second | | 9408 |
| | precision when | | |
| | this request | | |
| | metric message | | |
| | was written. | | |
+-----------------+-----------------+-----------------+-----------------+
| correlation_id | The timestamp | string | db2d002e-2702-4 |
| | in nano-second | | 1ec-66f5-c002a8 |
| | precision when | | 0a3d3f |
| | this request | | |
| | metric message | | |
| | was written. | | |
+-----------------+-----------------+-----------------+-----------------+
| type | Type of | string | |
| | logging. “logs” | | |
| | or “request” | | |
+-----------------+-----------------+-----------------+-----------------+
| component_id | Uniquely | string | 9e6f3ecf-def0-4 |
| | identifies the | | baf-8fac-9339e6 |
| | software | | 1d5645 |
| | component that | | |
| | has processed | | |
| | the current | | |
| | request | | |
+-----------------+-----------------+-----------------+-----------------+
| component_name | A | string | my-fancy-compon |
| | human-friendly | | ent |
| | name | | |
| | representing | | |
| | the software | | |
| | component | | |
+-----------------+-----------------+-----------------+-----------------+
| component_insta | Instance’s | string | 0 |
| nce | index of | | |
| | horizontally | | |
| | scaled service | | |
+-----------------+-----------------+-----------------+-----------------+
+-------------------+-----------------+-----------------+-----------------+
| Field | Description | Format | Example |
+===================+=================+=================+=================+
| written_at | The date when | ISO 8601 | 2017-12-23T15:1 |
| | this log | YYYY-MM-DDTHH:M | 4:02.208Z |
| | message was | M:SS.milliZ | |
| | written. | | |
+-------------------+-----------------+-----------------+-----------------+
| written_ts | The timestamp | long number | 145682055381684 |
| | in nano-second | | 9408 |
| | precision when | | |
| | this request | | |
| | metric message | | |
| | was written. | | |
+-------------------+-----------------+-----------------+-----------------+
| correlation_id | The timestamp | string | db2d002e-2702-4 |
| | in nano-second | | 1ec-66f5-c002a8 |
| | precision when | | 0a3d3f |
| | this request | | |
| | metric message | | |
| | was written. | | |
+-------------------+-----------------+-----------------+-----------------+
| type | Type of | string | |
| | logging. “logs” | | |
| | or “request” | | |
+-------------------+-----------------+-----------------+-----------------+
| component_id | Uniquely | string | 9e6f3ecf-def0-4 |
| | identifies the | | baf-8fac-9339e6 |
| | software | | 1d5645 |
| | component that | | |
| | has processed | | |
| | the current | | |
| | request | | |
+-------------------+-----------------+-----------------+-----------------+
| component_name | A | string | my-component |
| | human-friendly | | |
| | name | | |
| | representing | | |
| | the software | | |
| | component | | |
+-------------------+-----------------+-----------------+-----------------+
| component_instance| Instance’s | string | 0 |
| | index of | | |
| | horizontally | | |
| | scaled service | | |
+-------------------+-----------------+-----------------+-----------------+

- application logs

Expand Down Expand Up @@ -549,8 +549,8 @@ See following tables for detail format explanation:
| t_type | associated with | | n |
| | the entity of | | |
| | the response if | | |
| | available/speci | | |
| | fied | | |
| | available or | | |
| | specified | | |
+-----------------+-----------------+-----------------+-----------------+
| referer | For HTTP | string | /index.html |
| | requests, | | |
Expand Down
5 changes: 4 additions & 1 deletion example/non_web.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import json_logging, logging, sys
import logging
import sys

import json_logging

# log is initialized without a web framework name
json_logging.ENABLE_JSON_LOGGING = True
Expand Down
3 changes: 3 additions & 0 deletions example/sanic_sample_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json_logging
import logging
# noinspection PyPackageRequirements
import sanic
import sys

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


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


Expand Down
8 changes: 5 additions & 3 deletions json_logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

def get_correlation_id():
"""
Get current request correlation-id.
In request context, if one is not present, a new one might be generated depends on CREATE_CORRELATION_ID_IF_NOT_EXISTS setting value.
Get current request correlation-id. If one is not present, a new one might be generated
depends on CREATE_CORRELATION_ID_IF_NOT_EXISTS setting value.
:return: correlation-id string
"""
Expand Down Expand Up @@ -140,7 +140,7 @@ def init(framework_name=None):

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

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

# register flask support
# noinspection PyPep8
from json_logging.framework.sanic import SanicAppConfigurator, SanicAppRequestInstrumentationConfigurator, \
SanicRequestAdapter, SanicResponseAdapter

Expand Down
2 changes: 2 additions & 0 deletions json_logging/framework/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


def is_flask_present():
# noinspection PyPep8,PyBroadException
try:
import flask
return True
Expand Down Expand Up @@ -37,6 +38,7 @@ def config(self, app):

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

# noinspection PyAttributeOutsideInit
self.request_logger = logging.getLogger('flask-request-logger')
self.request_logger.setLevel(logging.DEBUG)
self.request_logger.addHandler(logging.StreamHandler(sys.stdout))
Expand Down
2 changes: 2 additions & 0 deletions json_logging/framework/sanic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


def is_sanic_present():
# noinspection PyBroadException
try:
# noinspection PyPackageRequirements
from sanic import Sanic
Expand Down Expand Up @@ -44,6 +45,7 @@ def config(self, app):
if not isinstance(app, Sanic):
raise RuntimeError("app is not a valid Sanic.app.Sanic app instance")

# noinspection PyAttributeOutsideInit
self.request_logger = logging.getLogger('sanic-request')
self.request_logger.setLevel(logging.DEBUG)
self.request_logger.addHandler(logging.StreamHandler(sys.stdout))
Expand Down
Loading

0 comments on commit 44fde00

Please sign in to comment.