# gzip audit-logs

**URL:** https://forum.syncthing.net/t/gzip-audit-logs/16949
**Category:** Feature
**Created:** [June 13, 2021, 4:46pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949 "2021-06-13T16:46:28Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![opensource21](https://forum.syncthing.net/user_avatar/forum.syncthing.net/opensource21/32/9958_2.png) [@opensource21](https://forum.syncthing.net/u/opensource21)
#### Post date: [June 13, 2021, 4:46pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/1 "2021-06-13T16:46:28Z")

</div>

I’m running syncthing with `--audit`. I would appreciate if old auditlogs would be gzipped and every day a new file will be used.

---

<div class="post-metadata">

### Author: ![AudriusButkevicius](https://forum.syncthing.net/user_avatar/forum.syncthing.net/audriusbutkevicius/32/277_2.png) [@AudriusButkevicius](https://forum.syncthing.net/u/AudriusButkevicius)
#### Post date: [June 13, 2021, 6:14pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/2 "2021-06-13T18:14:49Z")

</div>

Best I can Suggest is to set it up to log to stdout/stderr, and use standard rotation, or some log management systems, support setting up a pipe/named socket for an application to write to, which then then do rotation etc.

We have ways to do log rotation, which could be reused here, but I don’t think we’ll do gzipping etc.

---

<div class="post-metadata">

### Author: ![opensource21](https://forum.syncthing.net/user_avatar/forum.syncthing.net/opensource21/32/9958_2.png) [@opensource21](https://forum.syncthing.net/u/opensource21)
#### Post date: [June 15, 2021, 1:25pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/3 "2021-06-15T13:25:24Z")

</div>

Sorry, but I don’t understand your suggestions. The audit-log always wrote to a file as far as I know. Furtermore the name is unpredictable (contains the start time). So tools like newsyslog and logrotate doesn’t work. I only see the possibilities that the logik is implemented in syncthing or that syncthing always write to a file audit.log. Then logrotate can do the job.

---

<div class="post-metadata">

### Author: ![bt90](https://forum.syncthing.net/user_avatar/forum.syncthing.net/bt90/32/18565_2.png) [@bt90](https://forum.syncthing.net/u/bt90)
#### Post date: [June 15, 2021, 1:30pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/4 "2021-06-15T13:30:21Z")

</div>

> [@opensource21](#):
>
> Furtermore the name is unpredictable (contains the start time).

Logrotate allows wildcards AFAIK.

---

<div class="post-metadata">

### Author: ![Alex](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@Alex](https://forum.syncthing.net/u/Alex)
#### Post date: [June 15, 2021, 1:31pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/5 "2021-06-15T13:31:30Z")

</div>

you can specify the file it writes to:

```
--auditfile=PATH Specify audit file (use "-" for stdout, "--" for stderr)

```

---

<div class="post-metadata">

### Author: ![AudriusButkevicius](https://forum.syncthing.net/user_avatar/forum.syncthing.net/audriusbutkevicius/32/277_2.png) [@AudriusButkevicius](https://forum.syncthing.net/u/AudriusButkevicius)
#### Post date: [June 15, 2021, 1:45pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/6 "2021-06-15T13:45:29Z")

</div>

For log rotate to work, we’d need to periodically reopen the file, which we don’t do.

I know some logging daemons expose a named pipe you can write to, which then does log rotation on stuff read from the pipe.

---

<div class="post-metadata">

### Author: ![opensource21](https://forum.syncthing.net/user_avatar/forum.syncthing.net/opensource21/32/9958_2.png) [@opensource21](https://forum.syncthing.net/u/opensource21)
#### Post date: [June 15, 2021, 5:38pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/7 "2021-06-15T17:38:54Z")

</div>

> [@AudriusButkevicius](#):
>
> For log rotate to work, we’d need to periodically reopen the file, which we don’t do.

Does this mean if I set the audit-file to audit.log and then newlogsystem bzip to autit.0.log. The audit-log will become broken?

What logging deamons you have in mind?

---

<div class="post-metadata">

### Author: ![AudriusButkevicius](https://forum.syncthing.net/user_avatar/forum.syncthing.net/audriusbutkevicius/32/277_2.png) [@AudriusButkevicius](https://forum.syncthing.net/u/AudriusButkevicius)
#### Post date: [June 15, 2021, 5:46pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/8 "2021-06-15T17:46:53Z")

</div>

> [@opensource21](#):
>
> Does this mean if I set the audit-file to audit.log and then newlogsystem bzip to autit.0.log. The audit-log will become broken?

I believe so, because we will keep writing to a file descriptor that doesn’t exist on the filesystem anymore, because you’ve archived the file and deleted it.

> [@opensource21](#):
>
> What logging deamons you have in mind?

I can’t tell you a specific one, I just recall seeing something like that before.

Effectively what I am talking about is something like example 2 shown here:

> **[How to build Linux logging bash shell script write\_log, logging with Named...](https://www.pc-freak.net/blog/build-linux-logging-bash-shell-script-buffer-named-pipes-simple-linux-logging-logger-command/)**
>
> Logging into file in GNU / Linux and FreeBSD is as simple as simply redirecting the output, e.g.:   echo "$(date) Whatever" \>\> /home/hipo/log/output\_file\_log.txt or with pyping to tee command   echo "$(date) Service has Crashed" | tee...

You point syncthing to write audit logs to the named pipe (which I think should work), wand then your script that reads off of that named pipe decides what to do with the logs, when to roll a new file, archive it etc.

---

<div class="post-metadata">

### Author: ![bt90](https://forum.syncthing.net/user_avatar/forum.syncthing.net/bt90/32/18565_2.png) [@bt90](https://forum.syncthing.net/u/bt90)
#### Post date: [June 15, 2021, 5:48pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/9 "2021-06-15T17:48:25Z")

</div>

Would `copytruncate` not work?

---

<div class="post-metadata">

### Author: ![AudriusButkevicius](https://forum.syncthing.net/user_avatar/forum.syncthing.net/audriusbutkevicius/32/277_2.png) [@AudriusButkevicius](https://forum.syncthing.net/u/AudriusButkevicius)
#### Post date: [June 15, 2021, 5:50pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/10 "2021-06-15T17:50:48Z")

</div>

Good question/point, maybe it would.

---

<div class="post-metadata">

### Author: ![opensource21](https://forum.syncthing.net/user_avatar/forum.syncthing.net/opensource21/32/9958_2.png) [@opensource21](https://forum.syncthing.net/u/opensource21)
#### Post date: [June 15, 2021, 6:19pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/11 "2021-06-15T18:19:34Z")

</div>

> [@bt90](#):
>
> `copytruncate`

that seems in deed an option. So I can write in a fix file. Run a job, that copy it to another file and truncate the original one. The new file can then rotate with newsyslog which is the default at mac. Must think about it. Perhaps it’s easier to stop syncthing. gzip the log and restart it.

Thanks for all the input. In java this is normally only a thing of a few configurations.

---

<div class="post-metadata">

### Author: ![opensource21](https://forum.syncthing.net/user_avatar/forum.syncthing.net/opensource21/32/9958_2.png) [@opensource21](https://forum.syncthing.net/u/opensource21)
#### Post date: [June 15, 2021, 7:25pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/12 "2021-06-15T19:25:47Z")

</div>

Interesting note: There seems some code in sycnthing which deletes old audit-logs 😉

---

<div class="post-metadata">

### Author: ![calmh](https://forum.syncthing.net/user_avatar/forum.syncthing.net/calmh/32/15311_2.png) [@calmh](https://forum.syncthing.net/u/calmh)
#### Post date: [June 16, 2021, 4:47am UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/13 "2021-06-16T04:47:57Z")

</div>

Yep:

> <https://github.com/syncthing/syncthing/blob/89740490acc61e052447698c553fd8239c4f3313/cmd/syncthing/main.go#L936-L948>

(on startup)

---

<div class="post-metadata">

### Author: ![opensource21](https://forum.syncthing.net/user_avatar/forum.syncthing.net/opensource21/32/9958_2.png) [@opensource21](https://forum.syncthing.net/u/opensource21)
#### Post date: [July 10, 2021, 7:46pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/14 "2021-07-10T19:46:04Z")

</div>

Is it possible to stop the syncthing-process at the mac-os-version from commandline? The idea is to regulary stop syncthing gzip the audit-log and then restart the service. I tried to do it with the REST-Api and curl, but the mac-os-version restart it immediatly. One idea is to gzip everything and then shutdown. But it’s not really clean.

---

<div class="post-metadata">

### Author: ![calmh](https://forum.syncthing.net/user_avatar/forum.syncthing.net/calmh/32/15311_2.png) [@calmh](https://forum.syncthing.net/u/calmh)
#### Post date: [July 10, 2021, 8:01pm UTC](https://forum.syncthing.net/t/gzip-audit-logs/16949/15 "2021-07-10T20:01:39Z")

</div>

Probably the service manager restarts Syncthing as soon as it exits. This is fine though; restart Syncthing so it creates a new audit log, then gzip the old audit log.
