# Capture log of service from stdout



## soupdiver (Nov 15, 2019)

I'm pretty new to Freebsd, so please excuse me if this question is very basic.
I'm trying to configure a server for my home setup.
I installed `coredns` and enabled it in `/etc/rc.conf`

My issue is that `coredns` only logs to stdout and doesn't support a logfile.
What's the best way to redirect it's output to e.g.  `/var/log/coredns.log`?

I already tried messing around with `> /var/log/coredns.log` in its rc script but was not successfull.
I also tried to add `coredns.* /var/log/coredns.log` in my `/etc/syslog.conf` but am not sure if that's correct.
I'm not sure about the facility(?) of my service!?

If someone can point me in the right direction, that would be great

My `/usr/local/etc/rc.d/coredns`


```
#!/bin/sh

# PROVIDE: coredns
# REQUIRE: DAEMON NETWORKING
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf.local, /etc/rc.conf or
# /etc/rc.conf.d/coredns to enable this service:
#
# coredns_enable (bool):        Set to NO by default.
#                               Set it to "YES" to enable coredns.
# coredns_config (str):         Set to $PREFIX/etc/coredns/Corefile by default.
#                               Path to configuration file.
# coredns_cpu_cap (str):        Set to "100" by default.
#                               CPU cap.
# coredns_listen_port (str):    Set to "53" by default.
#                               Port to bind to.

. /etc/rc.subr

name=coredns
rcvar=coredns_enable
start_precmd="${name}_precmd"

load_rc_config $name

: ${coredns_enable:="NO"}
: ${coredns_config:="/usr/local/etc/coredns/Corefile"}
: ${coredns_cpu_cap:="100"}
: ${coredns_listen_port:="53"}

pidfile="/var/run/${name}.pid"
command="/usr/sbin/daemon"
procname="/usr/local/bin/${name}"
coredns_args="-conf ${coredns_config} -dns.port ${coredns_listen_port}"
command_args="-S -m 3 -s "info" -l "daemon" -p ${pidfile} /usr/bin/env ${procname} ${coredns_args}"

coredns_precmd()
{
    /usr/bin/install -d -m 0755 \
            /usr/local/etc/coredns
}
echo $command$command_args
run_rc_command "$1"
```


----------

