File tree 1 file changed +41
-3
lines changed
1 file changed +41
-3
lines changed Original file line number Diff line number Diff line change 3
3
# From a moodle dir, auto detect the log file and tail it
4
4
5
5
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
+
6
40
7
41
if (!-e ' config.php' ){
8
42
die " Can't find a config.php" ;
9
43
}
10
- # find current workig dir
44
+ # Find current workig dir
11
45
my $cwd = getcwd;
12
46
47
+ # Look in some typical places for site definitions which match
48
+ # the current directory
13
49
my $apache = ` grep '$cwd ' /etc/apache2/sites-enabled/* /etc/httpd/conf/*` ;
14
50
$apache =~ / ^(.*):/ ;
15
51
52
+ # If we found some, then grep these for the Apache config for where the
53
+ # error logs hangout
16
54
my $conf = $1 ;
17
- my $log = ` grep ErrorLog $conf ` ;
55
+ my $log = ` grep $LogConfig $conf ` ;
18
56
19
- $log =~ / ErrorLog (.*)$ / ;
57
+ $log =~ / $LogConfig (.*)$ / ;
20
58
$log = $1 ;
21
59
$log =~ s /\$\{ APACHE_LOG_DIR\} / \/ var\/ log\/ apache2/ ;
22
60
You can’t perform that action at this time.
0 commit comments