1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2024-11-29 09:24:12 +01:00
yubikey-val/ykval-log.php
Simon Josefsson bca5d339cb Use openlog.
2010-01-14 11:56:40 +00:00

49 lines
965 B
PHP

<?php
class Log
{
function __construct($name='ykval')
{
$this->name=$name;
$this->fields=array();
$this->LOG_LEVELS = array(LOG_EMERG=>'LOG_EMERG',
LOG_ALERT=>'LOG_ALERT',
LOG_CRIT=>'LOG_CRIT',
LOG_ERR=>'LOG_ERR',
LOG_WARNING=>'LOG_WARNING',
LOG_NOTICE=>'LOG_NOTICE',
LOG_INFO=>'LOG_INFO',
LOG_DEBUG=>'LOG_DEBUG');
openlog("ykval", LOG_PID, LOG_LOCAL0);
}
function addField($name, $value)
{
$this->fields[$name]=$value;
}
function log($priority, $message, $arr=null){
if (is_array($arr)) {
foreach($arr as $key=>$value){
$message.=" $key=$value ";
}
}
# Add fields
$msg_fields = "";
foreach ($this->fields as $field=>$value) {
$msg_fields .= "[" . $value . "] ";
}
syslog($priority,
$this->LOG_LEVELS[$priority] . ':' .
$this->name . ':' .
$msg_fields .
$message);
}
}
?>