Last active
March 26, 2018 22:53
-
-
Save knowsuchagency/5eb628dccbc9fd564eebfda90e6dbad6 to your computer and use it in GitHub Desktop.
integrate logging.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import logging\nimport sys\nfrom pprint import pprint\n\nimport eliot", | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def to_logger(msg: dict):\n \"\"\"\n Log message to basic logging mechanism.\n \n Args:\n _level: The logging level\n \"\"\"\n lvl = msg.pop('_level', logging.INFO)\n \n logging.log(lvl, msg)\n\n\ndef pretty_print(msg: dict):\n \"\"\"Pretty print message to stdout.\"\"\"\n pprint(msg)\n \n\neliot.add_destinations(to_logger, pretty_print)", | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "with eliot.start_action(action_type='parent message', arg='foo', _level=logging.CRITICAL):\n with eliot.start_action(action_type='child message', arg='bar'):\n pass", | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "CRITICAL:root:{'arg': 'foo', 'action_status': 'started', 'task_uuid': 'df21dfed-89d5-4be1-96e8-739811e1e188', 'task_level': [1], 'timestamp': 1522104758.064459, 'action_type': 'parent message'}\n", | |
"name": "stderr" | |
}, | |
{ | |
"output_type": "stream", | |
"text": "{'action_status': 'started',\n 'action_type': 'parent message',\n 'arg': 'foo',\n 'task_level': [1],\n 'task_uuid': 'df21dfed-89d5-4be1-96e8-739811e1e188',\n 'timestamp': 1522104758.064459}\n{'action_status': 'started',\n 'action_type': 'child message',\n 'arg': 'bar',\n 'task_level': [2, 1],\n 'task_uuid': 'df21dfed-89d5-4be1-96e8-739811e1e188',\n 'timestamp': 1522104758.070697}\n{'action_status': 'succeeded',\n 'action_type': 'child message',\n 'task_level': [2, 2],\n 'task_uuid': 'df21dfed-89d5-4be1-96e8-739811e1e188',\n 'timestamp': 1522104758.073175}\n{'action_status': 'succeeded',\n 'action_type': 'parent message',\n 'task_level': [3],\n 'task_uuid': 'df21dfed-89d5-4be1-96e8-739811e1e188',\n 'timestamp': 1522104758.07524}\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.6.4", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "5eb628dccbc9fd564eebfda90e6dbad6", | |
"data": { | |
"description": "integrate logging.ipynb", | |
"public": false | |
} | |
}, | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/5eb628dccbc9fd564eebfda90e6dbad6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment