AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Logging something without date/time (https://forums.alliedmods.net/showthread.php?t=117651)

Cader 02-03-2010 08:42

Logging something without date/time
 
Hello,

I use log_to_file() function like everyone to log something to log file. But when you take a look at to my log file it really looks complicated because of those date/time values. Is it possible to log something without date and time of the action?

fysiks 02-03-2010 13:29

Re: Logging something without date/time
 
You can manually write to a file. Or, you can just learn to ignore the timestamp.

Exolent[jNr] 02-03-2010 13:51

Re: Logging something without date/time
 
Code:
log_to_file_notime( const szFilename[ ], const szLogFormat[ ], any:... ) {     static szLog[ 1024 ];     vformat( szLog, 1023, szLogFormat, 3 );         static szNewFilename[ 128 ];     if( contain( szFilename, "/" ) > 0 ) {         copy( szNewFilename, 127, szFilename );     } else {         formatex( szNewFilename, 127, "addons/amxmodx/logs/%s", szFilename );     }         static szPluginFile[ 64 ], szTrash[ 2 ];     get_plugin( -1, szPluginFile, 63, szTrash, 1, szTrash, 1, szTrash, 1, szTrash, 1 );         new iFile = fopen( szNewFilename, "a+" );     fprintf( iFile, "[%s] %s^n", szPluginFile, szLog );     fclose( iFile );         return 1; }

ConnorMcLeod 02-04-2010 00:57

Re: Logging something without date/time
 
Rather than convert log_to_file, it would be better do use a custom function, like cache the file path in a global var so you only need to retrieve it once, and also, when you use a specific file, that file could also be plugin specific, so there is no need to add again the plugin name in the log.

PHP Code:

#include <amxmodx>

const MAX_LOG_LENGTH 256

new g_szLogFile[64// addons/amxmodx/logs/ = 20

public plugin_init()
{
    
get_localinfo("amxx_logs"g_szLogFilecharsmax(g_szLogFile))
    
add(g_szLogFilecharsmax(g_szLogFile), "/your_log_file.log")
}

LogToFile(const fmt[], any:...)
{
    new 
szLog[MAX_LOG_LENGTH]
    
vformat(szLogcharsmax(szLog), fmt2)

    new 
fp fopen(g_szLogFile"at")
    
fprintf(fp"%s^n"szLog)
    
fclose(fp)



Then you can do :

LogToFile("%s has killed %s", szKillerName, szVictimName)


All times are GMT -4. The time now is 07:27.

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