0

I want to use the logger command in order to write logs to /var/log/server.log

NOTE: These examples use the FreeBSD version of logger. Your system may have different options, so read your local documentation!

logger -p INFO -f /var/log/server.log -t MY_LOG_TAG "server is up"

This suppose to send the message to be logged in /var/log/server.log with the info, It includes a tag (-t MY_LOG_TAG), which is included in each line.

but the syntax with the logger not append the log to /var/log/server.log

please advice what is wring with the logger syntax ?

second is it possible to add the date in the log line ?

expected output

Wed Mar 6 18:16:54 UTC 2019 INFO server is up
3

You have misunderstood the -f option.

From the FreeBSD logger(1) manual:

-f file

Read the contents of the specified file into syslog. This option is ignored when a message is also specified.

The logger utility will send the message to the syslog service (by default on the local machine) and depending on its configuration and the priority/tag of the message, it will be appended to one or several log files. You can't log to a specific log file without configuring syslog to treat your log messages specially.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.