PDA

View Full Version : Is this bad practice? timestamp logging


Garavel
29/01/2018, 01:31 PM
I'm thinking of making my log timestamps global. As in...

Currently every command has its own gettime and getdate.

if(strcmp(cmd, "/samp", true) == 0)
{
SendClientMessage(playerid, COLOR_WHITE, "SA:MP.");
new y, m, d;new h,mi,s;getdate(y,m,d);gettime(h,mi,s);
format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] SA:MP -> %s.",d,m,y,h,mi,s,sendername);
CommandLog(string);
}

I'm thinking of creating a 500ms timer that gets the time and date on global variables so I don't have to add the same ugly code everywhere...



new y, m, d;new h,mi,s;

SetTimer("timetimer", 500, 1);

public timetimer()
{
getdate(y,m,d);gettime(h,mi,s);
}



Is this bad practice? How do YOU do this? Any chance this might be any more inaccurate than it currently is? The only thing I can think of is the timer dying, then my logs would be pretty messed up.

Mugala
29/01/2018, 01:40 PM
I dont understand what do u want to make but you can use this CommandLog code at OnPlayerCommandText like thispublic OnPlayerCommandText(playerid, cmdtext[])
{
CommandLog(cmdtext[]);
if (strcmp(cmd,"/cmdname", true) == 0)
{
and not in every command.

wallee
29/01/2018, 01:43 PM
if you use a command processor like y_commands then you have a callback like this:

OnPlayerCommandReceived(playerid, cmdtext[], e_COMMAND_ERRORS:success)

so you only need your logging code once

iLearner
29/01/2018, 03:04 PM
Why don't you simply gettime() which gets Unix timestamp. And then either use a custom function or timestodate.inc and convert it into valid time / date format.

iKarim
29/01/2018, 06:11 PM
I'm thinking of making my log timestamps global. As in...


new y, m, d;new h,mi,s;

SetTimer("timetimer", 500, 1);

public timetimer()
{
getdate(y,m,d);gettime(h,mi,s);
}



Is this bad practice? How do YOU do this? Any chance this might be any more inaccurate than it currently is?


Yes it is, there's no need for a timer or global variables. Just append the timestamp in the string in CommandLog function itself before printing so no need for repetition. This can't be inaccurate still the timer with low interval is totally unnecessary for this task.