added checking of result when building demos
[urisagit/Stem.git] / lib / Stem / Log / Entry.pm
CommitLineData
4536f655 1# File: Stem/Log/Entry.pm
2
3# This file is part of Stem.
4# Copyright (C) 1999, 2000, 2001 Stem Systems, Inc.
5
6# Stem is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10
11# Stem is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with Stem; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20# For a license to use the Stem under conditions other than those
21# described here, to purchase support for this software, or to purchase a
22# commercial warranty contract, please contact Stem Systems at:
23
24# Stem Systems, Inc. 781-643-7504
25# 79 Everett St. info@stemsystems.com
26# Arlington, MA 02474
27# USA
28
29use strict ;
30
31use Stem::Log ;
32
33package Stem::Log::Entry ;
34
35Stem::Route::register_class( __PACKAGE__, 'entry' ) ;
36
37
38my $attr_spec = [
39
40 {
41 'name' => 'text',
42 'default' => '',
43 'help' => <<HELP,
44Text for this log entry. Can be filtered with the rule 'match_text'.
45HELP
46 },
47 {
48 'name' => 'label',
49 'default' => 'info',
50 'help' => <<HELP,
51Label for this log entry. This is used to tag log entries from
52different sources. Can be filtered with the rule 'match_label'.
53HELP
54 },
55 {
56 'name' => 'level',
57 'default' => '1',
58 'help' => <<HELP,
59Severity level for this log entry. It is an integer with 0 being the
60most severe level and 10 the lowest (this maps to the levels of
61syslog). There are several rules which can filter based on the level.
62HELP
63 },
64 {
65 'name' => 'logs',
66 'type' => 'list',
67 'help' => <<HELP,
68This is a list of logical logs where this entry is submitted. The
69first one is considered the original log. If this is not passed, then
70the entry must be explicitly submitted by the submit method.
71HELP
72 },
73] ;
74
75
76
77sub new {
78
79 my( $class ) = shift ;
80
81 my $self = Stem::Class::parse_args( $attr_spec, @_ ) ;
82 return $self unless ref $self ;
83
84 $self->{'time'} = time() ;
85 $self->{'hub_name'} = $Stem::Vars::Hub_name ;
86 $self->{'host_name'} = $Stem::Vars::Host_name ;
87 $self->{'program_name'} = $Stem::Vars::Program_name ;
88
89 if ( my $logs_attr = $self->{'logs'} ) {
90
91 $self->submit( @{$logs_attr} ) ;
92 }
93
94 return $self ;
95}
96
97sub submit {
98
99 my( $self, @logs ) = @_ ;
100
101 foreach my $log_name ( @logs ) {
102
103#print "LOG [$log_name]\n" ;
104 if ( $log_name =~ /^(\w+):(\w+)$/ ) {
105
106 my $to_hub = $1 ;
107 my $to_log = $2 ;
108
109 my $log_msg = Stem::Msg->new(
110 'to' => "$to_hub:" . __PACKAGE__,
111 'from' => __PACKAGE__,
112 'type' => 'log',
113 'log' => $to_log,
114 'data' => $self,
115 ) ;
116
117#print $log_msg->dump( 'LOG out' ) ;
118
119
120 $log_msg->dispatch() ;
121
122 next ;
123 }
124
125 my $log_obj = Stem::Log::find_log( $log_name ) ;
126
127 next unless $log_obj ;
128
129
130 my $entry_copy ||= { %{$self} } ;
131
132 $entry_copy->{'log_name'} = $log_name ;
133 $entry_copy->{'orig_log_name'} ||= $log_name ;
134 $entry_copy->{'entry_obj'} = $self ;
135
136 $log_obj->submit( $entry_copy ) ;
137 }
138}
139
140# this method is how a remote log message is delivered locally
141
142sub log_in {
143
144 my( $class, $msg ) = @_ ;
145
146 my $entry = $msg->data() ;
147
148 print "$entry\n" unless ref $entry ;
149
150#print $msg->dump( 'LOG in' ) ;
151
152 $entry->submit( $msg->log() ) ;
153
154 return ;
155}
156
1571 ;