Easiest way to save to logs?
#1

Hello everyone, I have seen a few methods on how to save things to logs such as Kicks and Bans etcetera.

I would just like to know, what's the best method to do this?

For example.
If I was to save this to a log, so I could see what groups people had created after they typed /groupcreate.

What's the best way to do it?

pawn Код:
dcmd_groupcreate(playerid,params[])
{
    #pragma unused params
    if(group[playerid][gid] != -1) return SendClientMessage(playerid, COLOR_SANDYBROWN, "Leave your group with {FFFFFF}/groupleave{FF0000} before creating a new one!");
    if(strlen(params) > 49 || strlen(params) < 3) return SendClientMessage(playerid, COLOR_SANDYBROWN, "Usage: {FFFFFF}/groupcreate{FF0000} (Group name 3-50 characters)!");
    if(IsGroupTaken(params)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "Group name is already in use!");
    CreateGroup(params, playerid);
    return 1;
}
Thanks.
Reply
#2

Just use Logger("Insert Text here");
And it would all save to the same Log
pawn Код:
Logger(string[])
{
new entry[128];
format(entry, sizeof(entry), "%s\n", string);
new File:lFile = fopen("Logs/group.log", io_append);
hwrite(lFile, entry);
fclose(lFile);
}
Or add Log IDs and have multiple Logs such as
Logger("Insert Text here", 1);
Then it would be like this in the macro.

pawn Код:
Logger(string[], logid)
{
new entry[128];
format(entry, sizeof(entry), "%s\n", string);
if(logid == 1)
{
new File:lFile = fopen("Logs/group.log", io_append);
hwrite(lFile, entry);
fclose(lFile);
}
else if(logid == 2)
{
new File:lFile = fopen("Logs/death.log", io_append);
hwrite(lFile, entry);
fclose(lFile);
}
else if(logid == 3)
{
new File:lFile = fopen("Logs/admin.log", io_append);
hwrite(lFile, entry);
fclose(lFile);
}
return 1;
}
Reply
#3

What saving system do you use? If MySQL or SQLite, you can create a seperate table for these logs (for some reason, some people tend to cram all information in one table). Otherwise, a simple function would most likely suffice.
pawn Код:
stock WriteLog(path[], text[])
{
    new
        File:fHandle = fopen(path, io_append);

    if(!fHandle)
        return printf("[warning] Failed to open stream: %s", path), 0;

    fwrite(fHandle, text);
    fwrite(fHandle, "\r\n");
    fclose(fHandle);
    return 1;
}
Just wrote this from the top of my head, so don't know if it works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)