LoginSignup
3
2

More than 5 years have passed since last update.

Windowsでは syslog 関連の LOG_*** の値が異なる

Last updated at Posted at 2013-01-21

自前でこしらえた Logger で次のように LOG_*** でエラーレベルを表現していたのですが・・・

<?php
class Logger
{
    public function emerg($message)
    {
        $this->log($message, LOG_EMERG);
    }

    public function alert($message)
    {
        $this->log($message, LOG_ALERT);
    }

    public function crit($message)
    {
        $this->log($message, LOG_CRIT);
    }

    public function err($message)
    {
        $this->log($message, LOG_ERR);
    }

    // 以下略
}

Windows ではまともに動きませんでした。

<?php
$logger = new Logger();

$logger->emerg("x");   // CRIT: x
$logger->alert("x");   // CRIT: x
$logger->crit("x");    // CRIT: x
$logger->err("x");     // ERR: x
$logger->warning("x"); // WARNING: x
$logger->notice("x");  // DEBUG: x
$logger->info("x");    // DEBUG: x
$logger->debug("x");   // DEBUG: x

Windows だと Linux とかとは異なる値に定義されているためです。

<?php
var_dump(LOG_EMERG);   // int(1)
var_dump(LOG_ALERT);   // int(1)
var_dump(LOG_CRIT);    // int(1)
var_dump(LOG_ERR);     // int(4)
var_dump(LOG_WARNING); // int(5)
var_dump(LOG_NOTICE);  // int(6)
var_dump(LOG_INFO);    // int(6)
var_dump(LOG_DEBUG);   // int(6)

Zend_Log のようにしっかり定義しないとダメですね。

<?php
class Zend_Log
{
    const EMERG   = 0;  // Emergency: system is unusable
    const ALERT   = 1;  // Alert: action must be taken immediately
    const CRIT    = 2;  // Critical: critical conditions
    const ERR     = 3;  // Error: error conditions
    const WARN    = 4;  // Warning: warning conditions
    const NOTICE  = 5;  // Notice: normal but significant condition
    const INFO    = 6;  // Informational: informational messages
    const DEBUG   = 7;  // Debug: debug messages

     :
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2