Re: [systemd-devel] Append to logfile with year-month

2023-08-25 Thread Lennart Poettering
On Do, 24.08.23 09:48, Cecil Westerhof (cldwester...@gmail.com) wrote:

> In a service file I can use:
> StandardOutput=append:/var/log/root/aptCacheUsage.log
>
> but I want to use something like:
> StandardOutput=append:/var/log/root/aptCacheUsage_$(date +%%Y-%%m).log
>
> Did does not work, because this puts it in:
> /var/log/root/aptCacheUsage_$(date +%Y-%m).log
>
> Is there a way I can put it in:
> /var/log/root/aptCacheUsage_2023-08.log
>
> while it would automatically next month go into:
>/var/log/root/aptCacheUsage_2023-09.log
>
> I could of-course put it into:
> /var/log/root/aptCacheUsage.log
>
> and at the beginning of the month move it if it exists with a timed
> service, but I really would not like that kind of solution.

We do not support this. systemd supports evaluating some specifiers,
but time/date is not one of them, in particular as we resolve
specifiers at parse time of the unit only, not afterwards. or in other
words: we'd resolve the specifiers early at boot, and that doesn't
look like what you want.

Also, for long-running services this wouldn#t work anyway, as we can't
rotate files like that, because we cannot externally close the current
stdout of a process and replace it with a new file.

hence, what you are trying to do is not supported, and is unlikely to
ever be supported for multiple reasons.

sorry!

Lennart

--
Lennart Poettering, Berlin


Re: [systemd-devel] Append to logfile with year-month

2023-08-24 Thread Donald Buczek
Consider the ugly

ExecStart=bash -c "whatever > /var/log/root/aptCacheUsage_$(date +%%Y-%%m).log 
2>&1"

or

ExecStart=bash -c "whatever | cronolog /var/log/root/aptCacheUsage_%%Y-%%m.log 
2>&1"

Best
  Donald


On 8/24/23 9:48 AM, Cecil Westerhof wrote:
> In a service file I can use:
>     StandardOutput=append:/var/log/root/aptCacheUsage.log
> 
> but I want to use something like:
>     StandardOutput=append:/var/log/root/aptCacheUsage_$(date +%%Y-%%m).log
> 
> Did does not work, because this puts it in:
>     /var/log/root/aptCacheUsage_$(date +%Y-%m).log
> 
> Is there a way I can put it in:
>     /var/log/root/aptCacheUsage_2023-08.log
> 
> while it would automatically next month go into:
>    /var/log/root/aptCacheUsage_2023-09.log
> 
> I could of-course put it into:
>     /var/log/root/aptCacheUsage.log
> 
> and at the beginning of the month move it if it exists with a timed service, 
> but I really would not like that kind of solution.
> 
> -- 
> Cecil Westerhof


-- 
Donald Buczek
buc...@molgen.mpg.de
Tel: +49 30 8413 1433


Re: [systemd-devel] Append to logfile with year-month

2023-08-24 Thread Mantas Mikulėnas
On Thu, Aug 24, 2023 at 10:49 AM Cecil Westerhof 
wrote:

> In a service file I can use:
> StandardOutput=append:/var/log/root/aptCacheUsage.log
>
> but I want to use something like:
> StandardOutput=append:/var/log/root/aptCacheUsage_$(date +%%Y-%%m).log
>
> Did does not work, because this puts it in:
> /var/log/root/aptCacheUsage_$(date +%Y-%m).log
>
> Is there a way I can put it in:
> /var/log/root/aptCacheUsage_2023-08.log
>
> while it would automatically next month go into:
>/var/log/root/aptCacheUsage_2023-09.log
>
>
Not with built-in systemd tools. If it's a periodic (not permanently
running) service, best you can do is script a monthly cronjob that
automatically edits the StandardOutput line in your .service unit.


> I could of-course put it into:
> /var/log/root/aptCacheUsage.log
>
> and at the beginning of the month move it if it exists with a timed
> service, but I really would not like that kind of solution.
>

It's called /etc/logrotate.conf and it's what everyone else does. It's what
Debian/Ubuntu itself uses for /var/log/apt*.log and such.

-- 
Mantas Mikulėnas


[systemd-devel] Append to logfile with year-month

2023-08-24 Thread Cecil Westerhof
In a service file I can use:
StandardOutput=append:/var/log/root/aptCacheUsage.log

but I want to use something like:
StandardOutput=append:/var/log/root/aptCacheUsage_$(date +%%Y-%%m).log

Did does not work, because this puts it in:
/var/log/root/aptCacheUsage_$(date +%Y-%m).log

Is there a way I can put it in:
/var/log/root/aptCacheUsage_2023-08.log

while it would automatically next month go into:
   /var/log/root/aptCacheUsage_2023-09.log

I could of-course put it into:
/var/log/root/aptCacheUsage.log

and at the beginning of the month move it if it exists with a timed
service, but I really would not like that kind of solution.

-- 
Cecil Westerhof