Raised This Month: $32 Target: $400
 8% 

Monthly log file instead of writing to log_to_file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fatal_nl
Member
Join Date: Apr 2017
Old 05-17-2019 , 04:56   Monthly log file instead of writing to log_to_file
Reply With Quote #1

With log_to_file I have to clear the log by hand once a month because the file is getting too big.

Is there a replacement that generates a new logfile each month? Preferably with the month/year added to the file name.

Last edited by fatal_nl; 05-17-2019 at 04:57.
fatal_nl is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-17-2019 , 07:50   Re: Monthly log file instead of writing to log_to_file
Reply With Quote #2

Simply add the month in the filename. E.g.: log_file_05_2019.log
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-17-2019 , 08:16   Re: Monthly log file instead of writing to log_to_file
Reply With Quote #3

yeah like OciXCrom told you...search for get_time (, formatex, ..)
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
fatal_nl
Member
Join Date: Apr 2017
Old 05-17-2019 , 20:43   Re: Monthly log file instead of writing to log_to_file
Reply With Quote #4

Edit: now with formatex instead of format.

I hope this attempt works (it's a stripped down version I'm now testing with to write monthly log files, I removed the /allinfo command):

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <geoip>

new szName[32]
new 
szIP[20]
new 
szID[32]
new 
szCountry[40]

public 
plugin_init()
{
    
register_plugin("AllinfoIP""1.11""fatal")
}

