Filename | /usr/local/lib/perl5/site_perl/mach/5.24/Razor2/Syslog.pm |
Statements | Executed 15 statements in 1.12ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 38µs | 203µs | BEGIN@3 | Razor2::Syslog::
1 | 1 | 1 | 23µs | 728µs | BEGIN@5 | Razor2::Syslog::
1 | 1 | 1 | 20µs | 100µs | BEGIN@6 | Razor2::Syslog::
1 | 1 | 1 | 20µs | 3.33ms | BEGIN@4 | Razor2::Syslog::
0 | 0 | 0 | 0s | 0s | new | Razor2::Syslog::
0 | 0 | 0 | 0s | 0s | send | Razor2::Syslog::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Razor2::Syslog; | ||||
2 | |||||
3 | 2 | 60µs | 2 | 368µs | # spent 203µs (38+165) within Razor2::Syslog::BEGIN@3 which was called:
# once (38µs+165µs) by Razor2::Logger::BEGIN@6 at line 3 # spent 203µs making 1 call to Razor2::Syslog::BEGIN@3
# spent 165µs making 1 call to vars::import |
4 | 2 | 63µs | 2 | 6.64ms | # spent 3.33ms (20µs+3.31) within Razor2::Syslog::BEGIN@4 which was called:
# once (20µs+3.31ms) by Razor2::Logger::BEGIN@6 at line 4 # spent 3.33ms making 1 call to Razor2::Syslog::BEGIN@4
# spent 3.31ms making 1 call to IO::Socket::import |
5 | 2 | 62µs | 2 | 1.43ms | # spent 728µs (23+705) within Razor2::Syslog::BEGIN@5 which was called:
# once (23µs+705µs) by Razor2::Logger::BEGIN@6 at line 5 # spent 728µs making 1 call to Razor2::Syslog::BEGIN@5
# spent 705µs making 1 call to Exporter::import |
6 | 2 | 868µs | 2 | 180µs | # spent 100µs (20+80) within Razor2::Syslog::BEGIN@6 which was called:
# once (20µs+80µs) by Razor2::Logger::BEGIN@6 at line 6 # spent 100µs making 1 call to Razor2::Syslog::BEGIN@6
# spent 80µs making 1 call to Exporter::import |
7 | |||||
8 | 1 | 2µs | require Exporter; | ||
9 | |||||
10 | 1 | 17µs | @ISA = qw(Exporter AutoLoader); | ||
11 | # Items to export into callers namespace by default. Note: do not export | ||||
12 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||
13 | # Do not simply export all your public functions/methods/constants. | ||||
14 | 1 | 2µs | @EXPORT = qw( | ||
15 | |||||
16 | ); | ||||
17 | 1 | 2µs | $VERSION = '0.03'; | ||
18 | |||||
19 | |||||
20 | # Preloaded methods go here. | ||||
21 | |||||
22 | 1 | 11µs | my %syslog_priorities=( | ||
23 | emerg => 0, | ||||
24 | alert => 1, | ||||
25 | crit => 2, | ||||
26 | err => 3, | ||||
27 | warning => 4, | ||||
28 | notice => 5, | ||||
29 | info => 6, | ||||
30 | debug => 7 | ||||
31 | ); | ||||
32 | |||||
33 | 1 | 16µs | my %syslog_facilities=( | ||
34 | kern => 0, | ||||
35 | user => 1, | ||||
36 | mail => 2, | ||||
37 | daemon => 3, | ||||
38 | auth => 4, | ||||
39 | syslog => 5, | ||||
40 | lpr => 6, | ||||
41 | news => 7, | ||||
42 | uucp => 8, | ||||
43 | cron => 9, | ||||
44 | authpriv=> 10, | ||||
45 | ftp => 11, | ||||
46 | local0 => 16, | ||||
47 | local1 => 17, | ||||
48 | local2 => 18, | ||||
49 | local3 => 19, | ||||
50 | local4 => 20, | ||||
51 | local5 => 21, | ||||
52 | local6 => 22, | ||||
53 | ); | ||||
54 | |||||
55 | |||||
56 | sub new { | ||||
57 | |||||
58 | my $class = shift; | ||||
59 | my $name = $0; | ||||
60 | if($name =~ /.+\/(.+)/){ | ||||
61 | $name = $1; | ||||
62 | } | ||||
63 | my $self = { Name => $name, | ||||
64 | Facility => 'local5', | ||||
65 | Priority => 'err', | ||||
66 | SyslogPort => 514, | ||||
67 | SyslogHost => '127.0.0.1'}; | ||||
68 | bless $self,$class; | ||||
69 | my %par = @_; | ||||
70 | |||||
71 | foreach (keys %par){ | ||||
72 | $self->{$_}=$par{$_}; | ||||
73 | } | ||||
74 | |||||
75 | my $sock=new IO::Socket::INET(PeerAddr => $$self{SyslogHost}, | ||||
76 | PeerPort => $$self{SyslogPort}, | ||||
77 | Proto => 'udp'); | ||||
78 | die "Socket could not be created : $!\n" unless $sock; | ||||
79 | |||||
80 | $self->{sock} = $sock; | ||||
81 | |||||
82 | return $self; | ||||
83 | |||||
84 | } | ||||
85 | |||||
86 | |||||
87 | sub send { | ||||
88 | |||||
89 | my $self = shift; | ||||
90 | my $msg=shift; | ||||
91 | my %par = @_; | ||||
92 | my %local=%$self; | ||||
93 | |||||
94 | foreach (keys %par){ | ||||
95 | $local{$_}=$par{$_}; | ||||
96 | } | ||||
97 | |||||
98 | my $pid=$$; | ||||
99 | my $facility_i=$syslog_facilities{$local{Facility}}; | ||||
100 | my $priority_i=$syslog_priorities{$local{Priority}}; | ||||
101 | |||||
102 | if(!defined $facility_i){ | ||||
103 | $facility_i=21; | ||||
104 | } | ||||
105 | |||||
106 | if(!defined $priority_i){ | ||||
107 | $priority_i=4; | ||||
108 | } | ||||
109 | |||||
110 | my $d=(($facility_i<<3)|($priority_i)); | ||||
111 | my $message = "<$d>$local{Name}\[$pid\]: $msg"; | ||||
112 | |||||
113 | my $sock = $self->{sock}; | ||||
114 | |||||
115 | # Send the message to the socket directly. | ||||
116 | $sock->send($message); | ||||
117 | # Flush the socket, to ensure that messages don't arrive combined into one packet. | ||||
118 | $sock->flush; | ||||
119 | |||||
120 | } | ||||
121 | |||||
122 | |||||
123 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||
124 | |||||
125 | 1 | 22µs | 1; | ||
126 | __END__ |