uniplaces / unipy_logger

logger to abstract the format logic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python logger

Package to support logging standards at uniplaces (www.uniplaces.com). Used to enforce uniplaces log standards and respect uniplaces logging interface.

Log level respect RFC5424 https://tools.ietf.org/html/rfc5424

Improvements

Add tests and travis.

Prerequisites

This package needs python3 and has a dependency over logbook.

Installing

$ pip3 install unipy_logger

Example of usage

unipy*logger is fetching some evironment variables that must be set on runtime or exported in order for the logger to find them. These are APPID, ENV and GITHASH used to populate respectively app-id, env, git-hash. In order to add context fields that will be outputed in the resulting log json use addContextFields (receiving a dictionary) or *addContextField* (receiving a key value pair).

from unipy_logger import Logger

CONTEXT_FIELDS = {
    "foo": "bar",
    "lorem": "ipsum",
    "value": 10
}

Logger(sys.stdout, "DEBUG")
Logger.builder().addContextFields(CONTEXT_FIELDS).info("my first log")

# output
# {
#   "message": "my first log",
#   "app-id": "unipy_logger",
#   "git-hash": "28390e1f54d54b5189f5ec771860bc569e8ec507",
#   "time": "2018-01-30T15:14:45.43Z",
#   "env": dev,
#   "level_name": "INFO",
#   "level: 6,
#   "foo": "bar",
#   "lorem": "ipsum",
#   "value": 10
# }

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

Made with ❤️ at uniplaces

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

logger to abstract the format logic


Languages

Language:Python 100.0%