public 
client_connect(id)
{
    new 
iCurrentMonthYear[8]
    new 
szLogFile[32]
    
get_time("%m_%Y"iCurrentMonthYear7)
    
    
formatex(szLogFile31"allinfo_players_%s.txt"iCurrentMonthYear)
    
    
get_user_name(idszName31)
    
get_user_authid(idszID31)
    
get_user_ip(idszIP191)
    
geoip_country(szIPszCountry39)
    
    if (!
is_user_bot(id))
    {
        
log_to_file(szLogFile"     %s  |  %s  |  %s  |  %s"szNameszIPszIDszCountry)
    }
    
    return 
PLUGIN_HANDLED


Last edited by fatal_nl; 05-17-2019 at 21:28.
fatal_nl is offline
fatal_nl
Member
Join Date: Apr 2017
Old 05-21-2019 , 20:09   Re: Monthly log file instead of writing to log_to_file
Reply With Quote #5

Another question:

What is more effecient?

Putting this into client_connect:

PHP Code:
new iCurrentMonthYear[8]
new 
szLogFile[32
Or add it outside of it. These 2 are only used in client_connect. The other 4 "new" (how do you call this exactly) are placed outside of it because they're going to be used in more functions.

Last edited by fatal_nl; 05-21-2019 at 20:10.
fatal_nl is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 05-21-2019 , 21:33   Re: Monthly log file instead of writing to log_to_file
Reply With Quote #6

Quote:
Originally Posted by fatal_nl View Post
Another question:

What is more effecient?

Putting this into client_connect:

PHP Code:
new iCurrentMonthYear[8]
new 
szLogFile[32
Or add it outside of it. These 2 are only used in client_connect. The other 4 "new" (how do you call this exactly) are placed outside of it because they're going to be used in more functions.
make a global variable that will save the string name for the logfile, in plugin_init you can either create a function or just do the code to get the date for the logfile string, then you can reference the global variable for the filename when using your log_to_file
__________________
+|- KARMA Respectively

HLM is offline
fatal_nl
Member
Join Date: Apr 2017
Old 05-22-2019 , 05:40   Re: Monthly log file instead of writing to log_to_file
Reply With Quote #7

Below is my code with another update (writing logs in seperate folder). I don't know exactly what I can move to plugin_init and what should be kept in client_connect. Keeping in mind that the server can be started on the last day of the month and a player connects on the first day of a new month. Then it should write to a new log file.

Code:
#include <amxmodx> #include <amxmisc> #include <geoip> new szName[32], szIP[17], szID[25], szCountry[41] public plugin_init() {     register_plugin("AllinfoIP", "1.12b", "fatal") } public client_connect(id) {     new AmxxLogsDir[20], LogFilesDir[28], LogFileName[28], LogFile[56]         get_localinfo("amxx_logs", AmxxLogsDir, charsmax(AmxxLogsDir))         formatex(LogFilesDir, charsmax(LogFilesDir), "%s/allinfo", AmxxLogsDir)         if(!dir_exists(LogFilesDir))         mkdir(LogFilesDir)         get_time("allinfo_players_%m_%Y.txt", LogFileName, charsmax(LogFileName))         formatex(LogFile, charsmax(LogFile), "%s/%s", LogFilesDir, LogFileName)         get_user_name(id, szName, charsmax(szName))     get_user_authid(id, szID, charsmax(szID))     get_user_ip(id, szIP, charsmax(szIP), 1)     geoip_country(szIP, szCountry, charsmax(szCountry))         if (!is_user_bot(id))     {         log_to_file(LogFile, "     %s  |  %s  |  %s  |  %s", szName, szIP, szID, szCountry)     }         return PLUGIN_HANDLED }

And this is the complete code with some of your suggestion implemented if I understood what you meant. I need confirmation from a more experienced coder if I did this right:

Code:
#include <amxmodx> #include <amxmisc> #include <geoip> #define ADMIN ADMIN_LEVEL_G  // Custom admin level new AmxxLogsDir[20], LogFilesDir[28], LogFileName[28], LogFile[56], iPlayers[32], iPlayerNum, szName[32], szIP[17], szID[25], szCountry[41] public plugin_init() {     register_plugin("AllinfoIP", "1.12b", "fatal")     register_concmd("amx_allinfo", "cmd_allinfo", ADMIN, "- All info..")         get_localinfo("amxx_logs", AmxxLogsDir, charsmax(AmxxLogsDir))         formatex(LogFilesDir, charsmax(LogFilesDir), "%s/allinfo", AmxxLogsDir)         if(!dir_exists(LogFilesDir))         mkdir(LogFilesDir) } public client_connect(id) {     get_time("allinfo_players_%m_%Y.txt", LogFileName, charsmax(LogFileName))         formatex(LogFile, charsmax(LogFile), "%s/%s", LogFilesDir, LogFileName)         get_user_name(id, szName, charsmax(szName))     get_user_authid(id, szID, charsmax(szID))     get_user_ip(id, szIP, charsmax(szIP), 1)     geoip_country(szIP, szCountry, charsmax(szCountry))         if (!is_user_bot(id))     {         log_to_file(LogFile, "     %s  |  %s  |  %s  |  %s", szName, szIP, szID, szCountry)     }         get_players(iPlayers, iPlayerNum)         for (new i = 0; i < iPlayerNum; i++)     {         if (access(iPlayers[i], ADMIN))         {             if (!is_user_bot(id))             {                 client_print(iPlayers[i], print_chat, "%s connected :  %s : %s : %s", szName, szID, szIP, szCountry)             }             else             {                 client_print(iPlayers[i], print_chat, "%s connected :  %s", szName, szID)             }         }     }         return PLUGIN_HANDLED } public client_disconnect(id) {     get_user_name(id, szName, charsmax(szName))     get_user_authid(id, szID, charsmax(szID))     get_user_ip(id, szIP, charsmax(szIP), 1)     get_players(iPlayers, iPlayerNum)         for (new i = 0; i < iPlayerNum; i++)     {         if (access(iPlayers[i], ADMIN))         {             if (!is_user_bot(id))             {                 client_print(iPlayers[i], print_chat, "%s disconnected :  %s : %s", szName, szID, szIP)             }             else             {                 client_print(iPlayers[i], print_chat, "%s disconnected :  %s", szName, szID)             }         }     }         return PLUGIN_HANDLED } public cmd_allinfo(id, level, cid) {     if (!cmd_access(id, level, cid, 1))     {         console_print(id, "You have no access to this command!")                 return PLUGIN_HANDLED     }         get_players(iPlayers, iPlayerNum, "ch")         for (new i = 0; i < iPlayerNum; i++)     {         get_user_name(iPlayers[i], szName, charsmax(szName))         get_user_ip(iPlayers[i], szIP, charsmax(szIP), 1)         get_user_authid(iPlayers[i], szID, charsmax(szID))         geoip_country(szIP, szCountry, charsmax(szCountry))                 console_print(id, "%s  |  %s  |  %s  |  %s", szName, szIP, szID, szCountry)     }         return PLUGIN_HANDLED }

Last edited by fatal_nl; 05-22-2019 at 06:11. Reason: Adding additional code
fatal_nl is offline
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

Forum Jump


All times are GMT -4. The time now is 05:28.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode