1212
1313enum logType_s {
1414 _Default,
15- _LogToDir
15+ _LogToDir,
16+ _LogToDirSilent
1617}
1718
1819new logType_s: ca_log_type,
@@ -92,9 +93,12 @@ public _OnConfigsExecuted() {
9293
9394Register_CVars () {
9495 bind_pcvar_num (create_cvar (" ca_log_type" , " 1" ,
95- .description = fmt (" Log file type\n 0 = log to common amxx log file (logs/L*.log)\n 1 = log to plugins folder (logs/%s /[plugin name]/L*.log)" , LOG_FOLDER),
96+ .description = fmt (" Log file type\n \
97+ 0 = log to common amxx log file (logs/L*.log)\n \
98+ 1 = log to plugins folder (logs/%s /[plugin name]/L*.log)\n \
99+ 2 = silent log to plugins folder (logs/%s /[plugin name]/L*.log)" , LOG_FOLDER),
96100 .has_min = true , .min_val = 0 .0 ,
97- .has_max = true , .max_val = float (_LogToDir )
101+ .has_max = true , .max_val = float (_LogToDirSilent )
98102 ),
99103 ca_log_type
100104 )
@@ -209,30 +213,35 @@ public bool: native_CA_Log(const plugin_id, const argc) {
209213 return false
210214 }
211215
212- new msg[2048 ];
216+ new msg[2048 ]
213217 vdformat (msg, charsmax (msg), arg_msg, arg_format)
214218
215- new pluginName[32 ]
216- get_plugin (plugin_id, pluginName, charsmax (pluginName))
219+ new logsFile[PLATFORM_MAX_PATH]
217220
218- replace (pluginName, charsmax (pluginName), " .amxx" , " " )
221+ if (ca_log_type > _Default)
222+ {
223+ new pluginName[32 ]
224+ get_plugin (plugin_id, pluginName, charsmax (pluginName))
219225
220- new logsPath[PLATFORM_MAX_PATH]
221- formatex (logsPath, charsmax (logsPath), " %s /%s " , g_logsPath, pluginName)
226+ replace (pluginName, charsmax (pluginName), " .amxx" , " " )
222227
223- if (! dir_exists (logsPath)) {
224- mkdir (logsPath)
225- }
228+ new logsPath[PLATFORM_MAX_PATH]
229+ formatex (logsPath, charsmax (logsPath), " %s /%s " , g_logsPath, pluginName)
230+
231+ if (! dir_exists (logsPath)) {
232+ mkdir (logsPath)
233+ }
226234
227- new year, month, day
228- date (year, month, day)
235+ new year, month, day
236+ date (year, month, day)
229237
230- new logsFile[PLATFORM_MAX_PATH];
231- formatex (logsFile, charsmax (logsFile), " %s / %s __ %i - %02i - %02i .log " , logsPath, pluginName, year, month, day)
238+ formatex ( logsFile, charsmax (logsFile), " %s / %s __ %i - %02i - %02i .log " , logsPath, pluginName, year, month, day)
239+ }
232240
233241 switch (ca_log_type) {
234- case _LogToDir: log_to_file (logsFile, msg)
235- case _Default: log_amx (msg)
242+ case _LogToDir: log_to_file (logsFile, msg)
243+ case _Default: log_amx (msg)
244+ case _LogToDirSilent: log_to_file_ex (logsFile, msg)
236245 }
237246
238247 return true
@@ -251,7 +260,6 @@ public bool: native_CA_PlayerHasBlockedPlayer(const plugin_id, const argc) {
251260 return false
252261}
253262
254-
255263static GetLogsFilePath (buffer[], len = PLATFORM_MAX_PATH, const dir[] = " ChatAdditions" ) {
256264 get_localinfo (" amxx_logs" , buffer, len)
257265 strcat (buffer, fmt (" /%s " , dir), len)
@@ -366,3 +374,40 @@ static stock CmpVersions(const a[], const b[]) {
366374
367375 return countA - countB
368376}
377+
378+ stock log_to_file_ex (const filePath[], message[]) {
379+ new file
380+ new bool: firstTime = true
381+ new date[32 ]
382+
383+ format_time (date, charsmax (date), " % m/%d /% Y - % H:% M:%S " )
384+ static modName[15 ], amxVersion[15 ]
385+
386+ if (! modName[0 ]) {
387+ get_modname (modName, charsmax (modName))
388+ }
389+
390+ if (! amxVersion[0 ]) {
391+ get_amxx_verstring (amxVersion, charsmax (amxVersion))
392+ }
393+
394+ if ((file = fopen (filePath, " r" ))) {
395+ firstTime = false
396+ fclose (file)
397+ }
398+
399+ if (! (file = fopen (filePath, " at" ))) {
400+ log_error (AMX_ERR_GENERAL, " Can't open \" %s \" file for writing." , filePath)
401+ return PLUGIN_CONTINUE
402+ }
403+
404+ if (firstTime) {
405+ fprintf (file, " L %s : Log file started (file \" %s \" ) (game \" %s \" ) (amx \" %s \" )\n " , date, filePath, modName, amxVersion)
406+ }
407+
408+ fprintf (file, " L %s : %s \n " , date, message)
409+
410+ fclose (file)
411+
412+ return PLUGIN_HANDLED
413+ }
0 commit comments