David Parks
David Parks

Reputation: 32081

Howto: Using syslog for user created shell script

Information abound about syslog, but I can't find anything very concise for my interest.

I have a user-created bash script that should log various debug, info, and error messages. I'd like to use syslog. This in Ubuntu Server distribution.

I'm looking for a quick overview only.

With those questions answered I should be able to glean the details from the man pages.

Upvotes: 6

Views: 7500

Answers (2)

sorpigal
sorpigal

Reputation: 26096

You want the logger(1) utility, available in the bsdutils package.

From the man page:

     logger - a shell command interface to the syslog(3) system log module

There's nothing that's essential to configure, just pass the switches you want. E.g.

logger -p local3.info -t myprogram "What's up, doc?"

You can now inspect wherever local3.info messages go and you will see something like this:

Jul 11 12:46:35 hostname myprogram: What's up, doc?

You only need to worry about logrotate if you need something fancier than this.

As for what log facility to use, I would use daemon for daemon messages and local for most other things. You should consult syslog(3) for the purposes of the different facilities.

Upvotes: 10

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799150

  • Don't worry about logrotate. It doesn't affect you if you're logging to the system log.
  • You can use any facility you like. See the syslogd configuration for what ends up where.
  • See the syslogd configuration for what ends up where.
  • See the... yeah, you get it.

Upvotes: 1

Related Questions