| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Debconf::Log - debconf log module |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
package Debconf::Log; |
| 10 |
use warnings; |
| 11 |
use strict; |
| 12 |
use base qw(Exporter); |
| 13 |
our @EXPORT_OK=qw(debug warn); |
| 14 |
our %EXPORT_TAGS = (all => [@EXPORT_OK]); # Import :all to get everything. |
| 15 |
require Debconf::Config; # not use; there are recursive use loops |
| 16 |
|
| 17 |
=head1 DESCRIPTION |
| 18 |
|
| 19 |
This is a log module for debconf. |
| 20 |
|
| 21 |
This module uses Exporter. |
| 22 |
|
| 23 |
=head1 METHODS |
| 24 |
|
| 25 |
=over 4 |
| 26 |
|
| 27 |
=item debug |
| 28 |
|
| 29 |
Outputs an infomational message. The first parameter specifies the type of |
| 30 |
information that is being logged. If the user has specified a debug or log |
| 31 |
setting that matches the parameter, the message is output and/or logged. |
| 32 |
|
| 33 |
Currently used types of information: user, developer, debug, db |
| 34 |
|
| 35 |
=cut |
| 36 |
|
| 37 |
my $log_open=0; |
| 38 |
sub debug { |
| 39 |
my $type=shift; |
| 40 |
|
| 41 |
my $debug=Debconf::Config->debug; |
| 42 |
if ($debug && $type =~ /$debug/) { |
| 43 |
print STDERR "debconf ($type): ".join(" ", @_)."\n"; |
| 44 |
} |
| 45 |
|
| 46 |
my $log=Debconf::Config->log; |
| 47 |
if ($log && $type =~ /$log/) { |
| 48 |
require Sys::Syslog; |
| 49 |
unless ($log_open) { |
| 50 |
Sys::Syslog::setlogsock('unix'); |
| 51 |
Sys::Syslog::openlog('debconf', '', 'user'); |
| 52 |
$log_open=1; |
| 53 |
} |
| 54 |
eval { # ignore all exceptions this throws |
| 55 |
Sys::Syslog::syslog('debug', "($type): ". |
| 56 |
join(" ", @_)); |
| 57 |
}; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
=item warn |
| 62 |
|
| 63 |
Outputs a warning message. This overrides the builtin perl warn() command. |
| 64 |
|
| 65 |
=cut |
| 66 |
|
| 67 |
sub warn { |
| 68 |
print STDERR "debconf: ".join(" ", @_)."\n" |
| 69 |
unless Debconf::Config->nowarnings eq 'yes'; |
| 70 |
} |
| 71 |
|
| 72 |
=back |
| 73 |
|
| 74 |
=head1 AUTHOR |
| 75 |
|
| 76 |
Joey Hess <[email protected]> |
| 77 |
|
| 78 |
=cut |
| 79 |
|
| 80 |
1 |