+<?php // vim: set binary noeol et sw=4 sts=4:
+
+function logserr($str, $level = L_ERR) {
+ global $php_errormsg;
+ logs("$str ($php_errormsg)", $level);
+}
+
+function logs($str, $level = L_INF) {
+ global $LOGLEVEL, $LOGFP, $argv;
+ if ($str and $LOGLEVEL & $level) {
+ fputs($LOGFP, sprintf("%s %s[%d] %-8s %s\n", strftime('%c'),
+ basename($argv[0]), 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 & L_INF) {
+ $ret[] = 'INFO';
+ }
+ if ($level & L_DBG) {
+ $ret[] = 'DEBUG';
+ }
+ if (count($ret) == 1) {
+ return reset($ret);
+ }
+ if ($ret) {
+ return '['.join(',', $ret).']';
+ }
+ return '';
+}
+
+?>
\ No newline at end of file