Shell How to feed a log file into syslog?

Say I have written a service that logs to /usr/local/opt/my_service/log/my_service.log. My understanding is that I can use newsyslog(8) to rotate the log. How can I feed the log file into syslog? Can logger(1) be used to do this?

Ideally I am looking for a solution that will pass new logging events to syslog in real time. I also need the solution stay in place when the system reboots.
 
And yes, you can replace writes to a log file with calls to logger(1), e.g.
Code:
/usr/bin/logger -p user.notice -t somelabel -- "your log text"
Pick a facility (like user.notice here) to push log lines into an existing log file (here /var/log/messages), or use one of the undefined ones (local.*) to create your own log file location using syslog.conf(5). And use newsyslog(8) to rotate those out of the way.
 
  • Thanks
Reactions: Oko
I have a server that writes to a log file. I want to feed live changes to this log file into syslog.

The following line feeds a file into syslog:
Code:
logger -f /path/to/my/server.log

The problem is that the above line feeds the whole file into syslog every time it is run.
I want to feed lines into syslog as they are appended to the file.
Is there a good way to do this?

EDIT:
The following line works.
Code:
tail -F /path/to/my/server.log | logger
Is there an existing utility that can be used to start feeding log files into syslog when the system boots?
If not, what is the "best" way to configure this?
 
I don't think this is a correct approach. Some applications allow you to choose where to log, it can be a file but it can also log directly to syslog. But that depends on the application. Apache for example logs directly to a file by default but can be configured to log to syslogd(8). But even if Apache is configured to log to a file you can still use newsyslog(8) to rotate the logs.
 
I am writing an application. When I asked about syslog packages for my technology of choice, I was advised not to use any of the them. The advice I received was to write to a log file and have syslog ingest the file. Does logging to syslog strike you as the correct approach? (Or offer both options like Apache.)
 
FWIW, I think that logging to syslog is the "correct" way to do it. Choices and options are always good - support them if you can.
 
Agreed. I like how Zabbix works for example. If you specify a log file it will use that, if you specify nothing it'll log to syslog.
 
Back
Top