Textualize / toolong

A terminal application to view, tail, merge, and search log files (plus JSONL).

Home Page:https://www.textualize.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request ability to interpret new line characters in the right panel

Rictus opened this issue · comments

commented

Thank you for developing toolong; it has proven to be incredibly useful.

I've noticed that my logs sometimes contain numerous newline characters (\n), particularly evident when outputting results from commands like nvidia-smi. When I click on a logline, the right panel opens, which is a convenient feature for viewing the entirety of the log with a vertical scrollbar. However, since newline characters are not interpreted, the content can become difficult to read depending on its structure.

Could we consider adding the interpretation of newline characters ? Maybe optionally? This would enhance the readability of the logs for users dealing with similar formatting issues.

I am keen to contribute if necessary

commented

Example log file

Wed Apr 24 10:22:22 2024       \n+-----------------------------------------------------------------------------------------+\n| NVIDIA-SMI 550.40.07              Driver Version: 551.52         CUDA Version: 12.4     |\n|-----------------------------------------+------------------------+----------------------+\n| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |\n| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |\n|                                         |                        |               MIG M. |\n|=========================================+========================+======================|\n|   0  NVIDIA T1200 Laptop GPU        On  |   00000000:01:00.0  On |                  N/A |\n| N/A   51C    P8              8W /   80W |     835MiB /   4096MiB |      6%      Default |\n|                                         |                        |                  N/A |\n+-----------------------------------------+------------------------+----------------------+\n                                                                                         \n+-----------------------------------------------------------------------------------------+\n| Processes:                                                                              |\n|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |\n|        ID   ID                                                               Usage      |\n|=========================================================================================|\n|    0   N/A  N/A        22      G   /Xwayland                                   N/A      |\n+-----------------------------------------------------------------------------------------+

Possible fix, add the following line before the yield there line_panel.py#L45 :

self.text._text[0] = re.sub("\\\\n", "\n", self.text._text[0])

Before:
image

After:
image

It does the job but I feel like this is not the right place for it. Maybe textualize should provide an adapted Text type for this. @willmcgugan What is your advice on this ?

Ah, so these are escaped newlines. Is it common for logs to do that?

Seems like a reasonable thing to do. I wonder if it should be an option, in case "\n" appears in a log file that wasn't intended to be a newline.

commented

Ah, so these are escaped newlines. Is it common for logs to do that?

I don't know if it's common but I try to avoid writing multiline logs to never loose track of the beginning of the line (log level, datetime, etc). And also that's where toolong comes very handy.

I agree to make it optional.

 $ tl --help
Usage: tl [OPTIONS] FILE1 FILE2

  View / tail / search log files.

Options:
  --version              Show the version and exit.
  -m, --merge            Merge files.
 -n, --new-lines         Unescape newline characters in the line panel
  -o, --output-merge PATH  Path to save merged file (requires -m).
  --help

Added this to 1.5.0.

It will automatically unescape newlines. If anyone complains, I might put it behind a switch