Commits

Herbert Breunung committed 676c3f0

smarter logging messages include called sub name

Comments (0)

Files changed (12)

lib/Kephra/API.pm

 use strict;
 use warnings;
-
-package Kephra::API;
-
 use Carp;
 use Kephra::App::Window;
 use Kephra::Config::Global;
 use Kephra::KeyMap;
 use Kephra::Log;
 
+package Kephra::API;
 Kephra::CommandList::register_switch_var({
 	'$app'    => 'app',
 	'$win'    => 'main_window',

lib/Kephra/App/Panel/Editor.pm

 	my( $class, $parent) = @_;
 	$doc_bar{'leftup'} = Kephra::App::Bar::Document->new( $parent );
 	# Wx::SplitterWindow->new( $splitter{'left'}, -1 );
-
 	return $doc_bar{'leftup'};
 }
 

lib/Kephra/App/Panel/FileBrowser.pm

 use Kephra::API;
 use Kephra::File;
 
+Kephra::CommandList::register_cmd_namespace('filebrowser');
 Kephra::CommandList::register_cmd({
-	'filebrowser-open' => {
-		sub => 'focus', label => 'Filebrowser', keys  => 'F2',
-		help => ''},
+ '-focus'=>{ sub=>'focus', label => ' ', keys => 'F2' },
 });
 
 

lib/Kephra/App/Panel/IOUnit.pm

 our @ISA = 'Wx::Panel';
 our $_ref;
 
-Kephra::CommandList::register_cmd_namespace('IOUnit');
+Kephra::CommandList::register_cmd_namespace('iounit');
 Kephra::CommandList::register_cmd({
-	'-focus' => { sub => 'focus_on_input',    label => ' ', keys => 'esc'},
+ '-focus'=>{sub=>'focus_on_input', label => ' ', keys => 'esc'},
 });
 
 
-
 sub new {
 	my( $class, $parent) = @_;
 	my $self = $_ref = $class->SUPER::new($parent, -1);

lib/Kephra/App/Window.pm

 my $title_end = "$Kephra::NAME $Kephra::VERSION";
 
 Kephra::CommandList::register_cmd({
-	'window-fullscreen-toggle' => { 
-		sub => '$win->toggle_fullscreen', label => 'Fullscreen', keys => 'F11', 
-		help => ''},
+ 'window-fullscreen-toggle'=>{sub => '$win->toggle_fullscreen', label=>'Fullscreen', keys=>'F11'},
 });
 
 
 sub get_focus { $_[0]->{'focus_stack'}[0] }
 sub set_focus {
 	my ($self, $widget) = @_;
-	die __PACKAGE__."::set_focus got no proper widget ($widget) from ", (caller)[0]
+	Kephra::Log::warning( "got no proper widget ($widget) from ", (caller)[0] )
 		unless Kephra::App::Util::is_widget($widget);
 	unshift @{$self->{'focus_stack'}}, $widget;
 	pop @{$self->{'focus_stack'}} if @{$self->{'focus_stack'}} > 12;

lib/Kephra/CommandList.pm

 	my $calling_module = (caller)[0];
 	if (ref $var eq ref {}){
 		no strict 'refs';
-		#return Kephra::Log::error #("register_object_switch_var: $- already registered as ".$switch{'name'}{$_}) #if exists $switch{'name'}{$_};
+		#return Kephra::Log::error #("$- already registered as ".$switch{'name'}{$_}) if exists $switch{'name'}{$_};
 		for my $name (keys %$var){
 			$var->{$name} = $calling_module . '::' . $var->{$name}
 				if index($var->{$name}, '::') == -1 and $calling_module;
 		$switch{'package'}{$calling_module} = $var if defined $calling_module;
 	}
 	else {
-		return Kephra::Log::error
-			("register_switch_var: need a sub name string or of a var => sub hash");
+		return Kephra::Log::error("need a sub name string or of a var => sub hash");
 	}
 }
 sub register_cmd_namespace {
 	my $name = shift;
 	my $calling_module = (caller)[0];
-	return Kephra::Log::error
-		("register_cmd_namespace: called without value from $calling_module") unless $name;
+	return Kephra::Log::error("called without value from $calling_module") unless $name;
 	$namespace{ $calling_module } = $name;
 }
 sub register_cmd {
 	my $cmd = shift;
-	return Kephra::Log::error( 'register_cmd: "$cmd" has to be a hash ref')
-		unless ref $cmd eq ref {};
+	return Kephra::Log::error( '"$cmd" has to be a hash ref') unless ref $cmd eq ref {};
 	my $calling_module = (caller)[0];
 	my $cmd_namespace = $namespace{ $calling_module }; 
 	for my $ID (keys %$cmd) {
 		my $fullID = (substr($ID,0,1) eq '-' and $cmd_namespace)
 			? $cmd_namespace . $ID 
 			: $ID ;
-		Kephra::Log::warning
-			( "register_cmd: $cmd lacks command namespace to prefix"), next
+		Kephra::Log::warning("$cmd lacks command namespace to prefix"), next
 				if $fullID ne $ID and not $cmd_namespace;
-		Kephra::Log::warning( "register_cmd: $cmd already registered to do " .
+		Kephra::Log::warning( "$cmd already registered to do " .
 			cmd_property($fullID, 'sub') . " by " .
 			cmd_property($fullID, 'source')  ), next
 				if cmd_exists( $fullID );
 	for my $cmd (keys %list) {
 		my $data = $list{$cmd};
 		my $call = $data->{'sub'};
-		Kephra::Log::warning( "init: $cmd lacks sub value"), next unless $call;
+		Kephra::Log::warning( "$cmd lacks sub value"), next unless $call;
 		# insert start (prefix) of the call, module name mostly
 		if (substr($call, 0, 1) eq '$'){
 			if (substr($call, 1, 1) eq '_'){
 				Kephra::Log::warning
-					( "init: $cmd lacks switch declared by ".$data->{'source'}), next
+					( "$cmd lacks switch declared by ".$data->{'source'}), next
 						unless $switch{'package'}{ $data->{'source'} };
 				$call = $switch{'package'}{ $data->{'source'} }.'()'.substr($call, 2);
 			}
 
 sub cmd_all_properties { 
 	if ( cmd_exists($_[0]) ) { $list{$_[0]} }
-	else                     { Kephra::Log::warning
-		( 'cmd_all_properties: requested data of unknown command '.$_[0].' from '.(caller)[0])
+	else                     {
+		Kephra::Log::warning('requested data of unknown command '.$_[0].' from '.(caller)[0]);
 	}
 }
 sub cmd_property       { $list{$_[0]}{$_[1]}         if cmd_property_exists(@_) }

lib/Kephra/DocumentStash.pm

 sub active_editor { $active->editor }
 sub set_active_doc{
 	my $any = shift;
-	warn "Kephra::DocumentStash::set_active_doc: need a parameter!" unless $any;
+	Kephra::Log::warning('need a parameter!') unless $any;
 	my $new_doc = doc_by_anything( $any ) ;
 	return unless defined $new_doc;
 	_activate($new_doc);
 }
 sub add {            # silently
 	my $doc = shift;
-	warn __PACKAGE__."::add: add to me only docs, not $doc!"
-		unless $doc->isa('Kephra::Document');
+	Kephra::Log::warning("add to me only docs, not $doc!") unless $doc->isa('Kephra::Document');
 	$document{$doc->editor} = $doc;
 }
 sub del {
 	my $doc = shift;
-	warn __PACKAGE__."::del: add to me only docs, not $doc!" 
-		unless $doc->isa('Kephra::Document');
+	Kephra::Log::warning("add to me only docs, not $doc!") unless $doc->isa('Kephra::Document');
 	warn "DocStash:del: $doc was not in the stash!" unless $document{$doc->editor};
 	delete $document{$doc->editor};
 }
 
 sub doc_by_anything {
 	my $any = shift;
-	warn __PACKAGE__."::get_by_anything: need a parameter!" unless $any;
+	Kephra::Log::warning("need a parameter!") unless $any;
 	return     ref($any) eq ''                  ? doc_by_path ($any)
 			 : $any->isa('Wx::Panel')           ? doc_by_panel($any)
 			 : $any->isa('Kephra::App::Editor') ? doc_by_ed   ($any)
 }
 sub doc_by_ed {
 	my $ed = shift;
-	warn __PACKAGE__."::get_by_ed needs a Kephra::App::Editor, not $ed!"
+	Kephra::Log::warning("needs a Kephra::App::Editor, not $ed!")
 		unless $ed->isa('Kephra::App::Editor');
 	return $document{$ed};
 }
 sub doc_by_panel {
 	my $panel = shift;
-	warn "Kephra::DocumentStash::get_by_ed needs a Wx::Panel, not $panel!"
-		unless $panel->isa('Wx::Panel');
+	Kephra::Log::warning("needs a Wx::Panel, not $panel!") unless $panel->isa('Wx::Panel');
 	for my $ed (keys %document) {
 		return $document{$ed} if $document{$ed}->panel eq $panel;
 	}
 }
 sub doc_by_path {
 	my $file_path = shift;
-	warn "Kephra::DocumentStash::get_by_path needs a file path as input!"
-		unless $file_path and -e $file_path;
+	Kephra::Log::warning("needs a file path as input!") unless $file_path and -e $file_path;
 	for my $ed (keys %document) {
 		return $document{$ed} if $document{$ed}->file_path eq $file_path;
 	}
 
 sub file_loaded {
 	my $file_path = shift;
-	warn "Kephra::DocumentStash::file_loaded needs a file path as input!"
-		unless $file_path and -e $file_path;
+	Kephra::Log::warning("needs a file path as input!") unless $file_path and -e $file_path;
 	for my $ed (keys %document) {
 		return 1 if $document{$ed}->file_path and $document{$ed}->file_path eq $file_path;
 	}

lib/Kephra/Edit/Comment.pm

 package Kephra::App::Editor;
 
 Kephra::CommandList::register_cmd({
- '-comment-toggle'=>{ sub=>'$ed->toggle_comment', label=>'Toggle Comment', keys=>'alt+#' },
+ '-comment-toggle'=>{sub=>'$ed->toggle_comment', label=>'Toggle Comment', keys=>'alt+#' },
 });
 
 

lib/Kephra/Edit/Format.pm

 package Kephra::App::Editor;
 
 Kephra::CommandList::register_cmd({
- '-goto-block-up'    =>{sub=>'$ed->ParaUp',                   label=>'Block Up',    keys=>'ctrl+up' },
- '-goto-block-down'  =>{sub=>'$ed->ParaDown',                 label=>'Block Down',  keys=>'ctrl+down' },
- '-select-block-up'  =>{sub=>'$ed->ParaUpExtend',             label=>'Block Up',    keys=>'ctrl+shift+up' },
- '-select-block-down'=>{sub=>'$ed->ParaDownExtend',           label=>'Block Down',  keys=>'ctrl+shift+down' },
- '-indent-level'     =>{sub=>'$ed->indent_level',             label=>'Indent Level',keys=>'alt+right' },
- '-dedent-level'     =>{sub=>'$ed->dedent_level',             label=>'Dedent Level',keys=>'alt+left' },
- '-move-line-up'     =>{sub=>'$ed->move_sel_or_line_up',      label=>'Line Up',     keys=>'alt+up' },
- '-move-line-down'   =>{sub=>'$ed->move_sel_or_line_down',    label=>'Line Down',   keys=>'alt+down' },
- '-move-page-up'     =>{sub=>'$ed->move_sel_or_line_page_up', label=>'Page Up',     keys=>'' },
- '-move-page-down'   =>{sub=>'$ed->move_sel_or_line_page_down',label=>'Page Down',  keys=>'' },
- '-move-begin'       =>{sub=>'$ed->move_sel_or_line_begin',   label=>'Doc Begin',   keys=>'alt+home' },
- '-move-end'         =>{sub=>'$ed->move_sel_or_line_end',     label=>'Doc End',     keys=>'alt+end' },
- '-move-word-left'   =>{sub=>'$ed->move_sel_or_word_left',    label=>'Word Left',   keys=>'alt+shift+left' },
- '-move-word-right'  =>{sub=>'$ed->move_sel_or_word_right',   label=>'Word Right',  keys=>'alt+shift+right' },
+ '-goto-block-up'    =>{sub=>'$ed->ParaUp',                    label=>'Block Up',    keys=>'ctrl+up' },
+ '-goto-block-down'  =>{sub=>'$ed->ParaDown',                  label=>'Block Down',  keys=>'ctrl+down' },
+ '-select-block-up'  =>{sub=>'$ed->ParaUpExtend',              label=>'Block Up',    keys=>'ctrl+shift+up' },
+ '-select-block-down'=>{sub=>'$ed->ParaDownExtend',            label=>'Block Down',  keys=>'ctrl+shift+down' },
+ '-indent-level'     =>{sub=>'$ed->indent_level',              label=>'Indent Level',keys=>'alt+right' },
+ '-dedent-level'     =>{sub=>'$ed->dedent_level',              label=>'Dedent Level',keys=>'alt+left' },
+ '-move-line-up'     =>{sub=>'$ed->move_sel_or_line_up',       label=>'Line Up',     keys=>'alt+up' },
+ '-move-line-down'   =>{sub=>'$ed->move_sel_or_line_down',     label=>'Line Down',   keys=>'alt+down' },
+ '-move-page-up'     =>{sub=>'$ed->move_sel_or_line_page_up',  label=>'Page Up',     keys=>'' },
+ '-move-page-down'   =>{sub=>'$ed->move_sel_or_line_page_down',label=>'Page Down',   keys=>'' },
+ '-move-begin'       =>{sub=>'$ed->move_sel_or_line_begin',    label=>'Doc Begin',   keys=>'alt+home' },
+ '-move-end'         =>{sub=>'$ed->move_sel_or_line_end',      label=>'Doc End',     keys=>'alt+end' },
+ '-move-word-left'   =>{sub=>'$ed->move_sel_or_word_left',     label=>'Word Left',   keys=>'alt+shift+left' },
+ '-move-word-right'  =>{sub=>'$ed->move_sel_or_word_right',    label=>'Word Right',  keys=>'alt+shift+right' },
 });
 
 

lib/Kephra/Edit/Search.pm

 use strict;
 use warnings;
-
 use Kephra::API;
 
 package Kephra::Edit::Search;

lib/Kephra/KeyMap.pm

 use strict;
 use warnings;
 use Wx;
-use Kephra::CommandList;
-use Kephra::Log;
+use Kephra::API;
 
 package Kephra::KeyMap;
 
 
 sub register_keys {
 	my ($keys, $map) = @_;
-	return Kephra::Log::warning ("register_code: got no hashref") unless ref $keys eq ref {};
+	return Kephra::Log::warning ("got no hashref") unless ref $keys eq ref {};
 	$map = $main_map unless defined $map;
 	for my $cmd (keys %$keys) {
 		$definition{$map}{ $cmd } = $keys->{$cmd};
 		my $code = code_from_definition( $keys->{$cmd} );
 		unless (exists $code{$map}{ $code }) { $code{$map}{ $code } = $cmd }
 		else {
-			Kephra::Log::warning
-				("register_code: $cmd tried to register the already taken keycode $code");
+			Kephra::Log::warning("$cmd tried to register the already taken keycode $code");
 		}
 	}
 }
 
 sub code_registered {
 	my ($code, $map) = @_;
-	Kephra::Log::warning ("code_registered: got no key code") unless $code;
+	Kephra::Log::warning ('got no key code') unless $code;
 	$map = $main_map unless defined $map;
 	return 1 if defined $code{$map}{$code} and $code{$map}{$code}
 }
 
 sub cmd_from_code {
 	my ($code, $map) = @_;
-	Kephra::Log::warning ("cmd_from_code: got no key code") unless $code;
+	Kephra::Log::warning ('got no key code') unless $code;
 	$map = $main_map unless defined $map;
 	$code{$map}{$code};
 }
 sub code_from_definition {
 	my $def = shift;
 	$def =~ tr/ 	//d;
-	Kephra::Log::warning ("code_from_definition: got no key definition") unless $def;
+	Kephra::Log::warning ('got no key definition') unless $def;
 
 	my @key = split '\+', $def;           # only + can combine key in definition
 	my $code = length($key[-1]) == 1 ? ord uc $key[-1] : $key_value{ $key[-1] };
-	Kephra::Log::warning ("code_from_definition: don't know this key ".$key[-1]) unless $code;
+	Kephra::Log::warning ('don\'t know this key '.$key[-1]) unless $code;
 
 	$code += $mod_key_value{ shift(@key) } while @key > 1;
 	Kephra::Log::warning ("got unknown key definition $def") unless $code;

lib/Kephra/Log.pm

 sub init {}
 
 sub warning { 
-	my $msg = timestamp().' '.(caller)[0].'::'. $_[0];
+	my $msg = timestamp() . ' ' . sender() . ': '. $_[0];
 	warn $msg;
 	Kephra::API::output('warn', $msg);
 }
 
-sub error { die timestamp(), ' ', (caller)[0], '::', $_[0] }
+sub error { die timestamp(), ' ', sender(), ': ', $_[0] }
 
 sub timestamp { sprintf("[%02u:%02u:%02u]", (localtime)[2,1,0]) }
-
+sub sender    { ( caller(2) )[0] . '::' . ( caller(2) )[3] }
 
 1;