CC-2694: Create command line program for viewing/dumping log files
-Better error messages.
This commit is contained in:
parent
bf95c3df1c
commit
58f64b97ae
|
@ -5,14 +5,17 @@ require_once('Zend/Loader/Autoloader.php');
|
||||||
$autoloader = Zend_Loader_Autoloader::getInstance();
|
$autoloader = Zend_Loader_Autoloader::getInstance();
|
||||||
|
|
||||||
$log_files = array("media-monitor" => "/var/log/airtime/media-monitor/media-monitor.log",
|
$log_files = array("media-monitor" => "/var/log/airtime/media-monitor/media-monitor.log",
|
||||||
"show-recorder" => "/var/log/airtime/show-recorder/show-recorder.log",
|
"recorder" => "/var/log/airtime/show-recorder/show-recorder.log",
|
||||||
"playout" => "/var/log/airtime/pypo/pypo.log",
|
"playout" => "/var/log/airtime/pypo/pypo.log",
|
||||||
"web" => "/var/log/airtime/zendphp.log");
|
"web" => "/var/log/airtime/zendphp.log");
|
||||||
|
|
||||||
function printUsage($opts, $userMsg)
|
function printUsage($userMsg = "")
|
||||||
{
|
{
|
||||||
|
global $opts;
|
||||||
|
|
||||||
$msg = $opts->getUsageMessage();
|
$msg = $opts->getUsageMessage();
|
||||||
echo $userMsg;
|
if (strlen($userMsg)>0)
|
||||||
|
echo $userMsg;
|
||||||
echo PHP_EOL."Usage: airtime-log [options]";
|
echo PHP_EOL."Usage: airtime-log [options]";
|
||||||
echo substr($msg, strpos($msg, "\n")).PHP_EOL;
|
echo substr($msg, strpos($msg, "\n")).PHP_EOL;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +32,7 @@ function viewSpecificLog($key){
|
||||||
echo "Viewing $key log\n";
|
echo "Viewing $key log\n";
|
||||||
pcntl_exec(exec("which less"), array($log_files[$key]));
|
pcntl_exec(exec("which less"), array($log_files[$key]));
|
||||||
pcntl_wait($status);
|
pcntl_wait($status);
|
||||||
}
|
} else printUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
function dumpAllLogs(){
|
function dumpAllLogs(){
|
||||||
|
@ -50,7 +53,7 @@ function dumpSpecificLog($key){
|
||||||
$dir = dirname($log_files[$key]);
|
$dir = dirname($log_files[$key]);
|
||||||
$command = "tar cfz $filename $dir 2>/dev/null";
|
$command = "tar cfz $filename $dir 2>/dev/null";
|
||||||
exec($command);
|
exec($command);
|
||||||
}
|
} else printUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
function tailAllLogs(){
|
function tailAllLogs(){
|
||||||
|
@ -67,31 +70,31 @@ function tailSpecificLog($key){
|
||||||
echo "Tail $key log";
|
echo "Tail $key log";
|
||||||
pcntl_exec(exec("which tail"), array("-F", $log_files[$key]));
|
pcntl_exec(exec("which tail"), array("-F", $log_files[$key]));
|
||||||
pcntl_wait($status);
|
pcntl_wait($status);
|
||||||
}
|
} else printUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$opts = new Zend_Console_Getopt(
|
$opts = new Zend_Console_Getopt(
|
||||||
array(
|
array(
|
||||||
'view|v-s' => "Display log file\n"
|
'view|v=s' => "Display log file\n"
|
||||||
."\t\tmediamonitor|playout|recorder|web (ALL by default)",
|
."\t\tmedia-monitor|playout|recorder|web (ALL by default)",
|
||||||
'dump|d-s' => "Collect all log files and compress into a tarball\n"
|
'dump|d-s' => "Collect all log files and compress into a tarball\n"
|
||||||
."\t\tmediamonitor|playout|recorder|web (ALL by default)",
|
."\t\tmedia-monitor|playout|recorder|web (ALL by default)",
|
||||||
'tail|t-s' => "View any new entries appended to log files in real-time\n"
|
'tail|t-s' => "View any new entries appended to log files in real-time\n"
|
||||||
."\t\tmediamonitor|playout|recorder|web (ALL by default)"
|
."\t\tmedia-monitor|playout|recorder|web (ALL by default)"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$opts->parse();
|
$opts->parse();
|
||||||
}
|
}
|
||||||
catch (Zend_Console_Getopt_Exception $e) {
|
catch (Zend_Console_Getopt_Exception $e) {
|
||||||
print $e->getMessage() .PHP_EOL;
|
print $e->getMessage() .PHP_EOL;
|
||||||
printUsage($opts, "");
|
printUsage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($opts->v)){
|
if (isset($opts->v)){
|
||||||
if ($opts->v === true){
|
if ($opts->v === true){
|
||||||
echo "Please choose a specific log to view";
|
//Should never get here. Zend_Console_Getopt requires v to provide a string parameter.
|
||||||
} else {
|
} else {
|
||||||
viewSpecificLog($opts->v);
|
viewSpecificLog($opts->v);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue