Skip to content

Commit 59a5bb6

Browse files
Added support for tailing access logs
1 parent 197d9bc commit 59a5bb6

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

mdl-tail

+41-3
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,58 @@
33
# From a moodle dir, auto detect the log file and tail it
44

55
use Cwd;
6+
use Getopt::Long;
7+
8+
my $help;
9+
my $access;
10+
my $info = <<EOF;
11+
12+
Auto discover and live tail the moodle logs
13+
14+
Usage:
15+
16+
/var/www/moodle > mdl-tail
17+
18+
Options:
19+
20+
-h --help Show this help
21+
-a --access Tail access instead of error logs
22+
23+
EOF
24+
25+
GetOptions(
26+
"help|h" => \$help,
27+
"access|a" => \$access,
28+
) or die ("Error in cli args: $info");
29+
30+
if ($help) {
31+
print $info;
32+
die;
33+
}
34+
35+
my $LogConfig = 'ErrorLog';
36+
if ($access) {
37+
$LogConfig = 'CustomLog';
38+
}
39+
640

741
if (!-e 'config.php'){
842
die "Can't find a config.php";
943
}
10-
# find current workig dir
44+
# Find current workig dir
1145
my $cwd = getcwd;
1246

47+
# Look in some typical places for site definitions which match
48+
# the current directory
1349
my $apache = `grep '$cwd' /etc/apache2/sites-enabled/* /etc/httpd/conf/*`;
1450
$apache =~ /^(.*):/;
1551

52+
# If we found some, then grep these for the Apache config for where the
53+
# error logs hangout
1654
my $conf = $1;
17-
my $log = `grep ErrorLog $conf`;
55+
my $log = `grep $LogConfig $conf`;
1856

19-
$log =~ /ErrorLog(.*)$/;
57+
$log =~ /$LogConfig(.*)$/;
2058
$log = $1;
2159
$log =~ s/\$\{APACHE_LOG_DIR\}/\/var\/log\/apache2/;
2260

0 commit comments

Comments
 (0)