# How can I split the log file depending on the input file?

I have a large document that I have split into several separate documents. I have one `main.tex` file and several `file_i.tex` files which are included into `main.tex` using the `\input`-command. It also happens that this including is nested, i.e. that one of `file_i.tex` files included another file.

The log file `main.log` that is generated looks something like this:

``````blabla
(main.tex
blabla
blabla
(file_1.tex
blabla
)
(file_2.tex
blablabla
(file_2_1.tex)
)
blabla
)
``````

I wonder if there exists some way/script that splits this file into e.g. `part_main.log`, `part_file_1.log`, `part_file_2.log` and `part_file_2_1.log`.

It doesn't seem to difficult to write an ad-hoc script to do this, but it also seems such a common problem, that I would expect some well-tested scripts to already be available.

-

I don't know of an "official" script but I wrote a little perl script some time ago for a similar task. It is kind of a dirty hack and sparsely tested, but it might be useful for others as well. Improvements are welcome.

The script expects TeX's logfile as a parameter and generates separate .log files for each included module.

``````#!/usr/bin/perl

use File::Basename;

die("Syntax: splitlog <logfile>") unless (\$#ARGV == 1);

@log = <ARGV>;
push(@files, \$ARGV[0]);
foreach (@log) {
chomp;
while (length(\$_) > 0) {
if (/^\(([^)]+)\$/) {
push(@files, \$1);
\$_ = "";
\$fname = basename(\$1);
open(LOG, ">\$fname.log");
}
elsif (/^(\)+)\s*(.*)\$/) {
for (\$i=0; \$i < length(\$1); ++\$i) {
close(LOG);
pop(@files);
}
if (\$#files > 0) {
\$fname = basename(\$files[-1]);
open(LOG, ">>\$fname.log");
}
\$_ = \$2;
}
else {
print LOG "\$_\n";
\$_ = "";
}
}
}
``````
-