# # logger writes a string to the system log file.
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2003/12/13 logger

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© December 2003 Tony Lawrence

Writes a string to the system log file.

An ordinary user can run this without read or write permission on the system log file. It simply adds a date stamp, your login name, and whatever arguments you gave it:


$ logger fooey
$ tail -1 /var/log/system.log
Dec 12 08:35:03 localhost apl: fooey
 

There are more possibilities: you can specify a priority level, and that could cause your message to go to some other system log depending on the configuration of syslog:

 apl$ sudo cat /etc/syslog.conf
*.err;kern.*;auth.notice;authpriv,remoteauth,install.none;mail.crit            /dev/console
*.notice;*.info;authpriv,remoteauth,ftp,install.none;kern.debug;mail.crit      /var/log/system.log

authpriv.*;remoteauth.crit                              /var/log/secure.log

lpr.info                                                /var/log/lpr.log
mail.*                                                  /var/log/mail.log
ftp.*                                                   /var/log/ftp.log
netinfo.err                                             /var/log/netinfo.log
install.*                                               /var/log/install.log
install.*                                               @127.0.0.1:32376

*.emerg                                                 *
 apl$ logger -p lpr.info try this
 apl$ tail -1 /var/log/system.log
Dec 12 08:40:46 localhost apl: try this
 apl$ tail -1 /var/log/lpr.log   
Dec 12 08:40:46 localhost apl: try this
 

See also Log Level

If you found something useful today, please consider a small donation.



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> logger writes a string to the system log file.


Inexpensive and informative Apple related e-books:

Take Control of Preview

El Capitan: A Take Control Crash Course

Photos for Mac: A Take Control Crash Course

iOS 10: A Take Control Crash Course

Take Control of iCloud, Fifth Edition





More Articles by © Tony Lawrence



And of course you can use PERL to log events to your syslog, with Sys::Syslog - which can be done like this:

-----BEGIN script
#!/usr/bin/perl -w
# Script to log HOT to /var/log/messages if the temp
# id higher than the varibale set below in $temp
#
# Requires: Device-Serial per module.
# Requires: Sys::Syslog

use Device::SerialPort 0.05;
use Sys::Syslog qw(:DEFAULT setlogsock);
use strict;

my $Temptrax = "/dev/ttyE4";
my $pass;
my $return;
my $new;
my $HOT;
my $time;
my $bldg;
my $room;


$time = localtime;


################################
# BEGIN Variable Configuration #
################################

# $temp is the max or min temp before we start YELLING!
my $temp = "76";

# $bldg is the building where the Temptrax is located
$bldg = "164 Fredette St.";

# $room is the Room in which the Temptrax is located
$room = "Computer Room";

##############################
# END Variable Configuration #
##############################

# Constructor & Basic Values

my $ob = Device::SerialPort->new ($Temptrax) || die "Can't open $Temptrax:$!";

$ob->baudrate (9600) || die "fail setting baudrate";
$ob->parity ("none") || die "fail setting parity";
$ob->databits (8) || die "fail setting databits";
$ob->stopbits (1) || die "fail setting stopbits";
$ob->handshake ("none") || die "fail setting handshake";
$ob->dtr_active (1) || die "fail setting dtr_active";

$ob->write_settings || die "no settings";

sleep 1;

#send a dummy character to the TempTrax device to "wake it up"
#The temperature will be returned

$pass = $ob->write("a") or die ("Could not write to Temptrax: $!");

sleep 1;

if (($return = $ob->input) ne "") {
$ob->write($return);
$new = substr($return, -15) = "";
if ($return > $temp) {

# use perl syslog facility
my $count = 0;
my $host = "localhost";
setlogsock("unix");
openlog(basename($0), "pid", "local3");
syslog("warning", "COMPUTER ROOM: ** HOT **: $return");
closelog();

}
}
---------END script

I use that program from cron to query a temperature probe that is located in our computer room. I then use swatch to look for the word HOT and page me. The temperature probe hardware can be found here: http://www.temptrax.com I use the RS-232 version.

- Bruce Garlock

---------------------

Aso, don't forget that most UNIX systems listen on UDP port 514 and write whatever shows up there into syslog. I often use this feature to monitor HP JetDirect print servers when something is acting up.

--BigDumbDinosaur





Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us


Printer Friendly Version





The only thing I'd rather own than Windows is English. Then I'd be able to charge you an upgrade fee every time I add new letters like N and T. (Scott McNealy)




Linux posts

Troubleshooting posts


This post tagged:

Scripting

Shell

UnixWords



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode