Add log_init_level()
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Web.pm
1 # $Id: Web.pm,v 1.2 2006-09-26 11:25:07 mike Exp $
2
3 package ZOOM::IRSpy::Web;
4
5 use 5.008;
6 use strict;
7 use warnings;
8
9 use ZOOM::IRSpy;
10 our @ISA = qw(ZOOM::IRSpy);
11
12 use ZOOM::IRSpy::Record qw(xml_encode);
13
14 =head1 NAME
15
16 ZOOM::IRSpy::Web - subclass of ZOOM::IRSpy for use by Web UI
17
18 =head1 DESCRIPTION
19
20 This behaves exactly the same as the base C<ZOOM::IRSpy> class except
21 that the Clog()> method does not call YAZ log, but outputs
22 HTML-formatted messages on standard output.  The additional function
23 log_init_level() controls what log-levels are to be included in the
24 output.
25
26 =cut
27
28 sub log_init_level {
29     my $this = shift();
30     my($level) = @_;
31
32     my $old = $this->{log_level};
33     $this->{log_level} = $level if defined $level;
34     return $old;
35 }
36
37 sub log {
38     my $this = shift();
39     my($level, @s) = @_;
40
41     $this->{log_level} = "irspy" if !defined $this->{log_level};
42     return if index(("," . $this->{log_level} . ","), ",$level,") < 0;
43
44     my $message = "[$level] " . join("", @s);
45     $| = 1;                     # 
46     print xml_encode($message), "<br/>\n";
47
48     ### This is naughty -- it knows about HTML::Mason
49     $HTML::Mason::Commands::m->flush_buffer();
50 }
51
52
53 =head1 SEE ALSO
54
55 ZOOM::IRSpy
56
57 =head1 AUTHOR
58
59 Mike Taylor, E<lt>mike@indexdata.comE<gt>
60
61 =head1 COPYRIGHT AND LICENSE
62
63 Copyright (C) 2006 by Index Data ApS.
64
65 This library is free software; you can redistribute it and/or modify
66 it under the same terms as Perl itself, either Perl version 5.8.7 or,
67 at your option, any later version of Perl 5 you may have available.
68
69 =cut
70
71 1;