Raised This Month: $ Target: $400
 0% 

Check log for specific words


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BeasT
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 08-19-2009 , 13:34   Check log for specific words
Reply With Quote #1

I need to check my log file that is placed in amxmodx/logs for specific words (actualy I need to check if the map, that is being currently played, name is written in the log). And if the log contains the map name than do nothing, and if doesn't contain - do something. And one more thing: the code should 'understand' the diffrence between de_dust and de_dust2 (these two are 'diffrent words').
BeasT is offline
Send a message via Skype™ to BeasT
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-19-2009 , 13:47   Re: Check log for specific words
Reply With Quote #2

You need :

- open_dir() : To open the directory wanted.
- next_file() : To read the next file in the directory handle.
- fopen() / fgets() / fclose() : To open the file, reading each line, and closing the file.

And while reading each line, you would need to use something like contain().
But depending what you need to find, you may want to try regex.
__________________
Arkshine is offline
BeasT
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 08-19-2009 , 15:01   Re: Check log for specific words
Reply With Quote #3

I don't understand, need example
BeasT is offline
Send a message via Skype™ to BeasT
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-19-2009 , 15:57   Re: Check log for specific words
Reply With Quote #4

Here ->
PHP Code:
stock CheckForString(const szDir[16], const szFile[16], const szString[])
{
    new 
szLocalDir[32];
    
get_localinfo("amx_basedir"szLocalDircharsmax(szLocalDir));
    new 
szPath[64];
    
formatex(szPathcharsmax(szPath), "%s/%s/%s"szLocalDirszDirszFile);
    
    new 
iFile fopen(szPath);
    if(!
iFile)
        return 
0;
    
    new 
szBuffer[128];
    while(!
feof(iFile))
    {
        
fgets(iFileszBuffercharsmax(szBuffer));
        if(!
szBuffer[0])
            continue;
        
        if(
containi(szBufferszString) != -1)
        {
            
fclose(iFile);
            return 
1;
        }
    }
    
fclose(iFile);
    return 
0;

Just use CheckForString("logs", "somefile.log", "searched_string") , returns 0 if file not exists or string wasn't found else returns 1
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 08-19-2009 at 17:00.
Alka is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-19-2009 , 16:21   Re: Check log for specific words
Reply With Quote #5

Damn I've read too fastly. I've confused with another plugin which read files in a specific directory.
__________________
Arkshine is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-19-2009 , 17:00   Re: Check log for specific words
Reply With Quote #6

Hey onion!
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
BeasT
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 08-19-2009 , 17:41   Re: Check log for specific words
Reply With Quote #7

Thx Alka!
BeasT is offline
Send a message via Skype™ to BeasT
Reply



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 12:29.


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