1 package Sys::Syslog::Win32;
7 # === WARNING === WARNING === WARNING === WARNING === WARNING === WARNING ===
9 # This file was generated by Sys-Syslog/win32/compile.pl on Wed Aug 22 01:33:58 2007
10 # Any changes being made here will be lost the next time Sys::Syslog
13 # Do NOT USE THIS MODULE DIRECTLY: this is a utility module for Sys::Syslog.
14 # It may change at any time to fit the needs of Sys::Syslog therefore no
15 # warranty is made WRT to its API. You Have Been Warned.
17 # === WARNING === WARNING === WARNING === WARNING === WARNING === WARNING ===
24 use Win32::TieRegistry 0.20 (
25 TiedRef => \$Registry,
42 my $is_Cygwin = $^O =~ /Cygwin/i;
43 my $is_Win32 = $^O =~ /Win32/i;
97 MSG_REMOTEAUTH => 149,
106 STATUS_SEVERITY_SUCCESS => 0,
107 STATUS_SEVERITY_INFORMATIONAL => 1,
108 STATUS_SEVERITY_WARNING => 2,
109 STATUS_SEVERITY_ERROR => 3,
114 Sys::Syslog::LOG_KERN() => 'KERN',
115 Sys::Syslog::LOG_USER() => 'USER',
116 Sys::Syslog::LOG_MAIL() => 'MAIL',
117 Sys::Syslog::LOG_DAEMON() => 'DAEMON',
118 Sys::Syslog::LOG_AUTH() => 'AUTH',
119 Sys::Syslog::LOG_SYSLOG() => 'SYSLOG',
120 Sys::Syslog::LOG_LPR() => 'LPR',
121 Sys::Syslog::LOG_NEWS() => 'NEWS',
122 Sys::Syslog::LOG_UUCP() => 'UUCP',
123 Sys::Syslog::LOG_CRON() => 'CRON',
124 Sys::Syslog::LOG_AUTHPRIV() => 'AUTHPRIV',
125 Sys::Syslog::LOG_FTP() => 'FTP',
126 Sys::Syslog::LOG_LOCAL0() => 'LOCAL0',
127 Sys::Syslog::LOG_LOCAL1() => 'LOCAL1',
128 Sys::Syslog::LOG_LOCAL2() => 'LOCAL2',
129 Sys::Syslog::LOG_LOCAL3() => 'LOCAL3',
130 Sys::Syslog::LOG_LOCAL4() => 'LOCAL4',
131 Sys::Syslog::LOG_LOCAL5() => 'LOCAL5',
132 Sys::Syslog::LOG_LOCAL6() => 'LOCAL6',
133 Sys::Syslog::LOG_LOCAL7() => 'LOCAL7',
134 Sys::Syslog::LOG_NETINFO() => 'NETINFO',
135 Sys::Syslog::LOG_REMOTEAUTH() => 'REMOTEAUTH',
136 Sys::Syslog::LOG_RAS() => 'RAS',
137 Sys::Syslog::LOG_INSTALL() => 'INSTALL',
138 Sys::Syslog::LOG_LAUNCHD() => 'LAUNCHD',
139 Sys::Syslog::LOG_CONSOLE() => 'CONSOLE',
140 Sys::Syslog::LOG_NTP() => 'NTP',
141 Sys::Syslog::LOG_SECURITY() => 'SECURITY',
142 Sys::Syslog::LOG_AUDIT() => 'AUDIT',
143 Sys::Syslog::LOG_LFMT() => 'LFMT',
147 my @priority2eventtype = (
148 EVENTLOG_ERROR_TYPE(), # LOG_EMERG
149 EVENTLOG_ERROR_TYPE(), # LOG_ALERT
150 EVENTLOG_ERROR_TYPE(), # LOG_CRIT
151 EVENTLOG_ERROR_TYPE(), # LOG_ERR
152 EVENTLOG_WARNING_TYPE(), # LOG_WARNING
153 EVENTLOG_WARNING_TYPE(), # LOG_NOTICE
154 EVENTLOG_INFORMATION_TYPE(), # LOG_INFO
155 EVENTLOG_INFORMATION_TYPE(), # LOG_DEBUG
162 # Used to set up a connection to the eventlog.
165 return $logger if $logger;
167 # can't just use basename($0) here because Win32 path often are a
168 # a mix of / and \, and File::Basename::fileparse() can't handle that,
169 # while File::Spec::splitpath() can.. Go figure..
170 my (undef, undef, $basename) = File::Spec->splitpath($0);
171 ($Source) ||= $basename;
173 $Source.=" [SSW:1.0.1]";
175 #$Registry->Delimiter("/"); # is this needed?
176 my $root = 'LMachine/SYSTEM/CurrentControlSet/Services/Eventlog/Application/';
177 my $dll = 'Sys/Syslog/PerlLog.dll';
179 if (!$Registry->{$root.$Source} ||
180 !$Registry->{$root.$Source.'/CategoryMessageFile'}[0] ||
181 !-e $Registry->{$root.$Source.'/CategoryMessageFile'}[0] )
184 # find the resource DLL, which should be along Syslog.dll
185 my ($file) = grep { -e $_ } map { ("$_/$dll" => "$_/auto/$dll") } @INC;
186 $dll = $file if $file;
188 # on Cygwin, convert the Unix path into absolute Windows path
191 chomp($file = Cygwin::posix_to_win_path($file, 1));
194 local $ENV{PATH} = '';
195 chomp($dll = `/usr/bin/cygpath --absolute --windows "$dll"`);
199 $dll =~ s![\\/]+!\\!g; # must be backslashes!
200 die "fatal: Can't find resource DLL for Sys::Syslog\n" if !$dll;
202 $Registry->{$root.$Source} = {
203 '/EventMessageFile' => [ $dll, REG_EXPAND_SZ ],
204 '/CategoryMessageFile' => [ $dll, REG_EXPAND_SZ ],
205 '/CategoryCount' => [ '0x0000001e', REG_DWORD ],
206 #'/TypesSupported' => [ '0x0000001e', REG_DWORD ],
209 warn "Configured eventlog to use $dll for $Source\n" if $Sys::Syslog::DEBUG;
212 #Carp::confess("Registry has the wrong value for '$Source', possibly mismatched dll!\nMine:$dll\nGot :$Registry->{$root.$Source.'/CategoryMessageFile'}[0]\n")
213 # if $Registry->{$root.$Source.'/CategoryMessageFile'}[0] ne $dll;
215 # we really should do something useful with this but for now
216 # we set it to "" to prevent Win32::EventLog from warning
219 $logger = Win32::EventLog->new($Source, $host)
220 or Carp::confess("Failed to connect to the '$Source' event log");
229 # Used to convert syslog messages into eventlog messages
232 my ($buf, $numpri, $numfac) = @_;
233 $numpri ||= EVENTLOG_INFORMATION_TYPE();
234 $numfac ||= Sys::Syslog::LOG_USER();
235 my $name = $id2name{$numfac};
238 EventType => $priority2eventtype[$numpri],
239 EventID => $const{"MSG_$name"},
240 Category => $const{"CAT_$name"},
245 if ($Sys::Syslog::DEBUG) {
246 require Data::Dumper;
247 warn Data::Dumper->Dump(
248 [$numpri, $numfac, $name, $opts],
249 [qw(numpri numfac name opts)]
253 return $logger->Report($opts);
259 Sys::Syslog::Win32 - Win32 support for Sys::Syslog
263 This module is a back-end plugin for C<Sys::Syslog>, for supporting the Win32
264 event log. It is not expected to be directly used by any module other than
265 C<Sys::Syslog> therefore it's API may change at any time and no warranty is
266 made with regards to backward compatibility. You Have Been Warned.
274 SE<eacute>bastien Aperghis-Tramoni and Yves Orton
278 This program is free software; you can redistribute it and/or modify it
279 under the same terms as Perl itself.