Parse::Syslog - Parse Unix syslog files my $parser = Parse::Syslog->new('/var/log/syslog', year=>2001); while(my $sl = $parser->next) { ... access $sl->{timestamp|host|program|pid|text} ... } Unix syslogs are convenient to read for humans but because of small differences between operating systems and things like 'last message repeated xx times' not very easy to parse by a script. Parse::Syslog presents a simple interface to parse syslog files: you create a parser on a file (with new) and call next to get one line at a time with Unix-timestamp, host, program, pid and text returned in a hash-reference.

Constructing a Parser
new requires as first argument a file-name for the syslog-file to be parsed. Alternatively, you can pass a File::Tail object as first argument, in which case the read method will be called to get lines to process. After the file-name (or File::Tail object), you can specify options as a hash. The following options are defined: Syslog files usually do store the time of the event without year. With this option you can specify the start-year of this log. If not specified, it will be set to the current year. If this option is set, the time in the syslog will be converted assuming it is GMT time instead of local time. Parse::Syslog will by default repeat xx times events that are followed by messages like 'last message repeated xx times'. If you set this option to false, it won't do that. If this option is true, next will return an array-ref instead of a hash-ref (and is thus a bit faster), with the following contents: timestamp host program pid text

Parsing the file
The file is parse one line at a time by calling the next method, which returns a hash-reference containing the following keys: Unix timestamp for the event. Host-name where the event did happen. Program-name of the program that generated the event. PID of the Program that generated the event. This information is not always available for every operating system. Text description of the event. Message numeric identifier, available only on Solaris >= 8 with "message ID generation" enabled". Log facility name, available only on Solaris >= 8 with "message ID generation" enabled". Log level, available only on Solaris >= 8 with "message ID generation" enabled".

BUGS
There are many small differences in the syslog syntax between operating systems. This module has been tested for syslog files produced by the following operating systems: Debian GNU/Linux 2.4 (sid) Solaris 2.6 Solaris 8 Report problems for these and other operating systems to the author. Copyright (c) 2001, Swiss Federal Institute of Technology, Zurich. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. David Schweikert <dws@ee.ethz.ch> 2001-08-12 ds 0.01 first version 2001-08-19 ds 0.02 fix 'last message repeated xx times', Solaris 8 problems 2001-08-20 ds 0.03 implemented GMT option, year specification, File::Tail 2001-10-31 ds 0.04 faster time parsing, implemented 'arrayref' option, better time-increment algorithm