Thread: [Solved] Generate file depend date
View Single Post
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 03-10-2022 , 12:34   Re: Generate file depend date
Reply With Quote #4

That's because you're doing it only in OnPluginStart which is called only once after server start or when you (re)load the plugin manually.
You should rebuild the path at least in OnMapStart which is called after every map change.
The better way is to create a repeating timer (for example, with interval of 1 minute) and rebuild path in timer's callback.
And the best way is to rebuild path before every LogToFile call which is slightly unoptimized but still fast enough.

Code:
stock void LogToDateFile(const char[] message, any ...) {
    char sMessage[512];
    VFormat( sMessage, sizeof sMessage, message, 2 );

    char sTime[12], sPath[PLATFORM_MAX_PATH];
    FormatTime( sTime, sizeof sTime, "%F", GetTime() );
    BuildPath( Path_SM, sPath, sizeof sPath, "logs/test/custom_%s.log", sTime );
    LogToFile( sPath, "%s", sMessage );
}
In this case you don't need g_sPath and can just call LogToDateFile every time.
__________________

Last edited by MAGNAT2645; 03-10-2022 at 12:42.
MAGNAT2645 is offline