Skip to content

Instantly share code, notes, and snippets.

@duwaljyoti
Created October 14, 2016 09:31
Show Gist options
  • Save duwaljyoti/e78081f8b01da9690b6b97f8344f99a2 to your computer and use it in GitHub Desktop.
Save duwaljyoti/e78081f8b01da9690b6b97f8344f99a2 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>YIPL Code task</title>
</head>
<body>
<?php
$file = fopen('example.log', 'r') or die ('File opening failed');
$line = fgets($file);
while (!feof($file)) {
$request_counter = 1;
$warning_counter = 0;
$error_counter = 0;
$parts = explode(' ', $line);
$date = substr($parts[0], 0, 10);
$message = substr($parts[7], 0, 10);
if (messagewarning($message)) $warning_counter++;
if (messageerror($message)) $error_counter++;
l:
$line1 = fgets($file);
$parts1 = explode(' ', $line1);
$date1 = substr($parts1[0], 0, 10);
if ($date == $date1) {
$request_counter = 0;
$message = substr($parts1[7], 0, 10);
if (messagewarning($message)) $warning_counter++;
if (messageerror($message)) $error_counter++;
Goto l;
}
echo($date . " warning:" . $warning_counter . " error:" . $error_counter . "<br>");
$line = $line1;
}
fclose($file);
function messagewarning($message)
{
return substr_count($message, "warning") > 0;
}
function messageerror($message)
{
return substr_count($message, "error") > 0;
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment