# How to logging?

**URL:** https://forum.syncthing.net/t/how-to-logging/215
**Category:** Support
**Created:** [May 21, 2014, 8:02am UTC](https://forum.syncthing.net/t/how-to-logging/215 "2014-05-21T08:02:16Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![jedie](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/j/b5a626/32.png) [@jedie](https://forum.syncthing.net/u/jedie)
#### Post date: [May 21, 2014, 8:02am UTC](https://forum.syncthing.net/t/how-to-logging/215/1 "2014-05-21T08:02:17Z")

</div>

I start syncthing via rc.local, with this:

```
nice -n 19 ionice -c3 su -l syncthing -c "/home/syncthing/bin/syncthing" &

```

But what’s about logging?

I can redirect stdout and stderr into a file, maybe in **/var/log/syncthing** But then, the file will get bigger and bigger, isn’t it?

So i make currently this:

```
nice -n 19 ionice -c3 su -l syncthing -c "/home/syncthing/bin/syncthing" >> "/var/log/syncthing_$(date +"%Y%m")" 2>&1 &

```

So i will get one log file for one month…

Any better idea? Should syncthing implement a own file logging feature with a log-rotate?

---

<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: [May 21, 2014, 9:18am UTC](https://forum.syncthing.net/t/how-to-logging/215/2 "2014-05-21T09:18:53Z")

</div>

You could pipe to `logger` and let whatever syslog system is in place do the rotation.

---

<div class="post-metadata">

### Author: ![jedie](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/j/b5a626/32.png) [@jedie](https://forum.syncthing.net/u/jedie)
#### Post date: [May 21, 2014, 9:45am UTC](https://forum.syncthing.net/t/how-to-logging/215/3 "2014-05-21T09:45:15Z")

</div>

Can you give a example?

---

<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: [May 21, 2014, 12:09pm UTC](https://forum.syncthing.net/t/how-to-logging/215/4 "2014-05-21T12:09:35Z")

</div>

Sure. This is a start script I use with svrun on one of my machines;

```bash
#!/bin/sh

export HOME=/home/jb
export STNORESTART=1
setuidgid jb /home/jb/bin/syncthing 2>&1 | logger -t syncthing

```

When this runs, log output gets sent to regular syslog and can be handled by whatever syslog mechanisms you have in place.

```
jb@syncer:~$ sudo tail -f /var/log/syslog
May 21 14:06:15 syncer syncthing: [LGFPD] 14:06:15 INFO: syncthing v0.8.7-18-ge9eacfa (go1.2.2 linux-amd64) jb@jborg-mbp 2014-05-19 22:59:19 UTC
May 21 14:06:15 syncer syncthing: [LGFPD] 14:06:15 INFO: My ID: LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q
May 21 14:06:15 syncer syncthing: [LGFPD] 14:06:15 INFO: Starting web GUI on http://0.0.0.0:8080/
May 21 14:06:15 syncer syncthing: [LGFPD] 14:06:15 INFO: Populating repository index
May 21 14:06:21 syncer syncthing: [LGFPD] 14:06:21 INFO: No UPnP IGD device found, no port mapping created (read udp4 0.0.0.0:46581: i/o timeout)
May 21 14:06:21 syncer syncthing: [LGFPD] 14:06:21 INFO: Sending local discovery announcements

```

We get a double timestamp, one from syncthing and one from syslog. Could have a flag to disable that in case the log data is timestamped externally but I haven’t been sufficiently annoyed by it yet.

---

<div class="post-metadata">

### Author: ![jedie](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/j/b5a626/32.png) [@jedie](https://forum.syncthing.net/u/jedie)
#### Post date: [May 21, 2014, 12:34pm UTC](https://forum.syncthing.net/t/how-to-logging/215/5 "2014-05-21T12:34:05Z")

</div>

I will try, thanks!

And yes, a flag for no timestamps would be good!

---

<div class="post-metadata">

### Author: ![Hieronymus](https://forum.syncthing.net/user_avatar/forum.syncthing.net/hieronymus/32/460_2.png) [@Hieronymus](https://forum.syncthing.net/u/Hieronymus)
#### Post date: [October 6, 2014, 8:03am UTC](https://forum.syncthing.net/t/how-to-logging/215/6 "2014-10-06T08:03:47Z")

</div>

Hello there and on Windows?

---

<div class="post-metadata">

### Author: ![pszafer](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@pszafer](https://forum.syncthing.net/u/pszafer)
#### Post date: [November 18, 2014, 4:21pm UTC](https://forum.syncthing.net/t/how-to-logging/215/7 "2014-11-18T16:21:56Z")

</div>

Hello, Is there a way to get logger to log only certain information. Syncthing has log level in tags: INFO, OK etc.

do you know if there is a way, to force logger to get only WARNING message etc.

---

<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: [November 18, 2014, 4:44pm UTC](https://forum.syncthing.net/t/how-to-logging/215/8 "2014-11-18T16:44:48Z")

</div>

If you are on unix, you can pipe it through `grep` I guess.

---

<div class="post-metadata">

### Author: ![michaelsidenius](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@michaelsidenius](https://forum.syncthing.net/u/michaelsidenius)
#### Post date: [November 30, 2014, 1:00pm UTC](https://forum.syncthing.net/t/how-to-logging/215/9 "2014-11-30T13:00:07Z")

</div>

Is there a way to pipe to “logger -t syncthing” in a init.d deamon script, that will work correctly both when used with “service start/stop” as well as when syncthing is restarting due to configuration change? I’m on debian (raspberry) and Ubuntu 14.4. Havent been able to make it work so far.

---

<div class="post-metadata">

### Author: ![pszafer](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@pszafer](https://forum.syncthing.net/u/pszafer)
#### Post date: [December 1, 2014, 11:01am UTC](https://forum.syncthing.net/t/how-to-logging/215/10 "2014-12-01T11:01:04Z")

</div>

look at this [https://github.com/jedie/syncthing/wiki/Syncthing-in-Synology-DSM](https://github.com/jedie/syncthing/wiki/Syncthing-in-Synology-DSM)

I’ve achieved this by creating script in middle of start-stop-startus app and syncthing. This way daemon restarts also logger.

---

<div class="post-metadata">

### Author: ![michaelsidenius](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@michaelsidenius](https://forum.syncthing.net/u/michaelsidenius)
#### Post date: [December 2, 2014, 8:12am UTC](https://forum.syncthing.net/t/how-to-logging/215/11 "2014-12-02T08:12:28Z")

</div>

Thanks, I updated the script to my raspberry pi raspian setup, and inserted a missing function (daemon\_status), please see below, this has now been tested both with service start/stop/status, syncthing restart from GUI after config update, syncthing version auto update and rebooting. Hope it will help someone: /etc/init.d script (named “syncthing”):

```
#!/bin/sh 
### BEGIN INIT INFO
# Provides: syncthing
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: daemonized version of syncthing.
# Description: Starts the syncthing daemon for user root
### END INIT INFO

# Package
PACKAGE="syncthing"
DNAME="Syncthing"

# Others
INSTALL_DIR="/usr/local/bin"
PATH="${INSTALL_DIR}:${PATH}"
USER="root"

SYNCTHING="${INSTALL_DIR}/syncthing.sh" 
SYNCTHINGAPP="${INSTALL_DIR}/syncthing"

daemon_status () 
{
   start-stop-daemon --start --test --exec ${SYNCTHINGAPP} >/dev/null 2>&1
    if [$? -eq 0]; then 
        return 1 
    else 
        return 0 
    fi
}

start_daemon ()
{
    start-stop-daemon -b -o -c ${USER} -S -u ${USER} -x ${SYNCTHING} 
}

stop_daemon ()
{
    start-stop-daemon -o -c ${USER} -K -u ${USER} -x ${SYNCTHINGAPP}
}

case $1 in
    start)
        if daemon_status; then
            echo ${DNAME} is already running
        else
            echo Starting ${DNAME} ...
            start_daemon
        fi
        ;;
    stop)
        if daemon_status; then
            echo Stopping ${DNAME} ...
            stop_daemon
        else
            echo ${DNAME} is not running
        fi
        ;;
    status)
        if daemon_status; then
            echo ${DNAME} is running
            exit 0
        else
            echo ${DNAME} is not running
            exit 1
        fi
        ;;
    log)
        exit 1
        ;;
    *)
        exit 1
        ;;
esac

```

I have then created the following helping script to start syncthing and pipe output the the syslog daemon using the “logger” command. Script called “[syncthing.sh](http://syncthing.sh)” placed with syncthing binary:

```
#!/bin/sh
/usr/local/bin/syncthing 2>&1 | logger -t syncthing
```

---

<div class="post-metadata">

### Author: ![system](https://forum-uploads.syncthingcdn.net/original/2X/0/0b50e0a202b22ae6a67190759e8c868805b8ed9f.png) [@system](https://forum.syncthing.net/u/system)
#### Post date: [May 12, 2017, 12:56pm UTC](https://forum.syncthing.net/t/how-to-logging/215/12 "2017-05-12T12:56:22Z")

</div>


