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.
json processing is not using the jansson library.
% phpize
% ./configure
% make
% make test
$ make install
NOTICE: Posix extension is required to do all the tests.
elog.ini:
extension=elog.so
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 |
default type of elog functions.
default destination of elog functions.
default options of elog functions.
Set the output file path of command. Specify the type 10 in the elog.
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 |
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().
Set whether the Unicode Escape processed by elog.to = json.
The default value is On.
Set whether to get associative array as a array in elog.to = json.
The default value is Off.
Set the separator to be used in elog.to = http.
Set the encode type to be used in elog.to = http.
The default value is PHP_QUERY_RFC1738.
- PHP_QUERY_RFC1738
- PHP_QUERY_RFC3986
Set the timestamp format to be used in elog_filter_add_timestamp().
Set the field name of when processed the message value.
The default value is "message".
Set the field name of the file name in the elog_filter_add_fileline().
The default value is "elog_file".
Set the field name of the line in the elog_filter_add_fileline().
The default value is "elog_line".
Set the field name in the elog_filter_add_timestamp().
The default value is "elog_time".
Set the field name in the elog_filter_add_level().
The default value is "elog_level".
Set the field name in the elog_filter_add_request().
The default value is "elog_request".
Set the field name in the elog_filter_add_trace().
The default value is "elog_trace".
If On, error_log() override to elog().
The default value is "Off".
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.override_error_handler When the On, set the sent to the standard error handler.
The default value is "On".
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".
- 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
bool elog ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )
Sends an error message.
-
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.
Returns TRUE on success or FALSE on failure.
bool elog_emerg ( string $message [, int $type = 0 [, string $destination [, string $options ]]] )
elog function of log level emergency.
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.
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.
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.
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.
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.
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.
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.
int elog_shutdown_execute ( [, int $type = 0 [, string $destination [, string $options ]]] )
elog function for execution on shutdown.
-
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.
Returns TRUE on success or FALSE on failure.
bool elog_register_filter ( string $name , callback $callback [, int $enabled ] )
register the filters available in the elog().
-
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
Returns TRUE on success or FALSE on failure.
return FALSE if the rname is already defined.
bool elog_append_filter ( string $name )
Adds name to the list of filters attached to elog().
-
name
The filter name or function name.
Returns TRUE on success or FALSE on failure.
bool elog_prepend_filter ( string $name )
Adds name to the list of filters attached to elog().
-
name
The filter name or function name.
Returns TRUE on success or FALSE on failure.
bool elog_remove_filter ( string $name )
Removes a elog filter previously added to elog_prepend_filter() or elog_append_filter_append().
-
name
The filter name or function name.
Returns TRUE on success or FALSE on failure.
array elog_get_filter ( string $typename )
Retrieve the list of registered filters on the running system.
-
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
Returns an indexed array containing the name of filters available.
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.
-
value
The value.
Returns a value on success or FALSE on failure.
mixed elog_filter_add_timestamp ( mixed $value )
Add the execution time.
-
value
The value.
Returns a value on success or FALSE on failure.
If the scalar value of no-string, Add to timestamp after converted to a string.
mixed elog_filter_add_request ( mixed $value )
Add a variable REQUEST.
-
value
The value.
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.
mixed elog_filter_add_level ( mixed $value )
Add a log level.
-
value
The value.
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.
mixed elog_filter_add_trace ( mixed $value )
Add a trace information.
-
value
The value.
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.
also refer to example.
elog('dummy');
elog('dummy', 3, '/path/to/file');
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);
*/
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);
*/
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.
elog('dummy', 11, 'tcp://127.0.0.1:12342');
elog('dummy', 11, 'tcp://localhost:12342');
elog('dummy', 11, 'udp://127.0.0.1:12342');
elog('dummy=dummy', 11, 'http://127.0.0.1');
POST method, Media type is application/x-www-form-urlencoded.
elog('dummy=dummy', 11, 'http://127.0.0.1', "Content-Type:xxx\nUser-Agent:xxx");
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'.
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'.
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
*/
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_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_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_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
*/
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
*/
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
*/
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"
}
*/
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
*/
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,
)
*/
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
*/
// 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
*/
// 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
*/