Separate log of a specific application (advice and more)

Is it possible to create a new device for example /dev/log1 where a specific application will write its log without polluting what the classic logread command reports?

the application in question is "ModemManager" which allows you to send the logs to a separate file.

cat /etc/init.d/modemmanager (only modified lines)

LOG_LEVEL="DEBUG"
#LOG_FILE="/dev/null"
#LOG_FILE="/tmp/modemmanager.log"

procd_append_param command --log-level="$LOG_LEVEL" --log-file="$LOG_FILE"
[ "$LOG_LEVEL" = "DEBUG" ] && procd_append_param command --debug --log-file="$LOG_FILE"

Does it have to be a device (perhaps you meant the term differently)?

Can't you just pick a valid folder and select a new file name?

2 Likes

In the Linux tradition, you'd just write to /var/log/<app>.log if you have minimal logging to just one file and /var/log/<app>/<function>.log for more sophisticated requirements (say, for an http server you might have separate access and error logs).

Since /var is by default just a link to /tmp on OpenWrt, I'd just use this to make clear what's going on and be consistent with convention.

LOG_FILE=/var/log/modemmanager.log
1 Like

In the meantime, thank you for the responses

It's true it makes more sense for a file to be created in /var/log

but there is a micro problem (which can be solved with crontab if there are no alternatives) the file would tend to grow without any control, so it occurred to me to take inspiration from:

https://openwrt.org/docs/guide-user/base-system/log.essentials

I quote part of the document of interest to me:
This is implemented as a ring buffer with fixed sized records stored in RAM.

and whether it is possible to allocate a small, closed-loop log like the one managed by logd

as I said alternatively I send the files to /var/log/modemmanager.log and set up a crontab that will empty the file every day (cat /dev/null > /var/log/modemmanager.log)

In the meantime, thanks again for the replies

How about something like

keep_me=$(tail -100 mm.log) && echo "$keep_me" > mm.log

to retain the last 100 lines in the log, just in case. :grin:

1 Like

yes thanks for also finding a solution to keep some previous log lines (thanks) :+1:

unfortunately "ModemManager" in debug mode outputs a lot of information (even too many for my taste) ...

so I have to discard the idea of a "ring buffer" isn't it easy to create it?

Yeah, that's my poor man's attempt at logrotate without adding any packages.

My knowledge here is pretty limited, I don't know of any package that would allow you to implement a ring buffer without writing some code. Maybe someone else has a real solution to this?

1 Like

ok, I hoped it was easy, I'll set the solution you proposed as the solution :+1:

#!/bin/sh
if [ -f /var/log/modemmanager.log ]; then
#cat /dev/null > /var/log/modemmanager.log
tail -100 /var/log/modemmanager > /var/log/modemmanager.log
fi

Heh, better test that first. The redirect first overwrites the file, then tail tries to grab from the empty file, and ...

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.