SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/08/2019, 07:52 PM   #1
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 515
Reputation: 18
Default Server logs

Hello, i'm here to ask something that hope i can be helped about.

I'm about to create a log system which will store everything (from chat to deaths and so on), but i wanna categorize them in dates.

I mean imagine i have a "serverlogs" folder in /scriptfiles, how i can automatically create a server log txt file each day?

Something like:

27062019.txt
28062019.txt

And so on.
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 27/08/2019, 07:59 PM   #2
Jonny
Huge Clucker
 
Jonny's Avatar
 
Join Date: Nov 2009
Location: Italy
Posts: 284
Reputation: 38
Default Re: Server logs

You can simply save the files using a format with those functions:
https://wiki.sa-mp.com/wiki/Gettime
https://wiki.sa-mp.com/wiki/Getdate

Example:
Code:
new Year, Month, Day, Hour, Minute, Second,string[30];
getdate(Year, Month, Day);
gettime(Hour, Minute, Second);
format(string,sizeof(string),"%02d-%02d-%d - %02d:%02d.log",Day,Month,Year,Hour,Minute);
new File:f = fopen(string, io_append);
if(!f) dini_Create(f); 
//fwrite, then fclose
(I haven't tested it but it's an example code so, you can figure out how to make it by yourself)
__________________

Last edited by Jonny; 28/08/2019 at 01:40 AM. Reason: Added example code
Jonny is offline   Reply With Quote
Old 27/08/2019, 09:23 PM   #3
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 515
Reputation: 18
Default Re: Server logs

I know how to create logs, my question was another...
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 27/08/2019, 09:42 PM   #4
TomatoRage
Big Clucker
 
TomatoRage's Avatar
 
Join Date: Mar 2013
Location: Israel
Posts: 193
Reputation: 6
Default Re: Server logs

You can create one (if it doesnt exist) OnGameModeInit and have a timer every min to check if the the day changed (by comparing getdate return each time) when it changes make a timer for 24 hours
__________________
I can script for you, bugs, gamemodes, addons you name it. Hit me up
Click On Me Please
TomatoRage is offline   Reply With Quote
Old 27/08/2019, 10:15 PM   #5
YouShootIDodge
Little Clucker
 
Join Date: May 2019
Posts: 42
Reputation: 11
Default Re: Server logs

Create a variable to store the day (using getdate ofc):

Code:
new current_day;
Now whenever you while logs compare the day:

Code:
getdate(Year, Month, Day);

if (Day != current_day)
{
    // create new file and update the current_day variable
}
else
{
    // append in the current file
}
YouShootIDodge is offline   Reply With Quote
Old 28/08/2019, 12:19 AM   #6
Jonny
Huge Clucker
 
Jonny's Avatar
 
Join Date: Nov 2009
Location: Italy
Posts: 284
Reputation: 38
Default Re: Server logs

Quote:
Originally Posted by KeyOfKey View Post
I know how to create logs, my question was another...
If you know how to create logs i provided you the functions you should use to make your own system, also, you must read it better, it actually makes a file for every minute, since you just want to be it per day you could just write Day - Month - Year, it was pretty simple
The example i've shown to you was almost complete, if you don't even dare to edit a single thing why are you here? You might receive help, but it seems like you want the full script already made to plug and play

There you go lazy boy
Code:
new Year, Month, Day,string[30];
getdate(Year, Month, Day);
format(string,sizeof(string),"%02d-%02d-%d",Day,Month,Year);
new File:f = fopen(string, io_append);
if(!f) dini_Create(f); 
fwrite(f, "Blablablabla");
fclose(f);
This checks if filename is CURRENT Day-Month-Year, so the next day it won't exist and it will automatically create another since DAY would be different.
__________________

Last edited by Jonny; 28/08/2019 at 12:51 AM.
Jonny is offline   Reply With Quote
Old 28/08/2019, 12:58 AM   #7
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 515
Reputation: 18
Default Re: Server logs

I don't want a plug&play code but nvm, thanks.

So i should unify your code with @YouShootIDoodge's one to automatically create logs everyday?
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 28/08/2019, 01:02 AM   #8
Kane
Gangsta
 
Kane's Avatar
 
Join Date: Sep 2012
Posts: 814
Reputation: 123
Default Re: Server logs

You're overthinking it. This is fairly easy.

Example code:

pawn Code:
_lSys_TimeStamp( )
{
    new pDate[ 50 ];
    new hour,   minute, second,
        day,    month,  year;
    getdate( year, month, day );
    gettime( hour, minute, second );
    format( pDate, sizeof( pDate ),"%02d/%02d/%02d - %02d:%02d:%02d",
    day, month, year, hour, minute, second );
    return pDate;
}

_lSys_DayMStamp()
{
    new pDate[ 30 ];
    new day,    month,  year;
    getdate( year, month, day );
    format( pDate, sizeof( pDate ),"%02d-%02d-%02d",
    day, month, year );
    return pDate;
}

/*
*   ServerLog
*
*   ServerLog creates a text file for the current month, date, year for every print and log.
*   For example: All of the chat-commands recorded via print will be stored in a text log file that,
*   would be called "01-12-2018 - server_log.txt".
*   This is basically creating a new server_log for each new day in scriptfiles/
*/

 
stock ServerLog(console_print, const str[], {Float,_}:...)
{
    static
        args,
        start,
        end,
        File:file,
        string[1024]
    ;
    format( string, 128, "%s - server_log.txt", _lSys_DayMStamp() );
    if( !fexist( string ) ) {
        file = fopen( string, io_write );
    } else {
        file = fopen( string, io_append );
    }
 
    #emit LOAD.S.pri 8
    #emit STOR.pri args
 
    if (!file) {
        printf( "ServerLog couldn't open path: \"%s\".", string );
        return 0;
    }
 
    if (args > 8)
    {
        #emit ADDR.pri str
        #emit STOR.pri start
 
        for (end = start + (args - 8); end > start; end -= 4)
        {
            #emit LREF.pri end
            #emit PUSH.pri
        }
        #emit PUSH.S str
        #emit PUSH.C 1024
        #emit PUSH.C string
        #emit PUSH.C args
        #emit SYSREQ.C format
 
        format( string, 1024, "[%s] %s", _lSys_TimeStamp(), string );
        if(console_print) {
            print( string );
        }
        fwrite(file, string);
        fwrite(file, "\r\n");
        fclose(file);
 
        #emit LCTRL 5
        #emit SCTRL 4
        #emit RETN
    }
    new stringtwo[1024];
    format( stringtwo, 1024, "[%s] %s", _lSys_TimeStamp(), str );
    if(console_print){
        print( stringtwo );
    }
    fwrite(file, stringtwo);
    fwrite(file, "\r\n");
    fclose(file);
 
    return 1;
}

Example usage:

pawn Code:
ServerLog(1, "Player %d connected to the server. Their name is: %s", playerid, GetPlayerName(playerid));

You can remove console_print and edit the function if you'd like as it's pretty useless. You should just print every log.
__________________
Los Santos Roleplay - Developer
@ls-rp.io

Former Beta Tester
Kane is offline   Reply With Quote
Old 28/08/2019, 01:34 AM   #9
Jonny
Huge Clucker
 
Jonny's Avatar
 
Join Date: Nov 2009
Location: Italy
Posts: 284
Reputation: 38
Default Re: Server logs

Quote:
Originally Posted by KeyOfKey View Post
I don't want a plug&play code but nvm, thanks.

So i should unify your code with @YouShootIDoodge's one to automatically create logs everyday?
No, you had to create a function with the code i just provided, without unifying, of course you just needed to change the fwrite, but seems like you don't want to collaborate.
Anyway, use the solution that @Kane provided to you but next time try to figure out the way to do it by yourself, you already said that you're able to make your own logs but you just needed to figure out how to put dates on file name, but you needed the full code instead so i'm assuming you weren't able to.

I don't wanna make any drama but you should be clear on what you need and try to understand how to work with the things people provides to you, be more accurate in reading what's into the code and how it could work, this is the only way if you really wanna learn
If everyone always gives you the full code and you just put it into the gamemode, you'll never learn from it

I hope it could give you some more reasons to improve yourself by trying and trying until you discover the way to do the scripts you want to make
__________________
Jonny is offline   Reply With Quote
Old 28/08/2019, 01:42 PM   #10
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 515
Reputation: 18
Default Re: Server logs

Thanks Kane, another question:

Do i have to call _lSys_TimeStamp or _lSys_DayMStamp to automatically generate a server log txt everyday?
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Server logs BOyka1 Scripting Help 1 10/01/2019 10:17 AM
server logs.. div Scripting Help 2 28/06/2018 03:48 PM
flooding in the server logs Test_Test has left the server (0:2) Marcid Scripting Help 5 23/03/2014 07:32 PM
Which is the best way to save chat logs/command logs, etc? BlackAnt Scripting Help 6 27/02/2014 10:09 PM


All times are GMT. The time now is 10:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.