katzgrau / KLogger

A Simple Logging Class For PHP
http://codefury.net/projects/klogger/
981 stars 284 forks source link

Parse logfile? #60

Closed jmcbee closed 9 years ago

jmcbee commented 9 years ago

Hello,

Is there a way to parse the lines of a logfile given that, I know the format used to write these lines?

Thanks.

onno-vos-dev commented 9 years ago

You can do this quite easily using regular expressions. I wrote a class for doing just this but unfortunately I can't share it due to company restrictions.

What exactly do you need because I can share some details with you :)

katzgrau commented 9 years ago

Definitely - although I'm not sure it qualifies as an issue for KLogger :)

$matches = [];
$lines = file('log.txt');
foreach ($lines as $line) {
  $matched = preg_match('/(some)(regex)(here)/', $line, $matches);
  if ($matched) {
    // do something with the matches - $matches[1], $matches[2], etc
  }
}
tleb commented 9 years ago
if ($match) { /* ... */ }

Where does your $match come from? :)

although I'm not sure it qualifies as an issue for KLogger :)

Also, wanted to say that there is no real place to ask questions about a project (not talking about KLogger specifically). Gitter tries to solve the problem, but it is not used by a lot of projects, and the chat format isn't perfect.

katzgrau commented 9 years ago

Typo, that should be $matched (fixed)

onno-vos-dev commented 9 years ago

@katzgrau: Maybe we can setup a sub-repo for discussions? No code just a place for people to ask questions and what not :)

Perhaps even move this project to its own Github page so we can host stuff like a parser as well? I'm sure I can refactor the parser to a point where I could share it.

Just a wild idea...?

jmcbee commented 9 years ago

Right, a simple regex should've done it. What was I thinking? Thanks.

onno-vos-dev commented 9 years ago

If you need any help just ping me :)