Wed Jun 9 07:35:19 UTC 2010 Johnny Willemsen <jwillemsen@remedy.nl>
[MPC.git] / modules / OutputMessage.pm
blob58636c7823f68a5402677b174be3f40024a562e5
1 package OutputMessage;
3 # ************************************************************
4 # Description : Prints information, warnings and errors.
5 # Author : Chad Elliott
6 # Create Date : 2/02/2004
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 # ************************************************************
16 # Data Section
17 # ************************************************************
19 my $debugtag = 'DEBUG: ';
20 my $infotag = 'INFORMATION: ';
21 my $warntag = 'WARNING: ';
22 my $errortag = 'ERROR: ';
24 my $debug = 0;
25 my $information = 0;
26 my $warnings = 1;
27 my $diagnostic = 1;
28 my $details = 1;
30 # ************************************************************
31 # Subroutine Section
32 # ************************************************************
34 sub new {
35 my $class = shift;
36 return bless {}, $class;
40 sub set_levels {
41 my $str = shift;
43 if (defined $str) {
44 $debug = ($str =~ /debug\s*=\s*(\d+)/i ? $1 : 0);
45 $details = ($str =~ /detail(s)?\s*=\s*(\d+)/i ? $2 : 0);
46 $diagnostic = ($str =~ /diag(nostic)?\s*=\s*(\d+)/i ? $2 : 0);
47 $information = ($str =~ /info(rmation)?\s*=\s*(\d+)/i ? $2 : 0);
48 $warnings = ($str =~ /warn(ing)?\s*=\s*(\d+)/i ? $2 : 0);
52 sub split_message {
53 my($self, $msg, $spc) = @_;
54 $msg =~ s/\.\s+/.\n$spc/g;
55 return $msg . "\n";
59 sub details {
60 if ($details) {
61 #my($self, $msg) = @_;
62 print "$_[1]\n";
67 sub diagnostic {
68 if ($diagnostic) {
69 #my($self, $msg) = @_;
70 print "$_[1]\n";
75 sub debug {
76 if ($debug) {
77 #my($self, $msg) = @_;
78 print "$debugtag$_[1]\n";
83 sub information {
84 if ($information) {
85 #my($self, $msg) = @_;
86 print $infotag, $_[0]->split_message($_[1], ' ' x length($infotag));
91 sub warning {
92 if ($warnings) {
93 #my($self, $msg) = @_;
94 print $warntag, $_[0]->split_message($_[1], ' ' x length($warntag));
99 sub error {
100 my($self, $msg, $pre) = @_;
101 print STDERR '', (defined $pre ? "$pre\n" : ''), $errortag,
102 $self->split_message($msg, ' ' x length($errortag));