Commits

Herbert Breunung committed b350c99

redo logging

Comments (0)

Files changed (5)

lib/Kephra/App/Focus.pm

 
 sub set  {                              # set focus to another widget
 	my ($widget) = @_;
-	Kephra::Log::note("focus is on :". get()." and will be: $widget");
+	#Kephra::Log::note("focus is on :". get()." and will be: $widget");
 	return Kephra::Log::warning( "got no proper widget but $widget", 1 )
 		unless Kephra::App::Util::is_widget($widget);
 	return if $widget eq get();

lib/Kephra/Log.pm

 
 our $level;
 our @output;
-our $test_mode = 0;
 
-sub init {}
+our $global_switch = 1;    # do_logging
+our $GUI_switch = 1;
+our $CLI_switch = 1;
+our %local_switch;
+
+sub mode {
+	my $mode = shift;
+	return unless defined $mode;
+	return unless $mode eq 'on' or $mode eq 'off'
+		or $mode eq 'gui' or $mode eq 'text' or $mode eq 'all';
+	$global_switch = $mode eq 'off' ? 0 : 1;
+	if ($mode eq 'text'){ $GUI_switch = 0; $CLI_switch = 1 }
+	if ($mode eq 'gui') { $GUI_switch = 1; $CLI_switch = 0 }
+	if ($mode eq 'all') { $GUI_switch = 1; $CLI_switch = 1 }
+}
+
 
 sub note {
-	return if $test_mode;
-	#say message( @_ );
+	return unless $global_switch;
+	say message( @_ ) if $CLI_switch;
 }
 
 sub warning {
-	return if $test_mode;
+	return unless $global_switch;
 	my $msg = message( @_ );
-	warn $msg;
-	Kephra::API::output('warn', $msg) unless $test_mode;
+	warn $msg if $CLI_switch;
+	Kephra::API::output('warn', $msg) if $GUI_switch;
 }
 
 sub error {
-	return if $test_mode;
+	return unless $global_switch;
 	my $msg = message( @_ );
-	die $msg;
-	Kephra::API::output('warn', 'ERROR: '.$msg) unless $test_mode;
+	die $msg if $CLI_switch;
+	Kephra::API::output('warn', 'ERROR: '.$msg) if $GUI_switch;
 }
 
 sub message     { 
 use Wx;
 use Kephra::App::Util qw(is_widget is_panel is_sizer is_color is_font create_color lounch_browser);
 
+
 # testing the function that gives references to the helper functions
 my $testcolor = Kephra::App::Util::get('is_color');
 my @chref = Kephra::App::Util::get('is_color', 'create_color');

t/605-app-focus.t

 use Kephra;
 
 Kephra::load_libs();
-$Kephra::Log::test_mode = 1;
+Kephra::Log::mode('text');
 
 my $frame = Wx::Frame->new( undef, -1, '');
 my $label = Wx::StaticText->new( undef, -1, '');
 is(Kephra::App::Focus::get(), $label, 'second widget was stored');
 
 my $size = Kephra::App::Focus::stack_size();
+Kephra::Log::mode('off'); # making some wrong things now
 Kephra::App::Focus::set($label);
 is(Kephra::App::Focus::stack_size(), $size, 'don\'t store widget twice in a row');
 
 is(Kephra::App::Focus::get(), $label, 'set doesnt take number');
 
 Kephra::App::Focus::set([]);
+Kephra::Log::mode('text');
 is(Kephra::App::Focus::get(), $label, 'set doesnt take references');
 
 Kephra::App::Focus::set_back();

t/610-api-command.t

 use Kephra::App::Util;
 
 Kephra::load_libs();
-$Kephra::Log::test_mode = 1;
+Kephra::Log::mode('text');
 
 sub one     { 'one' }
 sub true    { 'true' }