summaryrefslogtreecommitdiffabout
path: root/modules/renrot_msg.pm
Side-by-side diff
Diffstat (limited to 'modules/renrot_msg.pm') (more/less context) (ignore whitespace changes)
-rwxr-xr-xmodules/renrot_msg.pm86
1 files changed, 86 insertions, 0 deletions
diff --git a/modules/renrot_msg.pm b/modules/renrot_msg.pm
new file mode 100755
index 0000000..2b16f88
--- a/dev/null
+++ b/modules/renrot_msg.pm
@@ -0,0 +1,86 @@
+use strict;
+
+use Term::ANSIColor;
+
+package msg;
+
+sub new {
+ my $obj = shift;
+ my $use_color = shift;
+ my $quiet = shift;
+ my $verbose = shift;
+ my %colors = (
+ debug => {value => 'green'},
+ error => {value => 'magenta'},
+ fatal => {value => 'red'},
+ info => {value => 'bold'},
+ process => {value => 'white'},
+ warning => {value => 'cyan'},
+ );
+ return (bless {use_color => $use_color,
+ quiet => $quiet,
+ verbose => $verbose,
+ colors => \%colors,
+ }, $obj);
+ #$obj->Dbg(4,"msg class has been created.\n");
+}
+# destructor
+sub DESTROY {
+ my $obj = shift;
+ #$obj->Dbg(4,"msg class has been destroied.\n");
+}
+# Prints colored message to STDERR
+sub coloredprn {
+ my $obj = shift;
+ my $facility = shift;
+ if ($obj->{use_color} != 0) {
+ if (defined $facility and defined $obj->{colors}{$facility}) {
+ print STDERR Term::ANSIColor::colored [$obj->{colors}{$facility}{value}], @_;
+ return;
+ }
+ }
+ print STDERR @_; # fallback to normal print
+}
+# processing message
+sub Proc {
+ my $obj = shift;
+ return if ($obj->{quiet} != 0);
+
+ if ($obj->{use_color} != 0) {
+ if (defined $obj->{colors}{'process'}) {
+ print Term::ANSIColor::colored [$obj->{colors}{'process'}{value}], @_;
+ return;
+ }
+ }
+ print @_; # fallback to normal print
+}
+# information message
+sub Info {
+ my $obj = shift;
+ $obj->coloredprn('info', @_);
+}
+# warning message
+sub Warn {
+ my $obj = shift;
+ $obj->coloredprn('warning', "Warning: ", @_);
+}
+# error message
+sub Err {
+ my $obj = shift;
+ $obj->coloredprn('error', "ERROR: ", @_);
+}
+# fatal message
+sub Fatal {
+ my $obj = shift;
+ $obj->coloredprn('fatal', "FATAL: ", @_);
+}
+# debug message
+sub Dbg {
+ my $obj = shift;
+ my $level = shift;
+ if ($obj->{verbose} >= $level) {
+ $obj->coloredprn('debug', "DEBUG[$level]: ", @_);
+ }
+}
+
+1;

Return to:

Send suggestions and report system problems to the System administrator.