Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1002 Bytes

README.md

File metadata and controls

44 lines (31 loc) · 1002 Bytes

gjhandler

gjhandler is a simple log handler which generates new line delimited JSON for Cloud Logging and google-fluentd.

Installation

pip install git+https://github.com/sfujiwara/gjhandler.git

Example

import logging
import gjhandler

logger = logging.getLogger("gj_logger")
logger.setLevel(logging.DEBUG)
logger.addHandler(gjhandler.GoogleJsonHandler(filename="log_test.json"))

logger.info("this is info")
logger.error("this is error")

Resulting Outputs

{"timestamp": {"seconds": 1472657255, "nanos": 154423952}, "message": "this is info", "severity": "INFO", "thread": 140735257141248}
{"timestamp": {"seconds": 1472657255, "nanos": 155013084}, "message": "this is error", "severity": "ERROR", "thread": 140735257141248}

Setting for google-fluentd

<source>
  type tail
  format json
  path /var/log/python/*.log,/var/log/python/*.json
  read_from_head true
  tag python
</source>