This file is indexed.

/usr/share/perl5/NetSDS/Logger.pm is in libnetsds-perl 1.301-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#===============================================================================
#
#         FILE:  Logger.pm
#
#  DESCRIPTION:  Syslog wrapper for Net SDS
#
#       AUTHOR:  Michael Bochkaryov (Rattler), <misha@rattler.kiev.ua>
#      COMPANY:  Net.Style
#      CREATED:  25.04.2008 17:32:37 EEST
#===============================================================================

=head1 NAME

NetSDS::Logger - syslog wrapper for applications and classes

=head1 SYNOPSIS

	use NetSDS::Logger;

	my $logger = NetSDS::Logger->new(
		name => 'NetSDS-SuperDaemon',
	);
	$logger->log("info", "Syslog message here");

=head1 DESCRIPTION

This module contains implementation of logging functionality for NetSDS components.

By default, messages are logged with C<local0> facility and C<pid,ndelay,nowait> options.

B<NOTE>: C<NetSDS::Logger> module is for internal use mostly from application
frameworks like C<NetSDS::App>, C<NetSDS::App::FCGI>, etc.

=cut

package NetSDS::Logger;

use 5.8.0;
use warnings;

use Unix::Syslog qw(:macros :subs);

use version; our $VERSION = '1.301';

#===============================================================================

=head1 CLASS API

=over

=item B<new(%parameters)> - constructor

Constructor B<new()> creates new logger object and opens socket with default
NetSDS logging parameters.

Arguments allowed (as hash):

B<name> - application name for identification

	Use only ASCII characters in "name" to avoid possible errors.
	Default value is "NetSDS".

B<facility> - logging facility

	Available facility values:

		* local0..local7
		* user
		* daemon

	If not set 'local0' is used as default value

=cut

#-----------------------------------------------------------------------
sub new {

	my ( $class, %params ) = @_;

	my $self = {};

	# Set application identification name
	my $name = 'NetSDS';
	if ( $params{name} ) {
		$name = $params{name};
	}

	# Set logging facility
	my %facility_map = (
		'local0' => LOG_LOCAL0,
		'local1' => LOG_LOCAL1,
		'local2' => LOG_LOCAL2,
		'local3' => LOG_LOCAL3,
		'local4' => LOG_LOCAL4,
		'local5' => LOG_LOCAL5,
		'local6' => LOG_LOCAL6,
		'local7' => LOG_LOCAL7,
		'user'   => LOG_USER,
		'daemon' => LOG_DAEMON,
	);

	my $facility = LOG_LOCAL0;    # default is local0
	if ( $params{facility} ) {
		$facility = $facility_map{ $params{facility} } || LOG_LOCAL0;
	}

	openlog( $name, LOG_PID | LOG_CONS | LOG_NDELAY, $facility );

	return bless $self, $class;

} ## end sub new

#***********************************************************************

=item B<log($level, $message)> - write record to log

Wrapper to C<syslog()> method of L<Unix::Syslog> module.

Level is passed as string and may be one of the following:

	alert	- LOG_ALERT
	crit	- LOG_CRIT
	debug	- LOG_DEBUG
	emerg	- LOG_EMERG
	error	- LOG_ERR
	info	- LOG_INFO
	notice	- LOG_NOTICE
	warning	- LOG_WARNING

=cut

#-----------------------------------------------------------------------
sub log {

	my ( $self, $level, $message ) = @_;

	# Level aliases
	my %LEVFIX = (
		alert     => LOG_ALERT,
		crit      => LOG_CRIT,
		critical  => LOG_CRIT,
		deb       => LOG_DEBUG,
		debug     => LOG_DEBUG,
		emerg     => LOG_EMERG,
		emergency => LOG_EMERG,
		panic     => LOG_EMERG,
		err       => LOG_ERR,
		error     => LOG_ERR,
		inf       => LOG_INFO,
		info      => LOG_INFO,
		inform    => LOG_INFO,
		note      => LOG_NOTICE,
		notice    => LOG_NOTICE,
		warning   => LOG_WARNING,
		warn      => LOG_WARNING,
	);

	my $LEV = $LEVFIX{$level};

	if ( !$LEV ) {
		$LEV = LOG_INFO;
	}

	if ( !$message ) {
		$message = "";
	}

	syslog( $LEV, "[$level] $message" );

} ## end sub log

#***********************************************************************

=item B<DESTROY> - class destructor

Destructor (DESTROY method) calls C<closelog()> function. That's all.

=cut

#-----------------------------------------------------------------------
sub DESTROY {

	closelog();

}

1;

__END__

=back

=head1 EXAMPLES

See L<NetSDS::App> for example.

=head1 SEE ALSO

L<Sys::Syslog>

=head1 TODO

1. Implement logging via UDP socket.

=head1 AUTHOR

Michael Bochkaryov <misha@rattler.kiev.ua>

=head1 LICENSE

Copyright (C) 2008-2009 Net Style Ltd.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

=cut