Original date:2015-05-13 13:34:12 Edited by: ghaberek Subject: Logging tools

Forked from Re: Coding practice for better user-proofing

irv said...

Some programming languages (I forget which ones at the moment) have a way to include the current line number in an error message. So your error lines could read printf(1,"Error in line ..."), using some variable containing the current line #. I wonder if such a capability could be added to Eu?

Hm... the thought occurs to me that crash() already has that information. Maybe that would be a starting point for writing such a routine.

Euphoria 4.1 includes some new debugging tools, which includes a call_stack() function for some basic code introspection.

I've written some additional logging tools to provide some more modular logging. Perhaps it can be included in the 4.1 release.

This code will also work with 4.0, but for obvious reasons the call stack macros will not be parsed.

Code is here, complete with documentation: Logging tools

-- demo.ex 
include std/console.e 
include std/logging.e 
include std/io.e 
procedure main() 
    integer test_log = open( "demo.log", "w" ) 
    set_log_header( "%s %s %s %s:%s %s() - ", 
        __FILE__,__LINE__,__ROUTINE__} ) 
    set_log_output({ STDOUT, test_log }) 
    set_log_level( LOG_VERBOSE ) 
    write_log( LOG_SILENT, "zero" ) 
    write_log( LOG_SEVERE, "one" ) 
    write_log( LOG_ERRORS, "two" ) 
    write_log( LOG_WARNING, "three" ) 
    write_log( LOG_VERBOSE, "four" ) 
    close( test_log ) 
end procedure 

> eui demo.ex 
2015/05/13 13:31:15 LOG_SILENT demo.ex:17 main() - zero 
2015/05/13 13:31:15 LOG_SEVERE demo.ex:18 main() - one 
2015/05/13 13:31:15 LOG_ERRORS demo.ex:19 main() - two 
2015/05/13 13:31:15 LOG_WARNING demo.ex:20 main() - three 
2015/05/13 13:31:15 LOG_VERBOSE demo.ex:22 main() - four 


Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu