Logo Search packages:      
Sourcecode: webissues-server version File versions  Download package

logging.inc.php

<?php
/**************************************************************************
* This file is part of the WebIssues Server program
* Copyright (C) 2006 Michał Męciński
* Copyright (C) 2007-2009 WebIssues Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
**************************************************************************/

$open_logs = array();

function wi_log_open( $name )
{
    global $config, $open_logs;

    if ( isset( $open_logs[ $name ] ) )
        return $open_logs[ $name ];

    if ( isset( $config[ "log_$name" ] ) && $config[ "log_$name" ] != '' ) {
        $log = @fopen( $config[ "log_$name" ], 'a' );
        if ( $log ) {
            wi_log_write_header( $log );
            $open_logs[ $name ] = $log;
            return $log;
        }
    }

    return false;
}

function wi_log_check( $name )
{
    global $config, $open_logs;

    if ( isset( $open_logs[ $name ] ) )
        return true;

    if ( isset( $config[ "log_$name" ] ) && $config[ "log_$name" ] != '' ) {
        $log = @fopen( $config[ "log_$name" ], 'a' );
        if ( $log ) {
            fclose( $log );
            return true;
        }
    }

    return false;
}

function wi_log_write_header( $log )
{
    $date = date( 'Y-m-d H:i:s' );

    if ( isset( $_SERVER[ 'REMOTE_HOST' ] ) )
        $host = $_SERVER[ 'REMOTE_HOST' ];
    else if ( isset( $_SERVER[ 'REMOTE_ADDR' ] ) )
        $host = $_SERVER[ 'REMOTE_ADDR' ];
    else
        $host = 'unknown';

    fwrite( $log, "\n[$date, $host]\n" );
}

function wi_error_handler( $errno, $msg, $file, $line )
{
    if ( $errno & error_reporting() ) {
        $log = wi_log_open( 'errors' );
        if ( $log ) {
            $level = ( $errno == E_NOTICE ) ? 'NOTICE' : 'WARNING';
            fwrite( $log, "$level in $file($line):\n$msg\n" );
        }
    }
}

ini_set( 'html_errors', 0 );

set_error_handler( 'wi_error_handler' );

error_reporting( E_ALL ^ E_NOTICE );

Generated by  Doxygen 1.6.0   Back to index