Jump to content

Logs JSON Viewer


Robin S
 Share

Recommended Posts

Logs JSON Viewer

Formats JSON data in ProcessLogger for improved readability.

Because log files can only contain strings, it's a common practice to use json_encode() to convert an array to a string when you want to save the data to a log file.

But the resulting JSON is not as readable as it could be when viewing the log in ProcessLogger. The Logs JSON Viewer module uses the json-viewer library to improve the readability of JSON data in ProcessLogger and add some useful features.

Before:

ljv-1

After:

ljv-2

Configuration

You can set the config options for json-viewer in a textarea field. See the json-viewer readme for information about the options.

There is also an option to set the width of the column that contains the JSON data. This setting exists because otherwise the column jumps around in an inconsistent and distracting way when changing from log to log or between paginations.

Features

You can switch the view of the JSON data between formatted and unformatted using the toggle button at the bottom of the data.

The viewer has a number of useful features such as:

  • Progressively expand or collapse levels in the data.
  • View the count of child items and the data type of each item.
  • Search for a string within the data.
  • Copy all or part of the data to the clipboard (requires the HTTPS protocol).

 

https://github.com/Toutouwai/LogsJsonViewer
https://processwire.com/modules/logs-json-viewer/

  • Like 11
  • Thanks 3
Link to comment
Share on other sites

9 hours ago, Robin S said:

Because log files can only contain strings, it's a common practice to use json_encode() to convert an array to a string when you want to save the data to a log file.

Sure, I also do that ?

Thanks a 1000000 for sharing one of your modules again!

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
2 hours ago, MarkE said:

if the string is too long, it gets truncated in the log

LogsJsonViewer doesn't do any truncating, and doesn't get involved in the saving of log data at all - it just formats what is already in the log.

Your problem might be due to $maxLineLength in FileLog. There's a FileLog::setMaxLineLength() method, but I'm not sure how you could practically use this unless you write to your log file using FileLog::save() instead of the more convenient WireLog::save(). Instead you probably just have to try and avoid going over $maxLineLength if you are saving JSON, perhaps by doing your own truncation on individual values if they are long, before you save the data.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...