Skip to content

feat(cli): option to log in plain JSON#231

Merged
jansegre merged 1 commit intodevfrom
feat/json-logs
Jun 17, 2021
Merged

feat(cli): option to log in plain JSON#231
jansegre merged 1 commit intodevfrom
feat/json-logs

Conversation

@jansegre
Copy link
Member

This is what a regular log looks like:

2021-06-15 21:56:36 [info     ] [hathor.cli.run_node] hathor-core v0.39.1            genesis=3fdff62 hathor=0.39.1 my_peer_id=c68251cd14fb3d02eb743f39c5663f291f17d40f466fc0207eae28a82cd4e0ba pid=20658 platform=Darwin-20.5.0-x86_64-i386-64bit python=3.7.10-CPython
2021-06-15 21:56:36 [info     ] [hathor.cli.run_node] with storage                   path=/Users/jan/Projects/hathor-core4/datamain storage_class=TransactionRocksDBStorage
2021-06-15 21:56:36 [info     ] [hathor.cli.run_node] with cache                     capacity=100000 interval=5
2021-06-15 21:56:36 [info     ] [hathor.manager] start manager                  network=mainnet
2021-06-15 21:56:36 [info     ] [hathor.p2p.manager] update whitelist
2021-06-15 21:56:36 [info     ] [hathor.manager] initialize
^C2021-06-15 21:56:38 [warning  ] [hathor.cli.main] Aborting and exiting...

But when using --json-logs it looks like this:

{"hathor": "0.39.1", "pid": 20734, "genesis": "3fdff62", "my_peer_id": "c68251cd14fb3d02eb743f39c5663f291f17d40f466fc0207eae28a82cd4e0ba", "python": "3.7.10-CPython", "platform": "Darwin-20.5.0-x86_64-i386-64bit", "event": "hathor-core v0.39.1", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 21:57:17"}
{"storage_class": "TransactionRocksDBStorage", "path": "/Users/jan/Projects/hathor-core4/datamain", "event": "with storage", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 21:57:17"}
{"capacity": 100000, "interval": 5, "event": "with cache", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 21:57:17"}
{"network": "mainnet", "event": "start manager", "logger": "hathor.manager", "level": "info", "timestamp": "2021-06-15 21:57:17"}
{"event": "update whitelist", "logger": "hathor.p2p.manager", "level": "info", "timestamp": "2021-06-15 21:57:17"}
{"event": "initialize", "logger": "hathor.manager", "level": "info", "timestamp": "2021-06-15 21:57:18"}
^C{"event": "Aborting and exiting...", "logger": "hathor.cli.main", "level": "warning", "timestamp": "2021-06-15 21:57:19"}

It still logs to stderr and does not mess with stdout, but will correctly capture unhandled exceptions:

{"hathor": "0.39.1", "pid": 21091, "genesis": "3fdff62", "my_peer_id": "c68251cd14fb3d02eb743f39c5663f291f17d40f466fc0207eae28a82cd4e0ba", "python": "3.7.10-CPython", "platform": "Darwin-20.5.0-x86_64-i386-64bit", "event": "hathor-core v0.39.1", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 21:59:16"}
{"storage_class": "TransactionRocksDBStorage", "path": "/Users/jan/Projects/hathor-core4/datamain", "event": "with storage", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 21:59:16"}
{"capacity": 100000, "interval": 5, "event": "with cache", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 21:59:16"}
{"network": "mainnet", "event": "start manager", "logger": "hathor.manager", "level": "info", "timestamp": "2021-06-15 21:59:16"}
{"event": "update whitelist", "logger": "hathor.p2p.manager", "level": "info", "timestamp": "2021-06-15 21:59:16"}
{"event": "initialize", "logger": "hathor.manager", "level": "info", "timestamp": "2021-06-15 21:59:16"}
{"event": "Uncaught exception:", "logger": "hathor.cli.main", "level": "error", "timestamp": "2021-06-15 21:59:16", "exception": "Traceback (most recent call last):\n  File \"/Users/jan/Projects/hathor-core4/hathor/cli/main.py\", line 148, in main\n    sys.exit(CliManager().execute_from_command_line())\n  File \"/Users/jan/Projects/hathor-core4/hathor/cli/main.py\", line 143, in execute_from_command_line\n    module.main()\n  File \"/Users/jan/Projects/hathor-core4/hathor/cli/run_node.py\", line 439, in main\n    RunNode().run()\n  File \"/Users/jan/Projects/hathor-core4/hathor/cli/run_node.py\", line 428, in __init__\n    self.prepare(args)\n  File \"/Users/jan/Projects/hathor-core4/hathor/cli/run_node.py\", line 235, in prepare\n    self.start_manager()\n  File \"/Users/jan/Projects/hathor-core4/hathor/cli/run_node.py\", line 239, in start_manager\n    self.manager.start()\n  File \"/Users/jan/Projects/hathor-core4/hathor/manager.py\", line 237, in start\n    self._initialize_components()\n  File \"/Users/jan/Projects/hathor-core4/hathor/manager.py\", line 337, in _initialize_components\n    raise Exception('foobar')\nException: foobar"}

And unhandled error in deferred:

{"hathor": "0.39.1", "pid": 22218, "genesis": "3fdff62", "my_peer_id": "c68251cd14fb3d02eb743f39c5663f291f17d40f466fc0207eae28a82cd4e0ba", "python": "3.7.10-CPython", "platform": "Darwin-20.5.0-x86_64-i386-64bit", "event": "hathor-core v0.39.1", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 22:02:30"}
{"storage_class": "TransactionRocksDBStorage", "path": "/Users/jan/Projects/hathor-core4/datamain", "event": "with storage", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 22:02:30"}
{"capacity": 100000, "interval": 5, "event": "with cache", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 22:02:30"}
{"network": "mainnet", "event": "start manager", "logger": "hathor.manager", "level": "info", "timestamp": "2021-06-15 22:02:30"}
{"event": "update whitelist", "logger": "hathor.p2p.manager", "level": "info", "timestamp": "2021-06-15 22:02:30"}
{"event": "Unhandled error in Deferred:", "logger": "twisted", "level": "critical", "timestamp": "2021-06-15 22:02:30"}
{"event": "", "logger": "twisted", "level": "critical", "timestamp": "2021-06-15 22:02:30", "exception": "Exception: foobar"}
{"listen": 9080, "with_wallet_api": false, "event": "with status", "logger": "hathor.cli.run_node", "level": "info", "timestamp": "2021-06-15 22:02:30"}
...

@jansegre jansegre self-assigned this Jun 15, 2021
@jansegre jansegre requested a review from luislhl June 15, 2021 22:11
@codecov-commenter
Copy link

Codecov Report

Merging #231 (e3766eb) into dev (72b2473) will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #231      +/-   ##
==========================================
+ Coverage   83.29%   83.32%   +0.02%     
==========================================
  Files         147      147              
  Lines       14245    14245              
  Branches     1996     1996              
==========================================
+ Hits        11866    11869       +3     
+ Misses       1952     1949       -3     
  Partials      427      427              
Impacted Files Coverage Δ
hathor/transaction/base_transaction.py 93.60% <0.00%> (+0.31%) ⬆️
hathor/wallet/resources/thin_wallet/send_tokens.py 68.96% <0.00%> (+0.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72b2473...e3766eb. Read the comment docs.

@jansegre jansegre merged commit 41b410a into dev Jun 17, 2021
@jansegre jansegre deleted the feat/json-logs branch June 17, 2021 19:08
@jansegre jansegre mentioned this pull request Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants