<?php // vim: set binary noeol et sw=4 sts=4:
-function logserr($str, $level = L_ERR) {
+require_once 'T/logconstants.php';
+
+function logserr($str, $level = ERROR) {
global $php_errormsg;
logs("$str ($php_errormsg)", $level);
}
-function logs($str, $level = L_INF) {
+function logsdie($str, $level = CRITICAL) {
+ logs($str, $level);
+ die("$str.\n");
+}
+
+function logs($str, $level = INFO) {
global $LOGLEVEL, $LOGFP, $argv;
- if ($str and $LOGLEVEL & $level) {
+ if ($str and ($LOGLEVEL & $level) == $level) {
fputs($LOGFP, sprintf("%s %s[%d] %-8s %s\n", strftime('%c'),
- basename($argv[0]), getmypid(), loglevel2str($level), $str));
+ sprintf('% 8s', substr(basename($argv[0]), 3)), getmypid(),
+ loglevel2str($level), $str));
}
}
function loglevel2str($level) {
- $ret = array();
- if ($level & L_CRI) {
- $ret[] = 'CRITICAL';
- }
- if ($level & L_ERR) {
- $ret[] = 'ERROR';
- }
- if ($level & L_WRN) {
- $ret[] = 'WARNING';
+ if ($level == CRITICAL) {
+ return 'CRITICAL';
}
- if ($level & L_INF) {
- $ret[] = 'INFO';
+ if ($level == ERROR) {
+ return 'ERROR';
}
- if ($level & L_DBG) {
- $ret[] = 'DEBUG';
+ if ($level == WARNING) {
+ return 'WARNING';
}
- if (count($ret) == 1) {
- return reset($ret);
+ if ($level == INFO) {
+ return 'INFO';
}
- if ($ret) {
- return '['.join(',', $ret).']';
+ if ($level == DEBUG) {
+ return 'DEBUG';
}
- return '';
+ return 'UNKNOWN!';
}
?>
\ No newline at end of file