Author Topic: /var/log type logging for scripts  (Read 1951 times)

Windlord

  • Guest
/var/log type logging for scripts
« on: April 27, 2011, 08:15:55 pm »
Code: (squirrel) [Select]
DEBUG <- true;

// Function to add timestamps to debug messages
function debug ( msg )
{
// Check if debug is turned on
if ( !DEBUG ) return false;
else
{
// Get date data table
local dt = date();
local timestamp = format( "%02i/%02i %02i:%02i:%02i", dt.day, dt.month, dt.hour, dt.min, dt.sec );
msg = timestamp +" :: "+ msg;

// Initiate file stream if not already done
if ( !getroottable().rawin( "DEBUG_STREAM" ) )
{
DEBUG_STREAM <- file( "debug.log", "a" );
debug_newline();
}

// Write debug message to file stream
foreach ( idx, chr in msg )
DEBUG_STREAM.writen( chr, 'b' );

// Write newline to make debug.log readable
debug_newline();

print( "\r"+ msg );
return true;
}
}


function debug_newline ()
{
DEBUG_STREAM.writen( '\r', 'b' );
DEBUG_STREAM.writen( '\n', 'b' );
}

This code allows you to do a:
Code: (bash) [Select]
tail -f debug.logas you can do with Linux log files located in /var/log
« Last Edit: April 29, 2011, 08:57:50 am by Windlord »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: /var/log type logging for scripts
« Reply #1 on: April 27, 2011, 11:21:38 pm »
ow looks very smexy <3

Windlord

  • Guest
Re: /var/log type logging for scripts
« Reply #2 on: April 28, 2011, 02:40:15 am »
Thanks Thijn :)

Cleaned it up a bit and made the output use CRLF for Windows-friendliness...

 

© Liberty Unleashed Team.