Back to index

d-push  2.0
Static Public Member Functions | Static Private Member Functions | Static Private Attributes
ZLog Class Reference

List of all members.

Static Public Member Functions

static Initialize ()
 Initializes the logging.
static Write ($loglevel, $message)
 Writes a log line.
static GetWBXMLDebugInfo ()
 Returns logged information about the WBXML stack.
static GetLastMessage ($loglevel)
 Returns the last message logged for a log level.

Static Private Member Functions

static logToUserFile ()
 
private log stuff
static buildLogString ($loglevel)
 Returns the string to be logged.
static getLogLevelString ($loglevel, $pad=false)
 Returns the string representation of the LOGLEVEL.

Static Private Attributes

static $devid = ''
static $user = ''
static $authUser = false
static $pidstr
static $wbxmlDebug = ''
static $lastLogs = array()

Detailed Description

Definition at line 44 of file zlog.php.


Member Function Documentation

static ZLog::buildLogString ( loglevel) [static, private]

Returns the string to be logged.

private

Returns:
string

Definition at line 175 of file zlog.php.

                                                      {
        if (!isset(self::$pidstr))
            self::$pidstr = '[' . str_pad(@getmypid(),5," ",STR_PAD_LEFT) . '] ';

        if (!isset(self::$user))
            self::$user = '';

        if (!isset(self::$devid))
            self::$devid = '';

        return Utils::GetFormattedTime() ." ". self::$pidstr . self::$user . self::getLogLevelString($loglevel, (LOGLEVEL > LOGLEVEL_INFO)) ." ". self::$devid;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static ZLog::GetLastMessage ( loglevel) [static]

Returns the last message logged for a log level.

Parameters:
int$loglevelone of the defined LOGLEVELS

public

Returns:
string/false returns false if there was no message logged in that level

Definition at line 142 of file zlog.php.

                                                     {
        return (isset(self::$lastLogs[$loglevel]))?self::$lastLogs[$loglevel]:false;
    }

Here is the caller graph for this function:

static ZLog::getLogLevelString ( loglevel,
pad = false 
) [static, private]

Returns the string representation of the LOGLEVEL.

String can be padded

Parameters:
int$loglevelone of the LOGLEVELs
boolean$padprivate
Returns:
string

Definition at line 198 of file zlog.php.

                                                                       {
        if ($pad) $s = " ";
        else      $s = "";
        switch($loglevel) {
            case LOGLEVEL_OFF:   return ""; break;
            case LOGLEVEL_FATAL: return "[FATAL]"; break;
            case LOGLEVEL_ERROR: return "[ERROR]"; break;
            case LOGLEVEL_WARN:  return "[".$s."WARN]"; break;
            case LOGLEVEL_INFO:  return "[".$s."INFO]"; break;
            case LOGLEVEL_DEBUG: return "[DEBUG]"; break;
            case LOGLEVEL_WBXML: return "[WBXML]"; break;
            case LOGLEVEL_DEVICEID: return "[DEVICEID]"; break;
            case LOGLEVEL_WBXMLSTACK: return "[WBXMLSTACK]"; break;
        }
    }

Here is the caller graph for this function:

static ZLog::GetWBXMLDebugInfo ( ) [static]

Returns logged information about the WBXML stack.

public

Returns:
string

Definition at line 130 of file zlog.php.

                                               {
        return trim(self::$wbxmlDebug);
    }
static ZLog::Initialize ( ) [static]

Initializes the logging.

public

Returns:
boolean

Definition at line 58 of file zlog.php.

                                        {
        global $specialLogUsers;

        // define some constants for the logging
        if (!defined('LOGUSERLEVEL'))
            define('LOGUSERLEVEL', LOGLEVEL_OFF);

        if (!defined('LOGLEVEL'))
            define('LOGLEVEL', LOGLEVEL_OFF);

        list($user,) = Utils::SplitDomainUser(Request::GetGETUser());
        if (!defined('WBXML_DEBUG') && $user) {
            // define the WBXML_DEBUG mode on user basis depending on the configurations
            if (LOGLEVEL >= LOGLEVEL_WBXML || (LOGUSERLEVEL >= LOGLEVEL_WBXML && in_array($user, $specialLogUsers)))
                define('WBXML_DEBUG', true);
            else
                define('WBXML_DEBUG', false);
        }

        if ($user)
            self::$user = '['. $user .'] ';
        else
            self::$user = '';

        // log the device id if the global loglevel is set to log devid or the user is in  and has the right log level
        if (Request::GetDeviceID() != "" && (LOGLEVEL >= LOGLEVEL_DEVICEID || (LOGUSERLEVEL >= LOGLEVEL_DEVICEID && in_array($user, $specialLogUsers))))
            self::$devid = '['. Request::GetDeviceID() .'] ';
        else
            self::$devid = '';

        return true;
    }

Here is the call graph for this function:

static ZLog::logToUserFile ( ) [static, private]


private log stuff

Returns the filename logs for a WBXML debug log user should be saved to

private

Returns:
string

Definition at line 156 of file zlog.php.

                                            {
        global $specialLogUsers;

        if (self::$authUser === false) {
            if (RequestProcessor::isUserAuthenticated()) {
                $authuser = Request::GetAuthUser();
                if ($authuser && in_array($authuser, $specialLogUsers))
                    self::$authUser = preg_replace('/[^a-z0-9]/', '_', strtolower($authuser));
            }
        }
        return self::$authUser;
    }

Here is the call graph for this function:

static ZLog::Write ( loglevel,
message 
) [static]

Writes a log line.

Parameters:
int$loglevelone of the defined LOGLEVELS
string$messagepublic
Returns:

Definition at line 100 of file zlog.php.

                                                      {
        self::$lastLogs[$loglevel] = $message;
        $data = self::buildLogString($loglevel) . $message . "\n";

        if ($loglevel <= LOGLEVEL) {
            @file_put_contents(LOGFILE, $data, FILE_APPEND);
        }

        if ($loglevel <= LOGUSERLEVEL && self::logToUserFile()) {
            // padd level for better reading
            $data = str_replace(self::getLogLevelString($loglevel), self::getLogLevelString($loglevel,true), $data);
            // only use plain old a-z characters for the generic log file
            @file_put_contents(LOGFILEDIR . self::logToUserFile() . ".log", $data, FILE_APPEND);
        }

        if (($loglevel & LOGLEVEL_FATAL) || ($loglevel & LOGLEVEL_ERROR)) {
            @file_put_contents(LOGERRORFILE, $data, FILE_APPEND);
        }

        if ($loglevel & LOGLEVEL_WBXMLSTACK) {
            self::$wbxmlDebug .= $message. "\n";
        }
    }

Here is the call graph for this function:


Member Data Documentation

ZLog::$authUser = false [static, private]

Definition at line 47 of file zlog.php.

ZLog::$devid = '' [static, private]

Definition at line 45 of file zlog.php.

ZLog::$lastLogs = array() [static, private]

Definition at line 50 of file zlog.php.

ZLog::$pidstr [static, private]

Definition at line 48 of file zlog.php.

ZLog::$user = '' [static, private]

Definition at line 46 of file zlog.php.

ZLog::$wbxmlDebug = '' [static, private]

Definition at line 49 of file zlog.php.


The documentation for this class was generated from the following file: