klogg
klogg copied to clipboard
Improved scratchpad (xml, json, base64 etc.)
[email protected] Hi, they have this useful feature there and also a small build it xml viewer which we can open a large xml line in a log and read it in a more human format
Other scratchpad suggestions are welcome in this issue.
I don't know if the scratchpad in build 500 is toward this request, but this nifty little scratchpad could become more useful:
- Add "Encode Base64" and "Format XML"
- Make "Format JSON" work (it doesn't seem right now)
- Restrict encode/decode/format to current selection if any
- Remember last text content and window position/size of the scratchpad
- Have "Format JSON" leave as-is any text that appears before the first opening bracket and after the detected end bracket of the JSON content (xyz { ... } zyx)
- Right-click on lines in the main window and choose "Append to scratchpad" in the context menu
Although I think these enhancements might have less priority than other useful bugfix or features.
Thanks for useful feedback. It is still early work in progress. I just had to do a lot of base64 -> json recently and composed this little tool. Will make it more useful but with less priority.
Add url decoding support
"Format xml" in Scratchpad has an issue if first root node is an XML declaration like <?xml version="1.0" encoding="utf-8" ?>
then the rest is removed. This may be solved by my 2nd remark:
Even if it is invalid XML, I think you should not simply keep the first root node and remove the rest, but keep & format the following root nodes as well (some logging software may output consecutive root XML chunks)
Button CRC32 could be a "direct button with a split drop-down menu on the right side" offering MD5, SHA1 and SHA256 as well. Also I think this button should present the result as a MsgBox and place the checksum in the clipboard, rather than replace the content of the scratchpad.
Idea
It would be nice to have a way to "unescape" a string. Namely, I want to replace
-
\n
by new line -
\t
by tab -
\"
by"
It will be useful for long formatted strings serialized in the json attribute.
Test case
Let's have this log line:
{"@timestamp":"2023-05-18 21:22:35,588","level":"ERROR","message":"Exception caught in mainLoop: Response not obtained in 20 seconds","exc_info":"Traceback (most recent call last):\nFile \"/venv/lib/python3.10/site-packages/trio/_threads.py\", line 215, in to_thread_run_sync\n return await trio.lowlevel.wait_task_rescheduled(abort)\nFile \"/venv/lib/python3.10/site-packages/trio/_core/_traps.py\", line 166, in wait_task_rescheduled\n return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()\nFile \"/venv/lib/python3.10/site-packages/outcome/_impl.py\", line 138, in unwrap\n raise captured_error\nResponseTimeout: Response not obtained in 20 seconds","thread":"MainThread"}
If I send it to the scratchpad and press the "Format json" button, then I will get
{
"@timestamp": "2023-05-18 21:22:35,588",
"exc_info": "Traceback (most recent call last):\nFile \"/venv/lib/python3.10/site-packages/trio/_threads.py\", line 215, in to_thread_run_sync\n return await trio.lowlevel.wait_task_rescheduled(abort)\nFile \"/venv/lib/python3.10/site-packages/trio/_core/_traps.py\", line 166, in wait_task_rescheduled\n return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()\nFile \"/venv/lib/python3.10/site-packages/outcome/_impl.py\", line 138, in unwrap\n raise captured_error\nResponseTimeout: Response not obtained in 20 seconds",
"level": "ERROR",
"message": "Exception caught in mainLoop: Response not obtained in 20 seconds",
"thread": "MainThread"
}
It already works.
Then, when I select the "exc_info" attribute value ...
Traceback (most recent call last):\nFile \"/venv/lib/python3.10/site-packages/trio/_threads.py\", line 215, in to_thread_run_sync\n return await trio.lowlevel.wait_task_rescheduled(abort)\nFile \"/venv/lib/python3.10/site-packages/trio/_core/_traps.py\", line 166, in wait_task_rescheduled\n return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()\nFile \"/venv/lib/python3.10/site-packages/outcome/_impl.py\", line 138, in unwrap\n raise captured_error\nResponseTimeout: Response not obtained in 20 seconds
... and press the new (desired) "Unescape" button, I want it to be replaced with this text:
Traceback (most recent call last):
File "/venv/lib/python3.10/site-packages/trio/_threads.py", line 215, in to_thread_run_sync
return await trio.lowlevel.wait_task_rescheduled(abort)
File "/venv/lib/python3.10/site-packages/trio/_core/_traps.py", line 166, in wait_task_rescheduled
return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
File "/venv/lib/python3.10/site-packages/outcome/_impl.py", line 138, in unwrap
raise captured_error
ResponseTimeout: Response not obtained in 20 seconds
Thanks for the work on klogg. I'm excited about how much better it is than the original glogg.
Nice idea!
Need to revisit and split into separate issues