Jump to content

Recommended Posts

Right so I want to parse a ascii log generated by EQ2 and do some statistics etc on the resulting data.

A snip from the log file looks as follows:

[code]
(1140157349)[Fri Feb 17 06:22:29 2006] Logging to 'logs/ServerName/eq2log_Character.txt' is now *ON*
(1140157367)[Fri Feb 17 06:22:47 2006] You start fighting.
(1140157367)[Fri Feb 17 06:22:47 2006] YOU hit a Bitterwind pioneer for 126 points of piercing damage.
(1140157370)[Fri Feb 17 06:22:50 2006] a Bitterwind pioneer's Ball of Fire hits YOU for 260 points of heat damage.
(1140157375)[Fri Feb 17 06:22:55 2006] a Bitterwind pioneer hits YOU for 91 points of crushing damage.
(1140157377)[Fri Feb 17 06:22:57 2006] YOUR Crushing Anvil hits a Bitterwind pioneer for 89 points of crushing damage.
(1140157423)[Fri Feb 17 06:23:43 2006] You have killed a Bitterwind pioneer.
(1140157423)[Fri Feb 17 06:23:43 2006] You stop fighting.
[/code]

There is alot of useless banter in amogst those lines as well but I don't need thos, so I cut them from the overview.

I need to do a few things with this file:
1. Extract that line that says "Logging to .....*ON*", and extract the "Character" from it (this changes depending on who is logged in).
2. Replace all the "YOU" and "YOUR" with the name of the person who is logged in.


I then need to fill 2 tables. 1 with the damage data, and one with the fight data. The fight table will be something like:
fight_id|start_time|end_time

The start time would be "1140157367" in the example above, so I need to grab the numeric between () at the start of the line that contains the text "You start fighting". The end time would be the numeric between () at the start of the line that contains the test "You stop fighting".

I'm havign some issues figuring out how to actually grab that number. Should I do some sort of rexexp that finds "You start fighting" and then drop the whole line except the numeric? Or are there better ways?

The other table with the damage would do a simular thing per line, splitting it up into the needed fields, so once I find a solution for the start/end of a fight I should be able to port that to the other data.

I know this is vague and has no code at all, but as I can't see how to start doing this I haven't started coding at all :(

I had a look at a BBCode editor I have written for another site, to see if I can adapt that. But appart from the way it handles the data - in this case from a from - by stuffing it into a variable and then converting parts, which could be used to replace You/Your, I don't see how this code helps me much...

Does anyone have a sugestion on how to go about this? Or a pointer at what docs I might want to read?

Link to comment
https://forums.phpfreaks.com/topic/3749-log-parsing/
Share on other sites

The following should search the log file and extract the character name, start time, and end time:

[code]<?php
$log = 'log.txt';
$lines = file($log);

foreach ($lines as $line) {
    if (preg_match('/eq2log_([A-Za-z0-9]+)\.txt/', $line, $matches)) {
        $characterName = $matches[1];
    }
    if (preg_match('/\bYou start fighting\b/', $line)) {
        if (preg_match('/^\([0-9]+\)/', $line, $matches)) {
            $startTime = preg_replace(Array('/\(/', '/\)/'), '', $matches[0]);
        }
    }
    if (preg_match('/\bYou stop fighting\b/', $line)) {
        if (preg_match('/^\([0-9]+\)/', $line, $matches)) {
            $endTime = preg_replace(Array('/\(/', '/\)/'), '', $matches[0]);
        }
    }
}

echo "Name: $characterName";
echo '<br>';
echo "Start Time: $startTime";
echo '<br>';
echo "End Time: $endTime";
?>[/code]
Not really sure about the rest, but this may get you pointed in the right direction...
Link to comment
https://forums.phpfreaks.com/topic/3749-log-parsing/#findComment-13084
Share on other sites

[!--quoteo(post=350329:date=Feb 28 2006, 07:14 PM:name=kanikilu)--][div class=\'quotetop\']QUOTE(kanikilu @ Feb 28 2006, 07:14 PM) [snapback]350329[/snapback][/div][div class=\'quotemain\'][!--quotec--]
The following should search the log file and extract the character name, start time, and end time:
...
Not really sure about the rest, but this may get you pointed in the right direction...
[/quote]

Works great thanx! I took your code and startled fiddeling to get the other lines parsed. So far I've managed to get the "YOU hit" line down to the bare data I need. A bit more fiddeling and this should be done as I need. :)

Thanx loads
Link to comment
https://forums.phpfreaks.com/topic/3749-log-parsing/#findComment-13326
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.