Logging tools

new topic     » topic index » view thread      » older message » newer message

Forked from Re: Coding practice for better user-proofing

petelomax said...

Another trick I've started using recently is along the lines of logMsg("pemit2.e line 1443, ...").
Obviously the 1443 gets out-of-date pretty quickly, but you can easily search for it, in the right file.
Helps me out a lot on big complex apps when messages start appearing weeks or months after I added them.
The examples given are fine for debugging a single routine, but not really the whole process.

Pete

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() - ", 
        {__DATE__,__TIME__,__LEVEL__, 
        __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 ) 
     
    maybe_any_key() 
     
end procedure 
 
main() 

> 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 

-Greg

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu