]> mj.ucw.cz Git - pciids.git/blob - PciIds/Log.pm
Output better path
[pciids.git] / PciIds / Log.pm
1 package PciIds::Log;
2 use strict;
3 use warnings;
4 use base 'Exporter';
5 use PciIds::Config;
6
7 our @EXPORT = qw(&flog &tlog &logEscape &tulog);
8
9 checkConf( [ 'logfile' ] );
10
11 sub flog( $ ) {
12         my( $text ) = @_;
13         open LOG, '>>'.$config{'logfile'} or die "Could not open log file\n";
14         print LOG "$text\n";
15         close LOG;
16 }
17
18 sub tlog( $ ) {
19         my( $text ) = @_;
20         my $time = time;
21         flog( "$time: $text" );
22 }
23
24 sub tulog( $$ ) {
25         my( $user, $text ) = @_;
26         tlog( "User $user: $text" );
27 }
28
29 sub logEscape( $ ) {
30         my( $text ) = @_;
31         return "''" unless defined $text;
32         $text =~ s/(['"\\])/\\$1/g;
33         return "'$text'";
34 }
35
36 1;