LoginSignup
1
1

More than 5 years have passed since last update.

pygogoを使ってログをjsonで出す。

Last updated at Posted at 2016-01-25
import pygogo as gogo
formatter = gogo.formatters.structured_formatter
logger = gogo.Gogo('struct', low_formatter=formatter).get_logger(foo="barbar")

logger.debug('bought', extra={"type": "apple", "price": 250, "color": "red"})
#=> {"name": "struct.base", "level": "DEBUG", "color": "red", "price": 250, "msecs": 587.5449180603027, "time": "2016-01-25 16:02:24", "message": "bought", "foo": "barbar", "type": "apple"}

logger.debug('bought', extra={"type": "PC", "price": 100000, "memory": "16GB"})
#=>{"name": "struct.base", "level": "DEBUG", "price": 100000, "memory": "16GB", "msecs": 587.9619121551514, "time": "2016-01-25 16:02:24", "message": "bought", "foo": "barbar", "type": "PC"}

コンストラクタの引数にlow_levelを渡して上げると出力制御ができるっぽい。

import pygogo as gogo
formatter = gogo.formatters.structured_formatter
logger = gogo.Gogo('struct', low_formatter=formatter, low_level='info').get_logger(foo="barbar")

logger.debug('bought', extra={"type": "apple", "price": 250, "color": "red"})
#=>出ない
logger.info('bought', extra={"type": "PC", "price": 100000, "memory": "16GB"})
#=>出る
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1