forked from NatLibFi/RecordManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitlog.php
92 lines (87 loc) · 2.62 KB
/
splitlog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Command line program to split a harvesting debug log to a set of
* importable files.
*
* PHP version 5
*
* Copyright (C) Ere Maijala 2012.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category DataManagement
* @package RecordManager
* @author Ere Maijala <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://github.com/KDK-Alli/RecordManager
*/
require_once 'cmdline.php';
/**
* Main function
*
* @param string[] $argv Program parameters
*
* @return void
*/
function main($argv)
{
$params = parseArgs($argv);
if (!isset($params['input']) || !isset($params['output'])) {
echo "Usage: splitlog --input=... --output=...\n\n";
echo "Parameters:\n\n";
echo "--input A harvest debug log file\n";
echo "--output A file mask for output (e.g. output%d.xml)\n";
echo "--verbose Enable verbose output\n\n";
exit(1);
}
$fh = fopen($params['input'], 'r');
$out = null;
$count = 0;
$inResponse = false;
$emptyLines = 2;
while (($line = fgets($fh))) {
$line = chop($line);
if (!$line) {
++$emptyLines;
continue;
}
//echo "Empty: $emptyLines, $inResponse, line: '$line'\n";
if ($emptyLines >= 2 && $line == 'Request:') {
fgets($fh);
fgets($fh);
$inResponse = true;
$emptyLines = 0;
++$count;
$filename = sprintf($params['output'], $count);
echo "Creating file '$filename'\n";
if ($out) {
fclose($out);
}
$out = fopen($filename, 'w');
if ($out === false) {
die("Could not open output file\n");
}
continue;
}
$emptyLines = 0;
if ($inResponse) {
fputs($out, $line . "\n");
}
}
if ($out) {
fclose($out);
}
echo "Done.\n";
}
main($argv);