################################################## #written by Yevgen Muntyan muntyan@math.tamu.edu, 4-12-2005 # # to use, type: #Read("/home/wdj/gapfiles/logger.gap"); #StartLoggingTo("/home/wdj/gapfiles/logger_test1.log"); # # last modified 7-14-2006 (now checks if logging directory # exists - caused mysterious seg fault otherwise) ################################################ DeclareCategory( "IsOutputTextProxy", IsOutputTextStream ); DeclareRepresentation( "IsOutputTextProxyRep", IsComponentObjectRep, ["out", "func"] ); ## OutputTextProxy(real_stream, write_func) ## it creates an output stream which writes given text to real_stream ## using write_func OutputTextProxy := function( real_stream, write_func ) return Objectify( NewType(StreamsFamily, IsOutputTextProxy and IsOutputTextProxyRep ), rec(out := real_stream, func := write_func) ); end; InstallMethod( PrintObj, "output text proxy", true, [IsOutputTextProxyRep], function( obj ) Print( "OutputTextProxy( ", obj!.out, " )" ); end ); InstallMethod( WriteAll, [ IsOutputTextProxy and IsOutputTextProxyRep, IsList ], function( stream, string ) return stream!.func (stream!.out, string); end ); ####################################################################### StartLoggingTo := function(filename) local log_file, input_log, output_log; log_file := OutputTextFile (filename, false); input_log := OutputTextProxy (log_file, WriteAll); output_log := OutputTextProxy (log_file, ## this is the main function. it's not very good, but you got ## the idea function(stream, string) if string <> "gap> " then WriteAll(stream, "#"); WriteAll(stream, string); if not IsEmpty(string) and string[Length(string)] <> '\n' then WriteAll(stream, "\n"); fi; fi; return true; end); InputLogTo(input_log); OutputLogTo(output_log); end; ######################### added by wdj, 4-13-2005 ##################### # # For autologging (in linux *only*), # (1) Create the directory "/home/wdj/gapfiles/log" (of course, change # the path name "/home/wdj/gapfiles/" to what you like) # (2) Put the following 2 lines in your .gaprc file: # Read("/home/wdj/gapfiles/logger.gap"); # autologger(); # where the path name "/home/wdj/gapfiles/" is what you have in (1). # # That's it! Now every GAP command is automaticaly logged and filed by # date and time in the log subdirectory. # ###################################################################### autologger:=function() local now, logfile, gapfiles_path; gapfiles_path:="/home/wdj/computer_algebra/gapfi0les/"; ###### edit this to your path if not(IsDirectoryPath(gapfiles_path)) then Print("\n *** The logging path you specified does not exist, so autologging is turned off. ***\n \n"); break; fi; Exec("date > /tmp/now"); now:=StringFile("/tmp/now"); now:=ReplacedString(now,"\n",""); #Chomp now:=ReplacedString(now," ","-"); logfile:=Concatenation(gapfiles_path, "log/gaplog", now, ".log"); StartLoggingTo(logfile); end; ###### Added 4-19-2005 ###### Above function modified by Gary Zablackis ###### for use with windows machines with cygwin installation. autologger_win:=function() local now, logfile, gapfiles_path; gapfiles_path:="e:/math/gap4r4/work/"; ###### edit this to your path Exec("date > /tmp/now"); now:=StringFile("/tmp/now"); now:=ReplacedString(now,"\n",""); #Chomp now:=ReplacedString(now," ","-"); #if ARCH_IS_WINDOWS( ) then now:=ReplacedString(now,":",";"); #necessary for Windows #fi; logfile:=Concatenation(gapfiles_path, "log/gaplog", now, ".log"); StartLoggingTo(logfile); end;