Herbert Breunung avatar Herbert Breunung committed b94d606

starting to have logging

Comments (0)

Files changed (6)

Binary file modified.

lib/Kephra/API.pm

 package Kephra::API;
 our $VERSION = 0.1002;
 our @ISA = qw(Exporter);
-our @EXPORT = qw(note warn error);
-our @EXPORT_OK = qw();  # symbols to export on request
+our @EXPORT = qw(message warning error);
+our @EXPORT_OK = qw(message warning error);  # symbols to export on request
 #%EXPORT_TAGS = (T => [qw()], 2 => [qw()]);
 
-sub note  {}
-sub warn  {}
-sub error {}
+our $ed;
+our $doc;
+our $tabbar;
 
+sub message  { Kephra::API::Log::message(@_) }
+sub warning  { Kephra::API::Log::warning(@_) }
+sub error    { Kephra::API::Log::error(@_)   }
 
-'all you need';
+
+'all you need should is there for you';
Add a comment to this file

lib/Kephra/API/.DS_Store

Binary file removed.

lib/Kephra/API/Log.pm

 
 package Kephra::API::Log;
 
-use Kephra::API;
+use Kephra::API ();
 
 our $level;
 our @output;
-our %switch;
-
-our $global_switch = 1;    # do_logging
-our $GUI_switch = 0;
-our $CLI_switch = 1;
-our %local_switch;
+our %switch = (global => 1, cli => 1); # logging is on per default
 
 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 }
+	$switch{'global'} = $mode eq 'off' ? 0 : 1;
+	if ($mode eq 'text'){ $switch{'gui'} = 0; $switch{'cli'} = 1 }
+	if ($mode eq 'gui') { $switch{'gui'} = 1; $switch{'cli'} = 0 }
+	if ($mode eq 'all') { $switch{'gui'} = 1; $switch{'cli'} = 1 }
 }
 
 
-sub note {
-	return unless $global_switch;
-	say message( @_ ) if $CLI_switch;
+sub message {
+	return unless $switch{'global'};
+	my $msg = msg_text( @_ );
+	say message( @_ ) if $switch{'cli'};
 }
 
 sub warning {
-	return unless $global_switch;
-	my $msg = message( @_ );
-	warn $msg if $CLI_switch;
-	Kephra::API::output('warn', $msg) if $GUI_switch;
+	return unless $switch{'global'};
+	my $msg = msg_text( @_ );
+	warn $msg if $switch{'cli'};
+	#Kephra::API::output('warn', $msg) if $switch{'gui'};
 }
 
 sub error {
-	return unless $global_switch;
-	my $msg = message( @_ );
-	die $msg if $CLI_switch;
-	Kephra::API::output('warn', 'ERROR: '.$msg) if $GUI_switch;
+	return unless $switch{'global'};
+	my $msg = msg_text( @_ );
+	die $msg if $switch{'cli'};
+	#Kephra::API::output('warn', 'ERROR: '.$msg) if $switch{'gui'};
 }
 
-sub message     { 
+sub msg_text{ 
 	my ($text, $name_parent) = @_;
 	my $msg = timestamp() . ' ' . calling_sub(3) . ': "'. $text.'"';
-	$msg .= ', when called by '. calling_sub(3+$name_parent) if $name_parent;
+	$msg .= ', when called by '. calling_sub(3 + $name_parent) if $name_parent;
 	return $msg;
 }
+
 sub timestamp   { sprintf("[%02u:%02u:%02u]", (localtime)[2,1,0]) }
 sub calling_sub { ( caller($_[0]) )[3] } 
 

lib/Kephra/IO/LocalFile.pm

 use Encode;
 use Encode::Guess;
 use File::Spec;
+use Kephra::API;
 
 package Kephra::IO::LocalFile;
 
 sub read {
 	my $file = normalize_path( shift );
 	my $encoding;
-	#return Kephra::Log::warning("can't load nonexising file") unless $file and -e $file;
-	#return Kephra::Log::warning("can't read $file") unless -r $file;
+	return warning("can't load nonexising file") unless $file and -e $file;
+	return warning("can't read $file") unless -r $file;
 	CORE::open my $FH, '<', $file;
 	binmode($FH);
 	my $content = do { local $/; <$FH> };
 sub write {
 	my ($file, $encoding, $content) = @_;
 	$file = normalize_path( $file );
-	#return Kephra::Log::warning("need a file path") unless $file;
-	#return Kephra::Log::warning("can't overwrite $file") if -e $file and not -w $file;
+	return warning("need a file path") unless $file;
+	return warning("can't overwrite $file") if -e $file and not -w $file;
 	CORE::open my $FH, "> :raw :encoding($encoding)", $file;
 	print $FH $content;
 }
 package SingleEdit;
 use Wx;
 use base qw(Wx::App);
-use Kephra::API qw(warn);
+use Kephra::API qw(warning);
 use Kephra::App::Dialog;
 use Kephra::App::Editor;
 use Kephra::IO::LocalFile;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.