Skip to content

Commit

Permalink
0.0.3 - Bug fixes, added functionality
Browse files Browse the repository at this point in the history
Fixed typos in docs
Bug fixes in LOG(), WARN(), ERROR(), and set_style()
Added get_style()
Added unbuffer_output()
Added INVERSE text option
Tweaked styles
Updated examples/getopt_long.pl
  • Loading branch information
Alex-Kent committed Apr 11, 2019
1 parent bf424aa commit a87e6a1
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 58 deletions.
20 changes: 20 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
Revision history for Log::Selective

0.0.3 2019-04-11
Bug fixes, added functionality

o Fixed typos in docs
o Bug fixes in LOG(), WARN(), ERROR(), and set_style()
o Added get_style()
o Added unbuffer_output()
o Added INVERSE text option
o Tweaked styles
o Updated examples/getopt_long.pl

0.0.2 2019-04-10
Added styles, examples

o get_styles(): New function
o set_style(): New function
o set_colors(): Removed function
o LOG(): Rewrote color and style code
o Added detailed usage examples

0.0.1 2019-04-08
Initial release
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Changes
examples/00_index.txt
examples/all_functions.pl
examples/colors.pl
examples/extra_logging.pl
examples/getopt_long.pl
examples/stack_trace.pl
examples/styles.pl
ignore.txt
lib/Log/Selective.pm
LICENSE
Expand Down
113 changes: 84 additions & 29 deletions examples/getopt_long.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@

# Parse commandline options

my $help = undef;
my $verbose = 0;
my $quiet = undef;
my $silent = undef;
my $color = 'auto';
my $help = undef;
my $verbose = 0;
my $quiet = undef;
my $silent = undef;
my $extra_verbose = undef;
my $color = 'auto';
my $style = undef;
my $unbuffer = undef;

Getopt::Long::Configure ("no_ignore_case", "bundling");

unless ( GetOptions(
'help|h' => \$help,
'verbose|v+' => \$verbose,
'quiet|q' => \$quiet,
'silent|Q' => \$silent,
'color|c=s' => \$color
'help|h' => \$help,
'verbose|v+' => \$verbose,
'quiet|q' => \$quiet,
'silent|Q' => \$silent,
'extra-verbose=s' => \$extra_verbose,
'color|c=s' => \$color,
'style=s' => \$style,
'unbuffer' => \$unbuffer
) ) {
ERROR("Run '$0 --help' for available options");
exit;
Expand All @@ -39,57 +45,106 @@
be_quiet() if (defined $quiet);
be_silent() if (defined $silent);

if (defined $extra_verbose) {
my ($level, $regex) = split ',', $extra_verbose, 2;
extra_logging($level, $regex);
}

set_color_mode($color);

if ( defined $style ) {
if ( $style eq 'list' ) {
print "Available styles:\n";
print "@{[ get_styles() ]}\n";
exit;
} else {
set_style($style);
if ( get_style() ne $style ) {
ERROR( "Unknown style '$style'" );
exit;
}
}
}

unbuffer_output() if (defined $unbuffer);

show_usage() if ( $help );



# Display some output via Log::Selective

LOG( 0, "Run '$0 --help' for available options" );
LOG( 1, "Level 1 debug message" );
LOG( 2, "Level 2 debug message" );
LOG( 3, "Level 3 debug message" );
LOG( 4, "Level 4 debug message" );
LOG( 5, "Level 5 debug message" );

sub alpha() {
LOG( 2, "Level 2 debug message" );
LOG( 3, "Level 3 debug message" );
}

sub beta() {
LOG( 4, "Level 4 debug message" );
LOG( 5, "Level 5 debug message" );
}

alpha();
beta();

WARN( "Warning message" );
ERROR( "Error message" );

exit;



sub show_usage() {
print <<EOF;
Usage: $0 [OPTIONS]
Options:
--help | -h .......... Display this message
--help | -h ............. Display this message
--verbose | -v ....... Increase the amount of logging shown on the console.
This option can be given multiple times to show more
detailed information.
--verbose | -v .......... Increase the amount of logging shown on the console.
This option can be given multiple times to show more
detailed information.
--quiet | -q ......... Only show warnings and errors
--quiet | -q ............ Only show warnings and errors
--silent | -Q ........ Show no messages (not even warnings or errors)
--silent | -Q ........... Show no messages (not even warnings or errors)
--color=STRING | ..... Specify whether to use colors and styles for log messages
-c STRING Valid: 'auto', 'on', 'off'
Default: 'auto'
In 'auto' mode logging messages will only receive color
and styling if output is to a terminal (not a pipe or a
file). To force color output use 'on', to force plain
text output use 'off'.
--extra-verbose=STRING .. Show more verbose output for specific functions
The syntax of STRING is "LEVEL,REGEX" where LEVEL is
the maximum verbosity level and REGEX is the regular
expression matching the function names to show extra
verbosity for.
For example, to show messages up to level 4 for
alpha() and beta() one could use:
--extra-verbose="4,(alph|bet)a"
--color=STRING | ........ Whether to use colors and styles for log messages
-c STRING Valid: 'auto', 'on', 'off'
Default: 'auto'
In 'auto' mode logging messages will only receive
color and styling if output is to a terminal (not a
pipe or a file). To force color output use 'on', to
force plain text output use 'off'.
--style=STRING .......... Specify the color theme to use for console output
or use 'list' to see available styles
--unbuffer .............. Unbuffer logging output
Try running the following to see how Log::Selective handles output:
$0
$0 -v
$0 -vvvv
$0 -vvvvv
$0 --quiet
$0 --silent
$0 --extra-verbose="4,(alph|bet)a"
$0 | cat
$0 --color=on | cat
EOF
Expand Down
Loading

0 comments on commit a87e6a1

Please sign in to comment.