Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Top Logger

Top Tank
Wasted Jack
Join date: 5 Dec 2005
Posts: 12
04-20-2006 08:37
This is my generic "Top Logger" script. It collects log messages (strings), stores them in a fixed-size list along with SLT timestamps, and displays them on command.

Top Logger is a service provider script which needs to be called from your main script using llMessageLinked (see header for usage notes).

The total size of the log buffer is determined by the MAX_LOG_SIZE constant. The default is 25 lines but if your messages are relatively short you can increase it.

Currently, the dumpLog() function uses llOwnerSay() so only the owner will see the log data. I chose this method because llOwnerSay has no time penalties and typically only the owner can access this data, but if you need other people to be able to read the log, just change from llOwnerSay to llWhisper or llSay.

CODE

// Top Logger by Top Tank
//
/////////////////////////////////////////////////////
//
// To use, drop this script into your root prim and copy the following lines to your main script's Constants section:
//
// integer LOG_RESET = 2323;
// integer LOG_INIT = 2324;
// integer LOG_DUMP = 2325;
// integer LOG_LOG = 2326;
//
// Add the following line to your main script init() function:
//
// llMessageLinked(LINK_THIS, LOG_INIT, "", NULL_KEY);
//
// Add the following line to your main script reset() function:
//
// llMessageLinked(LINK_THIS, LOG_RESET, "", NULL_KEY);
//
// To log the message "Hello World" from your main script, do:
//
// llMessageLinked(LINK_THIS, LOG_LOG, "Hello World", NULL_KEY);
//
// To dump the log contents to the screen, use:
//
// llMessageLinked(LINK_THIS, LOG_DUMP, "", NULL_KEY);
//
/////////////////////////////////////////////////////
//
// Constants
string PRODUCT_NAME = "Top Logger";
string PRODUCT_VERSION = "1.01";

integer MAX_LOG_SIZE = 25;

integer LOG_RESET = 2323;
integer LOG_INIT = 2324;
integer LOG_DUMP = 2325;
integer LOG_LOG = 2326;

// Global Variables
list g_lActivityLog;

init()
{
g_lActivityLog = [];
}

dumpLog()
{
integer i;
integer iLogSize = llGetListLength(g_lActivityLog);

for (i = 0; i < iLogSize; i++)
{
llOwnerSay(llList2String(g_lActivityLog, i));
}
}

log(string sMessage)
{
// If the log buffer is full, delete the oldest record.
// This operation temporarily copies the entire log to another area in memory so the total log size (in bytes) should not exceed half of the available memory.
if (llGetListLength(g_lActivityLog) >= MAX_LOG_SIZE)
g_lActivityLog = llDeleteSubList(g_lActivityLog, 0, 0);

g_lActivityLog += getSLTDate() + " " + getSLTTime() + " " + sMessage;
}

string getSLTTime()
{
integer iTime = (integer)llGetWallclock(); ;
string sTime = "";

integer iHours;
integer iMinutes;
integer iSeconds;

iHours = iTime / 3600;
iMinutes = (iTime % 3600) / 60;
iSeconds = iTime % 60;

if (iHours < 10)
sTime = "0";
sTime += (string)iHours + ":";

if (iMinutes < 10)
sTime += "0";
sTime += (string)iMinutes + ":";

if (iSeconds < 10)
sTime += "0";
sTime += (string)iSeconds;

return sTime;
}

string getSLTDate()
{
string sDateToday = "";
string sDate = llGetDate();

if (llGetGMTclock() - llGetWallclock() < 0)
{
integer iYear = (integer)llGetSubString(sDate, 0, 3);
integer iMonth = (integer)llGetSubString(sDate, 5, 6);
integer iDay = (integer)llGetSubString(sDate, 8, 9);

if (iDay == 1) // if day is the 1st of a month, fix the date
{
if (iMonth == 1) // if it is January
{
iYear--;
iMonth = 12;
iDay = 31;
}
else
{
iMonth--;
if(iMonth == 2)
iDay = 28 + !(iYear % 4) - !(iYear % 100) + !(iYear % 400);
else
iDay = 30 + (iMonth == 5 || iMonth == 7 || iMonth == 10 || iMonth == 12);
}
}
else
iDay--;

if(iMonth < 10)
sDateToday = "0";

sDateToday += (string)iMonth + "-";

if(iDay < 10)
sDateToday += "0";

sDateToday += (string)iDay;

sDate = (string)iYear + "-" + sDateToday;
}

return sDate;
}

default
{
link_message(integer iSender, integer iIntegerParam, string sStringParam, key kKeyParam)
{
if (iIntegerParam == LOG_RESET)
{
llResetScript();
}
else
if (iIntegerParam == LOG_INIT)
{
init();
}
else
if (iIntegerParam == LOG_DUMP)
{
dumpLog();
}
else
if (iIntegerParam == LOG_LOG)
{
log(sStringParam);
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
04-22-2006 07:24
/54/07/101978/1.html
_____________________
i've got nothing. ;)
Hillary Melville
Emotionally Anarchic
Join date: 5 Jun 2005
Posts: 16
04-23-2006 16:08
Top Tank,

It looks like you took your getSLTDate() function from the example given in the Wiki for llGetDate() (http://secondlife.com/badgeo/wakka.php?wakka=llGetDate). There was a bug in the line that corrects the dates when they need to be rolled back. I fixed the example in the Wiki a little while back.

the line that reads
iDay = 31 - (iMonth == 5 || iMonth == 7 || iMonth == 10 || iMonth == 12);

should read
iDay = 30 + (iMonth == 5 || iMonth == 7 || iMonth == 10 || iMonth == 12);