File: Log.pm

package info (click to toggle)
libxtm-perl 0.29-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 388 kB
  • ctags: 179
  • sloc: perl: 2,759; makefile: 37
file content (145 lines) | stat: -rw-r--r-- 2,411 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package XTM::Log;

use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

require Exporter;
require AutoLoader;

@ISA = qw(Exporter AutoLoader);
@EXPORT = qw();
@EXPORT_OK = qw( flog elog);
$VERSION = '0.01';

use vars qw($logfile $loglevel);

$logfile  = 'xtmd.log';
$loglevel = 1;

=pod

=head1 NAME

XTM::Log - Topic Map Logger

=head1 SYNOPSIS

  use XTM::Log;

=head1 DESCRIPTION

This package provides some logging facilities for the XTM::* packages. Basically,
it provides STDERR and file based logging.

=head1 INTERFACE

=head2 Global Variables

Following variables can be set to control the behavior of this package:

=over

=item C<logfile> (xtmd.log)

=item C<loglevel> (1)

=back

=head1 Methods

=over

=item I<flog>

provides some basic file logging facilities. Please refer to the global variables for configuration.
It logs messages to the current C<logfile> whenever called
and the passed loglevel is at least the minimum (as configured via the global variable C<loglevel>).
Parameters are:

=over

=item C<entity>

Here you can provide some descriptive text of the module logging.

=item C<loglevel>

current loglevel

=back

Any additional parameters are copied (for SCALARs) or output via Data::Dumper::Dumper.

Example:

   flog ('MyProgram', 4, 'Logging a line', $line, \%context);

=cut

use POSIX qw(strftime);

use File::Slurp;
sub flog {
  my $entity = shift;
  my $level  = shift || 1;
  my @msgs   = @_;
  unless ($level > $loglevel) {
    append_file($logfile, (strftime "%Y %a %b %e %H:%M:%S", localtime)." - $entity($level): ".
		(@msgs ? join (" ", @msgs) : "Here!!").
		"\n");
    
  }
}

=pod

=item I<elog>

provides some basic STDERR logging facilities. Otherwise see C<flog>.

Example:

   elog ('MyProgram', 4, 'Logging a line', $line, \%context);

=cut

use Data::Dumper;

sub elog {
  my $entity = shift;
  my $level  = shift || 1;

  return if $level > $loglevel;

  my $m;
  foreach my $v (@_) {
    if (!ref($v)) {
      $m .= $v;
    } else {
      $m .= Dumper $v;
    }
  }
  print STDERR (strftime "%Y %a %b %e %H:%M:%S", localtime)." - $entity($level): ".    ($m ? $m : "Here!!").  "\n";
}


=pod

=back

=head1 SEE ALSO

L<XTM>

=head1 AUTHOR INFORMATION

Copyright 2001, Robert Barta <rho@telecoma.net>, All rights reserved.
 
This library is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.

=cut

1;

__END__