reddit / emacs

Reading remote docker logs with highlighting

LinkHimself · 2022-08-09 09:40
My workflow is such that I use tramp-term to connect to a server with running docker containers and sometimes I want to read the logs, preferably with highlighting. What is a good way to do this? The logs can be fairly large \~35MB and I need to search through all of it for debug purposes. I have tried logview-mode and log4j-mode, but it seems they can't deal with the log output of docker. Or maybe I haven't configured correctly?
7890yuiop · 2022-08-09 12:23
The `docker-tramp` package will let you visit files in docker containers. As for highlighting I've no idea, and don't imagine anyone else will without an example. What are they logs *for*, and what do they look like?
LinkHimself · 2022-08-09 13:53
Ah sorry, I phrased it badly. Here is an example of an info level:`time=2022-08-08T00:00:00,002 thread=pool-4-thread-1 level=INFO x_app= requestId= user_id= requesting_user_id= session_id= logger=x.x.events.EventService marker= publishing event with eventId=x-x-x-x-x and path=job/CheckRundeckJobStatusJob/start to 1/1 subscribers` Looks like what I see from java applications. Strange that logview-mode and log4j-mode didn't work for me.
by_wicker · 2022-08-09 14:08
For a quick and simplistic option, I use `(highlight-regexp)` on calls to `shell-command`. I already had an advising function on `shell-command`, so I added some regex highlighting, some of which is conditional on contents of the shell command. e.g.: (when (string-match "journalctl" command) (with-current-buffer output-buffer (highlight-regexp ....)))
7890yuiop · 2022-08-09 14:13
`M-x customize-group RET logview` then?
LinkHimself · 2022-08-10 07:56
Thanks, I will look into it.
LinkHimself · 2022-08-10 07:58
I'm not familiar with shell-command, when does it trigger? I'm not sure if I understood.
by_wicker · 2022-08-10 14:31
Pretty much any time you run a command in a buffer it's using `shell-command`. By default bound to `M-!`. If you run a command asynchronously (`M-&`, `async-shell-command`) it is just a wrapper to call `shell-command` slightly differently. So if you run a logging command into a buffer, you'll probably be doing it through `shell-command`.