NAME
SeeAlso::Logger - log requests to a SeeAlso Simple service
VERSION
version 0.71
DESCRIPTION
This class provides the log method to log successful requests to a SeeAlso Simple service. You can write logs to a file and/or handle them by a filter method.
USAGE
To log requests to your SeeAlso services, create a logfile directory that is writeable for the user your services runs as. If you run SeeAlso as cgi-script, this script may help you to find out:
#!/usr/bin/perl
print "Content-Type: text/plain;\n\n" . `whoami`;
Create a SeeAlso::Logger object with a filename of your choice and assign it to the SeeAlso::Server object:
my $logger = SeeAlso::Logger->new("/var/log/seealso/seealso.log");
$server->logger($logger);
To rotate logfiles you should use logrotate which is part of every linux distribution. Specify the configuration for your seealso logfiles in a configuration file where logrotate can find in (/etc/logrotate.d/seealso).
# example logrotate configuration for SeeAlso
/var/log/seealso/*.log {
compress
daily
dateext
ifempty
missingok
rotate 365
}
The constructor of this class does not throw an error if the file you specified for logging could not be opened. Instead test the 'handle' property whether it is defined.
METHODS
new ( [ $file-or-handle ] {, $option => $value } )
Create a new parser. Gets a a reference to a file handle or a file name or a handler function. You can specify the following options:
- file
-
Filename or reference to a file handle. If you give a file name, it will immediately be opened (this may throw an error).
- filter
-
Reference to a filter method. The methods gets an array (datetime, host, referer, service, id, valid, size) for each log event and is expected to return an array of same size. If the filter method returns undef, the log message will not be written to the log file.
Here is an example of a filter method that removes the query part of each referer:
my $logger = SeeAlso::Logger->new( file => "/var/log/seealso/seealso.log", filter => sub { $_[1] =~ s/\?.*$//; @_; } } );
- privacy
-
Do not log remote host (remote host is always '-'). To also hide the referer, use a filter method.
set_file ( $file-or-handle )
Set the file handler or file name or function to log to. If you specify a filename, the filename property of this object is set. Returns the file handle on success.
log ( $cgi, $response, $service )
Log a request and response. The response must be a SeeAlso::Response object, the service is string. Each logging event is a line of tabulator seperated values. Returns true if something was logged.
- datetime
-
An ISO 8601 timestamp (YYYY-MM-DDTHH:MM:SS).
- host
-
The remote host (usually an IP address) unless privacy is enabled.
- referer
-
HTTP Referer.
- service
-
Name of a service.
- id
-
The requested search term (CGI parameter 'id')
- valid
-
Whether the search term was a valid identifier (1) or not (0). This will only give meaningful values of your query method does not put invalid identifiers in the response.
- size
-
Number of entries in the response content
ADDITIONAL FUNCTIONS
parse ( $line )
Parses a line of of seven tabulator seperated values. The first value must be a ISO 8601 timestamp. as
AUTHOR
Jakob Voss
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Jakob Voss.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.