logger

From RaySoft

logger is a shell command interface to the syslog system log module.[1]

Documentation

Syntax

logger [PARAMETER ...] [MESSAGE ...]

Parameters

-p PRIORITY
Enter the message with the specified PRIORITY. The priority may be specified numerically or as a facility.level pair. For example, -p local3.info logs the message(s) as informational level in the local3 facility. The default is user.notice.
-s
Log the message to standard error, as well as the system log.
-t TAG
Mark every line in the log with the specified TAG.

Examples

Write a warning in /var/log/messages

Make sure your syslog daemon listen to the facility and level you have chosen. This example is based on syslogd, which stores its configuration in /etc/syslog.conf. The highlighted section already covers the needs:

# Log all kernel messages to the console.
# Logging much else clutters up the screen. 
#kern.*           /dev/console

# Log anything (except mail) of level info or higher. 
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none   /var/log/messages

# The authpriv file has restricted access. 
authpriv.*       /var/log/secure

# Log all the mail messages in one place.
mail.*           -/var/log/maillog


# Log cron stuff
cron.*           /var/log/cron

# Everybody gets emergency messages
*.emerg          *        

# Save news errors of level crit and higher in a special file.
uucp,news.crit   /var/log/spooler

# Save boot messages also to boot.log
local7.*         /var/log/boot.log

Restart the syslogd daemon if you changed its configuration:

/etc/init.t/syslogd restart

Execute the following script. Important is the highlighted line:

if [[ false ]]; then
   logger -t 'TEST' -p 'local1.warning' -s -- 'Test logger'
fi

In the /var/log/messages the following line is written:

Dec 23 13:26:59 neon TEST: Test logger

References

  1. man 1 'logger'