Merge branch 'master' of ssh://git.indexdata.com:222/home/git/pub/irspy
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Web.pm
1
2 package ZOOM::IRSpy::Web;
3
4 use 5.008;
5 use strict;
6 use warnings;
7
8 use ZOOM::IRSpy;
9 our @ISA = qw(ZOOM::IRSpy);
10
11 use ZOOM::IRSpy::Utils qw(xml_encode);
12
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.  Note that this arrangement only allows IRSpy-specific logging
25 to be generated, not underlying ZOOM logging.
26
27 =cut
28
29 sub log_init_level {
30     my $this = shift();
31     my($level) = @_;
32
33     my $old = $this->{log_level};
34     $this->{log_level} = $level if defined $level;
35     return $old;
36 }
37
38 sub log {
39     my $this = shift();
40     my($level, @s) = @_;
41
42     $this->{log_level} = "irspy" if !defined $this->{log_level};
43     return if index(("," . $this->{log_level} . ","), ",$level,") < 0;
44
45     my $message = "[$level] " . join("", @s);
46     $| = 1;                     # 
47     print xml_encode($message), "<br/>\n";
48
49     ### This is naughty -- it knows about HTML::Mason
50     $HTML::Mason::Commands::m->flush_buffer();
51 }
52
53
54 =head1 SEE ALSO
55
56 ZOOM::IRSpy
57
58 =head1 AUTHOR
59
60 Mike Taylor, E<lt>mike@indexdata.comE<gt>
61
62 =head1 COPYRIGHT AND LICENSE
63
64 Copyright (C) 2006 by Index Data ApS.
65
66 This library is free software; you can redistribute it and/or modify
67 it under the same terms as Perl itself, either Perl version 5.8.7 or,
68 at your option, any later version of Perl 5 you may have available.
69
70 =cut
71
72 1;