Skip to content

xingskycn/php-ext-elog

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elog function Extension for PHP

Build Status

This extension allows elog function.

elog is a function which is an extension of the error_log.

need at least PHP 5.4 or newer.

Dependencies

json processing is not using the jansson library.

Build

% phpize
% ./configure
% make
% make test
$ make install

NOTICE: Posix extension is required to do all the tests.

Configration

elog.ini:

extension=elog.so

List of elog.ini directives

Name Default Changeable
elog.default_type "0" PHP_INI_ALL
elog.default_destination NULL PHP_INI_ALL
elog.default_options NULL PHP_INI_ALL
elog.command_output NULL PHP_INI_ALL
elog.level NULL PHP_INI_ALL
elog.filter_execute NULL PHP_INI_ALL
elog.filter_json_unicode_escape "On" PHP_INI_ALL
elog.filter_json_assoc "Off" PHP_INI_ALL
elog.filter_http_separator NULL PHP_INI_ALL
elog.filter_http_encode "0" PHP_INI_ALL
elog.filter_timestamp_format NULL PHP_INI_ALL
elog.filter_label_message "message" PHP_INI_ALL
elog.filter_label_file "file" PHP_INI_ALL
elog.filter_label_line "line" PHP_INI_ALL
elog.filter_label_timestamp "time" PHP_INI_ALL
elog.filter_label_level "level" PHP_INI_ALL
elog.filter_label_request "request" PHP_INI_ALL
elog.filter_label_trace "trace" PHP_INI_ALL
elog.override_error_log "Off" PHP_INI_SYSTEM
elog.override_error_handler "Off" PHP_INI_SYSTEM
elog.called_origin_error_handler "On" PHP_INI_SYSTEM
elog.throw_exception_hook "Off" PHP_INI_SYSTEM

elog.default_type integer

default type of elog functions.

elog.default_destination string

default destination of elog functions.

elog.default_options string

default options of elog functions.

elog.command_output string

Set the output file path of command. Specify the type 10 in the elog.

elog.level string

log level of elog functions.

The default value is all.

level(number) or type (string) can be set.

level type
-1 none
0 emerg
1 alert
2 crit
3 err
4 warning
5 notice
6 info
7 debug
256 all

elog.filter_execute string

Set the filter to be performed, just prior to the execution of the function elog.

function name or filter name (which was registered in elog_register_filter()) can be set.

those registered with the filter name will be used if filter name and function name is the same.

execute after the filter that is registered in the elog_prepend_filter() or elog_append_filter().

does not run when registered the same function name or same filter name in the elog_filter_append() or elog_filter_prepend().

elog.filter_json_unicode_escape boolean

Set whether the Unicode Escape processed by elog.to = json.

The default value is On.

elog.filter_json_assoc boolean

Set whether to get associative array as a array in elog.to = json.

The default value is Off.

elog.filter_http_separator string

Set the separator to be used in elog.to = http.

elog.filter_http_encode integer

Set the encode type to be used in elog.to = http.

The default value is PHP_QUERY_RFC1738.

  • PHP_QUERY_RFC1738
  • PHP_QUERY_RFC3986

elog.filter_timestamp_format string

Set the timestamp format to be used in elog_filter_add_timestamp().

elog.filter_label_message string

Set the field name of when processed the message value.

The default value is "message".

elog.filter_label_file string

Set the field name of the file name in the elog_filter_add_fileline().

The default value is "elog_file".

elog.filter_label_line string

Set the field name of the line in the elog_filter_add_fileline().

The default value is "elog_line".

elog.filter_label_timestamp string

Set the field name in the elog_filter_add_timestamp().

The default value is "elog_time".

elog.filter_label_level string

Set the field name in the elog_filter_add_level().

The default value is "elog_level".

elog.filter_label_request string

Set the field name in the elog_filter_add_request().

The default value is "elog_request".

elog.filter_label_trace string

Set the field name in the elog_filter_add_trace().

The default value is "elog_trace".

elog.override_error_log boolean

If On, error_log() override to elog().

The default value is "Off".

elog.override_error_handler boolean

If On, changed error handler to elog.

processing of elog will be the default mode of specified (elog.default_type).

The default value is "Off".

elog.called_origin_error_handler boolean

elog.override_error_handler When the On, set the sent to the standard error handler.

The default value is "On".

elog.throw_exception_hook boolean

If On, send to elog messages that are throw new Exception.

processing of elog will be the default mode of specified (elog.default_type).

The default value is "Off".

Function

  • elog — Send an error message to the defined error handling routines
  • elog_emerg — elog: system is unusable
  • elog_alert — elog: action must be taken immediately
  • elog_crit — elog: critical conditions
  • elog_err — elog: error conditions
  • elog_warning — elog: warning conditions
  • elog_notice — elog: normal but significant condition
  • elog_info — elog: informational
  • elog_debug — elog: debug-level messages
  • elog_shutdown_execute — function for execution on shutdown

filter function:

  • elog_register_filter — Register a user defined elog filter
  • elog_append_filter — Attach a filter to a elog
  • elog_prepend_filter — Attach a filter to a elog
  • elog_remove_filter — Remove a filter from a elog
  • elog_get_filter — Retrieve list of elog filters

builtin filter function:

  • elog_filter_add_fileline — add the number of rows and executable file name
  • elog_filter_add_timestamp — add the execution time
  • elog_filter_add_request — add a variable REQUEST
  • elog_filter_add_level — add a log level
  • elog_filter_add_trace — add a trace information

elog — Send an error message to the defined error handling routines

Description

bool elog ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )

Sends an error message.

Parameters

  • message

    The error message.

  • type

    Says where the error should go. The possible message types are as follows:

    type description
    10 message is sent by command in the destination parameter.
    11 message is sent by socket in the destination parameter.

    0-4 are the same as error_log().

  • destination

    The destination. Its meaning depends on the type parameter as described above.

  • options

    The options. Its meaning depends on the type parameter as described above.

Return Values

Returns TRUE on success or FALSE on failure.

elog_emerg — elog: system is unusable

Description

bool elog_emerg ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )

elog function of log level emergency.

elog_alert — elog: action must be taken immediately

Description

bool elog_alert ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )

elog function of log level alert.

parameters and return values ​​the same and elog.

elog_crit — elog: critical conditions

Description

bool elog_crit ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )

elog function of log level critical.

parameters and return values ​​the same and elog.

elog_err — elog: error conditions

Description

bool elog_err ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )

elog function of log level error.

parameters and return values ​​the same and elog.

elog_warning — elog: warning conditions

Description

bool elog_warning ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )

elog function of log level warning.

parameters and return values ​​the same and elog.

elog_notice — elog: normal but significant condition

Description

bool elog_notice ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )

elog function of log level notice.

parameters and return values ​​the same and elog.

elog_info — elog: informational

Description

bool elog_info ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )

elog function of log level information.

parameters and return values ​​the same and elog.

elog_debug — elog: debug-level messages

Description

bool elog_debug ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )

elog function of log level debug.

parameters and return values ​​the same and elog.

elog_shutdown_execute — function for execution on shutdown

Description

int elog_shutdown_execute ( [, int $type = 0 [, string $destination [, string $options ]]] )

elog function for execution on shutdown.

Parameters

  • type

    Says where the error should go.

  • destination

    The destination. Its meaning depends on the type parameter as described above.

  • options

    The options. Its meaning depends on the type parameter as described above.

Return Values

Returns TRUE on success or FALSE on failure.

elog_register_filter — Register a user defined elog filter

Description

bool elog_register_filter ( string $name , callback $callback [, int $enabled ] )

register the filters available in the elog().

Parameters

  • name

    The filter name to be registered.

  • callback

    The filter callback to register.

  • enabled

    also grant to the elog at the same time as the registration of the filter.

    • EL_FILTER_APPEND
    • EL_FILTER_PREPEND

Return Values

Returns TRUE on success or FALSE on failure.

return FALSE if the rname is already defined.

elog_append_filter — Attach a filter to a elog

Description

bool elog_append_filter ( string $name )

Adds name to the list of filters attached to elog().

Parameters

  • name

    The filter name or function name.

Return Values

Returns TRUE on success or FALSE on failure.

elog_prepend_filter — Attach a filter to a elog

Description

bool elog_prepend_filter ( string $name )

Adds name to the list of filters attached to elog().

Parameters

  • name

    The filter name or function name.

Return Values

Returns TRUE on success or FALSE on failure.

elog_remove_filter — Remove a filter from a elog

Description

bool elog_remove_filter ( string $name )

Removes a elog filter previously added to elog_prepend_filter() or elog_append_filter_append().

Parameters

  • name

    The filter name or function name.

Return Values

Returns TRUE on success or FALSE on failure.

elog_get_filter — Retrieve list of elog filters

Description

array elog_get_filter ( string $typename )

Retrieve the list of registered filters on the running system.

Parameters

  • typename

    The filter type name.

    name description
    builtin filter function of the built-in
    registers registered in elog_register_filter()
    execute registered in elog.filter_execute
    enabled valid filter

Return Values

Returns an indexed array containing the name of filters available.

elog_filter_add_fileline — add the number of rows and executable file name

Description

mixed elog_filter_add_fileline ( mixed $value )

Add the number of rows and executable file name.

If the scalar value of no-string, Add to file name and the number of rows after converted to a string.

Parameters

  • value

    The value.

Return Values

Returns a value on success or FALSE on failure.

elog_filter_add_timestamp — add the execution time

Description

mixed elog_filter_add_timestamp ( mixed $value )

Add the execution time.

Parameters

  • value

    The value.

Return Values

Returns a value on success or FALSE on failure.

If the scalar value of no-string, Add to timestamp after converted to a string.

elog_filter_add_request — add a variable REQUEST

Description

mixed elog_filter_add_request ( mixed $value )

Add a variable REQUEST.

Parameters

  • value

    The value.

Return Values

Returns a value on success or FALSE on failure.

If the scalar value of no-string, Add to variable REQUEST after converted to a string.

elog_filter_add_level — add a log level

Description

mixed elog_filter_add_level ( mixed $value )

Add a log level.

Parameters

  • value

    The value.

Return Values

Returns a value on success or FALSE on failure.

If the scalar value of no-string, Add to log level after converted to a string.

elog_filter_add_trace — add a trace information

Description

mixed elog_filter_add_trace ( mixed $value )

Add a trace information.

Parameters

  • value

    The value.

Return Values

Returns a value on success or FALSE on failure.

If the scalar value of no-string, Add to trace information after converted to a string.

Examples

also refer to example.

default

elog('dummy');

file

elog('dummy', 3, '/path/to/file');

command

elog('dummy', 10, '/path/to/command');
/*
same as:
  system("echo 'dummy' | '/path/to/command');
or
  $process = popen('/path/to/command', 'w');
  fwrite($process, 'dummy');
  pclose($process);
*/

command option

elog('dummy', 10, '/path/to/command', 'command option');
/*
same as:
  system("echo 'dummy' | '/path/to/command command option');
or
  $process = popen('/path/to/command command option', 'w');
  fwrite($process, 'dummy');
  pclose($process);
*/

command output

ini_set('elog.command_output', '/path/to/output');
elog('dummy', 10, '/path/to/command');

The output of the /path/to/output is recorded in the /path/to/command.

socket (transport target)

TCP/IP

elog('dummy', 11, 'tcp://127.0.0.1:12342');
elog('dummy', 11, 'tcp://localhost:12342');

UDP

elog('dummy', 11, 'udp://127.0.0.1:12342');

HTTP

elog('dummy=dummy', 11, 'http://127.0.0.1');

POST method, Media type is application/x-www-form-urlencoded.

HTTP headers

elog('dummy=dummy', 11, 'http://127.0.0.1', "Content-Type:xxx\nUser-Agent:xxx");

multi type

elog('dummy', array(array(3, '/path/to/file1'),
                    array(3, '/path/to/file2'),
                    array(10, '/path/to/command'),
                    array(11, 'tcp://127.0.0.1:12342')));
  • The output to /path/to/file1, /path/to/file2.
  • Send to '/path/to/command'.
  • Send to 'tcp://127.0.0.1:12342'.

default set

ini_set('elog.default_type', 3);
ini_set('elog.default_destination', '/path/to/file');
ini_set('elog.default_options', 'x y z');

elog('dummy');
// The output to '/path/to/file x y z'.

ini_set('elog.default_type', 2);
ini_set('elog.default_destination', 'tcp://127.0.0.1:12342');

elog('dummy');
// Send to 'tcp://127.0.0.1:12342'.

level

ini_set('elog.level', 'emerg'); // or alert, crit, err, warning, notice,
                                //     info, debug, none, all

elog_emerg('dummy-0');
elog_alert('dummy-1');
elog_crit('dummy-2');
elog_err('dummy-3');
elog_warning('dummy-4');
elog_notice('dummy-5');
elog_info('dummy-6');
elog_debug('dummy-7');

/*
// output: emerg
dummy-0
// output: alert
dummy-0dummy-1
// output: crit
dummy-0dummy-1dummy-2
// output: err
dummy-0dummy-1dummy-2dummy-3
// output: warning
dummy-0dummy-1dummy-2dummy-3dummy-4
// output: notice
dummy-0dummy-1dummy-2dummy-3dummy-4dummy-5
// output: info
dummy-0dummy-1dummy-2dummy-3dummy-4dummy-5dummy-6
// output: debug
dummy-0dummy-1dummy-2dummy-3dummy-4dummy-5dummy-6dummy-7
// output: none
// output: all
dummy-0dummy-1dummy-2dummy-3dummy-4dummy-5dummy-6dummy-7
*/

filter

function f1($val) {
    return $val . '-a';
}

class F {
    public function f2($val) {
        return $val . '-b';
    }
    static public function f3($val) {
        return $val . '-c';
    }
}

elog_register_filter('a', 'f1');
elog_register_filter('b', array(new F, 'f2'));
elog_register_filter('c', 'F::f3');
elog_register_filter('d', function ($val) { return $val . '-d'; });

elog_append_filter('a'); // or elog_prepend_filter
elog_append_filter('b'); // or elog_prepend_filter
elog_append_filter('c'); // or elog_prepend_filter
elog_append_filter('d'); // or elog_prepend_filter

elog('dummy');
/*
// output: append
dummy-a-b-c-d

// output: prepend
dummy-d-c-b-a
*/

ini: elog.to string (default)

ini_set('elog.to', 'string');

elog('dummy');
/*
// output:
dummy
*/

elog(array('dummy'));
/* output:
[
    "dummy"
]
*/

elog(array('a' => 'dummy', 'b' => 'DUMMY'));
/* output:
{
    "a": "dummy"
    "b": "DUMMY"
}
*/

ini: elog.to json

ini_set('elog.to', 'json');

elog('dummy');
/*
// output:
{"message":"dummy"}
*/

elog(array('dummy'));
/*
// output:
{"MESSAGE":["dummy"]}
*/

elog(array('a' => 'dummy', 'b' => 'DUMMY'));
/*
// output:
{MESSAGE":{"a":"dummy","b":"DUMMY"}}
*/

ini: elog.to http

ini_set('elog.to', 'http');

elog('dummy');
/*
// output:
message=dummy
*/

elog(array('dummy'));
/*
// output:
message%5B0%5D=dummy
*/

elog(array('a' => 'dummy', 'b' => 'DUMMY'));
/*
// output:
message%5Ba%5D=dummy&message%5Bb%5D=DUMMY
*/

filter: elog_filter_add_fileline

elog_append_filter(array('elog_filter_add_fileline'));

elog('dummy');
/*
// output:
dummy
file: /path/to/test.php
line: 4
*/

ini_set('elog.filter_label_file', 'file');

elog(array('dummy'));
/*
// output:
[
  "dummy"
]
file: /path/to/test.php
line: 14
*/

ini_set('elog.filter_label_line', 'line');

elog(array('a' => 'dummy', 'b' => 'DUMMY'));
/*
// output:
{
  "a": "dummy"
  "b": "DUMMY"
}
file: /path/to/test.php
line: 26
*/

filter: elog_filter_add_timestamp

elog_append_filter(array('elog_filter_add_timestamp'));

elog('dummy');
/*
// output:
dummy
time: "20-May-2013 13:50:13 Asia/Tokyo"
*/

ini_set('elog.filter_timestamp_format', 'Y-m-d H:i:s');

elog(array('dummy'));
/*
// output:
[
  "dummy"
]
time: 2013-05-20 13:50:13
*/

ini_set('elog.filter_timestamp_format', 'U');
ini_set('elog.filter_label_timestamp', 'timestamp');
    
elog(array('a' => 'dummy', 'b' => 'DUMMY'));
/*
// output:
{
  "a": "dummy"
  "b": "DUMMY"
}
timestamp: 1369025413
*/

filter: elog_filter_add_request

elog_append_filter(array('elog_filter_add_request'));

// REQUEST
$_REQUEST['dummy'] = 'DUMMY';

elog('dummy');
/*
// output:
dummy
request: {
  "dummy": "DUMMY"
}
*/

elog(array('dummy'));
/*
// output:
[
  "dummy"
]
request: {
  "dummy": "DUMMY"
}
*/

elog(array('a' => 'dummy', 'b' => 'DUMMY'));
/*
// output:
{
  "a": "dummy"
  "b": "DUMMY"
}
request: {
  "dummy": "DUMMY"
}
*/

filter: elog_filter_add_level

elog_append_filter(array('elog_filter_add_level'));

elog_emerg('dummy');
/*
// output:
dummy
level: EMERGE
*/

elog_warning(array('dummy'));
/*
// output:
[
  "dummy"
]
level: WARNING
*/

ini_set('elog.filter_label_level', 'LEVEL');

elog_err(array('a' => 'dummy', 'b' => 'DUMMY'));
/*
// output:
{
  "a": "dummy"
  "b": "DUMMY"
}
LEVEL: ERR
*/

filter and HTTP

elog(array('a' => 'dummy', 'b' => 'DUMMY'), 11, 'http://127.0.0.1/recv.php');
/*
// http://127.0.0.1/recv.php: var_dump($_REQUEST)
array (
  'a' => 'dummy',
  'b' => 'DUMMY,
)

*/

filter and multi type

elog('dummy', array(array(3, '/path/to/file1', 'elog_filter_add_fileline'),
                    array(3, '/path/to/file2', 'elog_filter_add_timestamp')));
/*
// output: /path/to/file1
dummy
file: /path/to/test.php
line: 2

// output: /path/to/file2
dummy
time: 20-May-2013 14:02:14 Asia/Tokyo
*/

override error_log

// elog.ini:
// elog.default_type=3
// elog.default_destination=/path/to/file
// elog.override_error_log=On

error_log('dummy');
/*
// output: /path/to/file
dummy
*/

override error handler

// elog.ini:
// elog.default_type=3
// elog.default_destination=/path/to/file
// elog.override_error_handler=On

echo $dummy;
/*
// output: /path/to/file
PHP Notice:  Undefined variable: dummy in /path/to/test.php on line 2
*/

Related

About

elog function Extension for PHP

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.jansson

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 57.4%
  • PHP 42.4%
  • Shell 0.2%