Book/seaslog-Phpdoc专题

SeasLog

目录

简介

类摘要

SeasLog

class SeasLog {

/* 方法 */

public <span class="modifier">static bool <span class="methodname">alert ( <span class="type">string $message [, <span class="methodparam">array $content [, string $logger ]] )

public <span class="modifier">static mixed <span class="methodname">analyzerCount ( <span class="methodparam">string $level [, string $log_path [, <span class="type">string $key_word ]] )

public <span class="modifier">static mixed <span class="methodname">analyzerDetail ( <span class="methodparam">string $level [, string $log_path [, <span class="type">string $key_word [, <span class="methodparam">int $start [, int $limit [, int $order ]]]]] )

public <span class="modifier">static bool <span class="methodname">closeLoggerStream ( <span class="methodparam">int $model , string $logger )

public <span class="modifier">static bool <span class="methodname">critical ( <span class="type">string $message [, <span class="methodparam">array $content [, string $logger ]] )

public <span class="modifier">static bool <span class="methodname">debug ( <span class="type">string $message [, <span class="methodparam">array $content [, string $logger ]] )

public <span class="methodname">__destruct ( <span class="methodparam">void )

public <span class="modifier">static bool <span class="methodname">emergency ( <span class="type">string $message [, <span class="methodparam">array $content [, string $logger ]] )

public <span class="modifier">static bool <span class="methodname">error ( <span class="type">string $message [, <span class="methodparam">array $content [, string $logger ]] )

public <span class="modifier">static bool <span class="methodname">flushBuffer ( <span class="methodparam">void )

public <span class="modifier">static string <span class="methodname">Seaslog::getBasePath ( <span class="methodparam">void )

public <span class="modifier">static array <span class="methodname">getBuffer ( <span class="methodparam">void )

public <span class="modifier">static bool <span class="methodname">getBufferEnabled ( <span class="methodparam">void )

public <span class="modifier">static string <span class="methodname">getDatetimeFormat ( <span class="methodparam">void )

public <span class="modifier">static string <span class="methodname">getLastLogger ( <span class="methodparam">void )

public <span class="modifier">static string <span class="methodname">getRequestID ( <span class="methodparam">void )

public <span class="modifier">static bool <span class="methodname">getRequestVariable ( <span class="methodparam">int $key )

public <span class="modifier">static bool <span class="methodname">info ( <span class="type">string $message [, <span class="methodparam">array $content [, string $logger ]] )

public <span class="modifier">static bool <span class="methodname">log ( <span class="type">string $level [, <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]]] )

public <span class="modifier">static bool <span class="methodname">notice ( <span class="type">string $message [, <span class="methodparam">array $content [, string $logger ]] )

public <span class="modifier">static bool <span class="methodname">setBasePath ( <span class="type">string $base_path )

public <span class="modifier">static bool <span class="methodname">setDatetimeFormat ( <span class="methodparam">string $format )

public <span class="modifier">static bool <span class="methodname">setLogger ( <span class="type">string $logger )

public <span class="modifier">static bool <span class="methodname">setRequestID ( <span class="type">string $request_id )

public <span class="modifier">static bool <span class="methodname">setRequestVariable ( <span class="methodparam">int $key , <span class="methodparam">string $value )

public <span class="modifier">static bool <span class="methodname">warning ( <span class="type">string $message [, <span class="methodparam">array $content [, string $logger ]] )

}

SeasLog::alert

记录 alert 日志

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::alert ( <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]] )

记录 alert 日志

Note:

"ALERT" -必须立即采取行动的紧急事件 需要立即通知相关人员紧急修复。

参数

message
日志的消息

content
"消息"包含占位符,实现用 content 数组中的值替换这些占位符。 例如'消息'是 `log info from {NAME}`, '内容'是 `array('NAME' => neeke)`, 日志信息是 `log info from neeke`

logger
当函数调用 SeasLog::setLogger() 时,就像临时 logger 一样,在第三个参数中使用这个"logger"。 如果 `logger` 为NULL 或 "",那么 SeasLog 将使用由 <span class="methodname">SeasLog::setLogger设置的最新日志记录程序。

返回值

记录日志信息成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::alert例子

<?php

var_dump(SeasLog::alert('log message'));

//with content
var_dump(SeasLog::alert('log message from {NAME}',array('NAME' => 'neeke')));

//with tmp logger
var_dump(SeasLog::alert('log message from {NAME}',array('NAME' => 'neeke'),'tmp_logger'));

var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
array(2) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(81) "2018-07-07 11:45:49 | ALERT | 73263 | 5b40376d1067c | 1530935149.68 | log message
"
    [1]=>
    string(92) "2018-07-07 11:45:49 | ALERT | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
  ["/var/log/www/tmp_logger/20180707.log"]=>
  array(1) {
    [0]=>
    string(92) "2018-07-07 11:45:49 | ALERT | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
}

参见

  • seaslog.default_template
  • SeasLog::debug
  • SeasLog::info
  • SeasLog::notice
  • SeasLog::warning
  • SeasLog::error
  • SeasLog::critical
  • SeasLog::emergency
  • SeasLog::log

SeasLog::analyzerCount

Get log count by level, log_path and key_word

说明

public <span class="modifier">static mixed <span class="methodname">SeasLog::analyzerCount ( <span class="methodparam">string $level [, string $log_path [, <span class="type">string $key_word ]] )

`SeasLog` get count value of `grep -ai '{level}' | grep -aic '{key_word}'` use system pipe and return to PHP (array or int).

参数

level
String. The log information level.

log_path
String. The log information path.

key_word
String. The search key word for log information.

返回值

If `level` is SEASLOG_ALL or Empty, return all levels count as `array`. If `level` is SEASLOG_INFO or the other level, return count as `int`.

范例

示例 #1 SeasLog::analyzerCount example

<?php

$countResult1 = SeasLog::analyzerCount();

//with `level`
$countResult2 = SeasLog::analyzerCount(SEASLOG_DEBUG);

//with `level` and `log_path`
$countResult3 = SeasLog::analyzerCount(SEASLOG_ERROR,date('Ymd',time()));

//with `level` and `key_word`
$countResult4 = SeasLog::analyzerCount(SEASLOG_DEBUG,NULL,'accessToken');

var_dump($countResult1,$countResult2,$countResult3,$countResult4);

?>

以上例程的输出类似于:

array(8) {
  ["DEBUG"]=>
  int(180)
  ["INFO"]=>
  int(214)
  ["NOTICE"]=>
  int(0)
  ["WARNING"]=>
  int(0)
  ["ERROR"]=>
  int(228)
  ["CRITICAL"]=>
  int(244)
  ["ALERT"]=>
  int(1)
  ["EMERGENCY"]=>
  int(0)
}

int(180)

int(228)

int(29)

参见

  • SeasLog::analyzerDetail

SeasLog::analyzerDetail

Get log detail by level, log_path, key_word, start, limit, order

说明

public <span class="modifier">static mixed <span class="methodname">SeasLog::analyzerDetail ( <span class="methodparam">string $level [, string $log_path [, <span class="type">string $key_word [, <span class="methodparam">int $start [, int $limit [, int $order ]]]]] )

`SeasLog` get results of `grep -ai '{level}' | grep -ai '{key_word}' | sed -n '{start},{limit}'p` use system pipe and return array to PHP.

参数

level
String. The log information level.

log_path
String. The log information path.

key_word
String. The search key word for log information.

start
Int. Default is `1`.

limit
Int. Default is `20`.

order
Int. Default is SEASLOG_DETAIL_ORDER_ASC. See also:

返回值

Return results as array.

Note:

When `start`,`limit` is not NULL and in Windows, SeasLog will threw exception with message 'Param start and limit don't support Windows'.

范例

示例 #1 SeasLog::analyzerDetail example

<?php

$result1 = SeasLog::analyzerDetail(SEASLOG_ERROR);

//with `logger` and `key_word`
$result2 = SeasLog::analyzerDetail(SEASLOG_ERROR,'test/logger/','neeke');

//with `start` and `limit`
$result3 = SeasLog::analyzerDetail(SEASLOG_ERROR,'test/logger/','neeke',1,2);

var_dump($result1,$result2,$result3);
?>

以上例程的输出类似于:

array(20) {
  [0]=>
  string(93) "2018-07-09 12:52:53 | ERROR | 12247 | 5b42ea2580e51 | 1531111973.528 | log message from neeke"
  [1]=>
  string(93) "2018-07-09 12:52:54 | ERROR | 12256 | 5b42ea26d6657 | 1531111974.878 | log message from neeke"
  [2]=>
  string(93) "2018-07-09 12:52:55 | ERROR | 12265 | 5b42ea277b8d4 | 1531111975.506 | log message from neeke"
  [3]=>
  string(104) "2018-07-09 12:52:55 | ERROR | 12274 | 5b42ea27db5dc | 1531111975.898 | log message from the other people"
...
}

array(3) {
  [0]=>
  string(93) "2018-07-09 12:52:53 | ERROR | 12247 | 5b42ea2580e51 | 1531111973.528 | log message from neeke"
  [1]=>
  string(93) "2018-07-09 12:52:54 | ERROR | 12256 | 5b42ea26d6657 | 1531111974.878 | log message from neeke"
  [2]=>
  string(93) "2018-07-09 12:52:55 | ERROR | 12265 | 5b42ea277b8d4 | 1531111975.506 | log message from neeke"
}

array(2) {
  [0]=>
  string(93) "2018-07-09 12:52:53 | ERROR | 12247 | 5b42ea2580e51 | 1531111973.528 | log message from neeke"
  [1]=>
  string(93) "2018-07-09 12:52:54 | ERROR | 12256 | 5b42ea26d6657 | 1531111974.878 | log message from neeke"
}

参见

  • SeasLog::analyzerCount

SeasLog::closeLoggerStream

Manually release stream flow from logger

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::closeLoggerStream ( <span class="methodparam">int $model , string $logger )

Manually release stream flow from logger. SeasLog caches the stream handle opened by the log logger to save the overhead of creating a stream. The handle will be automatically released at the end of the request. If in CLI mode, the process will also automatically release when it exits. Or you can use the following functions to manually release(manually release function needs to update SeasLog 1.8.6 or updated version).

参数

model
Constant int.

logger
The logger name.

返回值

Return TRUE on released stream flow success, FALSE on failure.

范例

示例 #1 SeasLog::closeLoggerStream example

<?php

var_dump(SeasLog::closeLoggerStream());
var_dump(SeasLog::closeLoggerStream(SEASLOG_CLOSE_LOGGER_STREAM_MOD_ALL));
var_dump(SeasLog::closeLoggerStream(SEASLOG_CLOSE_LOGGER_STREAM_MOD_ASSIGN, 'logger_name'));

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)

参见

  • SeasLog::setLogger
  • SeasLog::getLastLogger

SeasLog::__construct

Description

说明

public <span class="methodname">SeasLog::__construct ( <span class="methodparam">void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

范例

示例 #1 SeasLog::__construct example

<?php

/* ... */

?>

以上例程的输出类似于:

...

SeasLog::critical

记录 critical 日志

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::critical ( <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]] )

记录 critical 日志

Note:

"CRITICAL" - 紧急情况、需要立刻进行修复、程序组件不可用

参数

message
日志的消息

content
"消息"包含占位符,实现用 content 数组中的值替换这些占位符。 例如'消息'是 `log info from {NAME}`, '内容'是 `array('NAME' => neeke)`, 日志信息是 `log info from neeke`

logger
当函数调用 SeasLog::setLogger() 时,就像临时 logger 一样,在第三个参数中使用这个"logger"。 如果 `logger` 为NULL 或 "",那么SeasLog将使用由 <span class="methodname">SeasLog::setLogger设置的最新日志记录程序。

返回值

记录日志信息成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::critical example

<?php

var_dump(SeasLog::critical('log message'));

//with content
var_dump(SeasLog::critical('log message from {NAME}',array('NAME' => 'neeke')));

//with tmp logger
var_dump(SeasLog::critical('log message from {NAME}',array('NAME' => 'neeke'),'tmp_logger'));

var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
array(2) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(81) "2018-07-07 11:45:49 | CRITICAL | 73263 | 5b40376d1067c | 1530935149.68 | log message
"
    [1]=>
    string(92) "2018-07-07 11:45:49 | CRITICAL | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
  ["/var/log/www/tmp_logger/20180707.log"]=>
  array(1) {
    [0]=>
    string(92) "2018-07-07 11:45:49 | CRITICAL | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
}

参见

  • seaslog.default_template
  • SeasLog::debug
  • SeasLog::info
  • SeasLog::notice
  • SeasLog::warning
  • SeasLog::error
  • SeasLog::alert
  • SeasLog::emergency
  • SeasLog::log

SeasLog::debug

记录 debug 日志

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::debug ( <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]] )

记录debug日志

Note:

"DEBUG" - debug 信息、细粒度信息事件

参数

message
日志的消息

content
"消息"包含占位符,实现用 content 数组中的值替换这些占位符。 例如'消息'是 `log info from {NAME}`, '内容'是 `array('NAME' => neeke)`, 日志信息是 `log info from neeke`

logger
当函数调用 SeasLog::setLogger() 时,就像临时 logger 一样,在第三个参数中使用这个"logger"。 如果 `logger` 为NULL 或 "",那么 SeasLog 将使用由 <span class="methodname">SeasLog::setLogger设置的最新日志记录程序。

返回值

记录日志信息成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::debug example

<?php

var_dump(SeasLog::debug('log message'));

//with content
var_dump(SeasLog::debug('log message from {NAME}',array('NAME' => 'neeke')));

//with tmp logger
var_dump(SeasLog::debug('log message from {NAME}',array('NAME' => 'neeke'),'tmp_logger'));

var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
array(2) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(81) "2018-07-07 11:45:49 | DEBUG | 73263 | 5b40376d1067c | 1530935149.68 | log message
"
    [1]=>
    string(92) "2018-07-07 11:45:49 | DEBUG | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
  ["/var/log/www/tmp_logger/20180707.log"]=>
  array(1) {
    [0]=>
    string(92) "2018-07-07 11:45:49 | DEBUG | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
}

参见

  • seaslog.default_template
  • SeasLog::info
  • SeasLog::notice
  • SeasLog::warning
  • SeasLog::error
  • SeasLog::critical
  • SeasLog::alert
  • SeasLog::emergency
  • SeasLog::log

SeasLog::__destruct

Description

说明

public <span class="methodname">SeasLog::__destruct ( <span class="methodparam">void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

范例

示例 #1 SeasLog::__destruct example

<?php

/* ... */

?>

以上例程的输出类似于:

...

SeasLog::emergency

记录 emergency 日志

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::emergency ( <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]] )

记录 emergency 日志

Note:

"EMERGENCY" - 系统不可用。

参数

message
日志的消息

content
"消息"包含占位符,实现用 content 数组中的值替换这些占位符。 例如'消息'是 `log info from {NAME}`, '内容'是 `array('NAME' => neeke)`, 日志信息是 `log info from neeke`

logger
当函数调用 SeasLog::setLogger() 时,就像临时 logger 一样,在第三个参数中使用这个"logger"。 如果 `logger` 为 NULL 或 "",那么 SeasLog 将使用由 <span class="methodname">SeasLog::setLogger设置的最新 Logger。

返回值

记录日志信息成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::emergency example

<?php

var_dump(SeasLog::emergency('log message'));

//with content
var_dump(SeasLog::emergency('log message from {NAME}',array('NAME' => 'neeke')));

//with tmp logger
var_dump(SeasLog::emergency('log message from {NAME}',array('NAME' => 'neeke'),'tmp_logger'));

var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
array(2) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(81) "2018-07-07 11:45:49 | EMERGENCY | 73263 | 5b40376d1067c | 1530935149.68 | log message
"
    [1]=>
    string(92) "2018-07-07 11:45:49 | EMERGENCY | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
  ["/var/log/www/tmp_logger/20180707.log"]=>
  array(1) {
    [0]=>
    string(92) "2018-07-07 11:45:49 | EMERGENCY | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
}

参见

  • seaslog.default_template
  • SeasLog::debug
  • SeasLog::info
  • SeasLog::notice
  • SeasLog::warning
  • SeasLog::error
  • SeasLog::critical
  • SeasLog::alert
  • SeasLog::log

SeasLog::error

记录 error 日志

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::error ( <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]] )

记录 error 日志

Note:

"ERROR" - 运行时出现的错误、不必要立即进行修复、不影响整个逻辑的运行、需要记录并做检测

参数

message
日志的消息

content
"消息"包含占位符,实现用 content 数组中的值替换这些占位符。 例如'消息'是 `log info from {NAME}`, '内容'是 `array('NAME' => neeke)`, 日志信息是 `log info from neeke`

logger
当函数调用 SeasLog::setLogger() 时,就像临时 logger 一样,在第三个参数中使用这个"logger"。 如果 `logger` 为NULL 或 "",那么 SeasLog 将使用由 <span class="methodname">SeasLog::setLogger设置的最新日志记录程序。

返回值

记录日志信息成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::error example

<?php

var_dump(SeasLog::error('log message'));

//with content
var_dump(SeasLog::error('log message from {NAME}',array('NAME' => 'neeke')));

//with tmp logger
var_dump(SeasLog::error('log message from {NAME}',array('NAME' => 'neeke'),'tmp_logger'));

var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
array(2) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(81) "2018-07-07 11:45:49 | ERROR | 73263 | 5b40376d1067c | 1530935149.68 | log message
"
    [1]=>
    string(92) "2018-07-07 11:45:49 | ERROR | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
  ["/var/log/www/tmp_logger/20180707.log"]=>
  array(1) {
    [0]=>
    string(92) "2018-07-07 11:45:49 | ERROR | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
}

参见

  • seaslog.default_template
  • SeasLog::debug
  • SeasLog::info
  • SeasLog::notice
  • SeasLog::warning
  • SeasLog::critical
  • SeasLog::alert
  • SeasLog::emergency
  • SeasLog::log

SeasLog::flushBuffer

将日志缓存刷新到介质中,文件介质,或者发送到远端的 TCP/UDP 服务地址。

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::flushBuffer ( <span class="methodparam">void )

将日志缓存按照 seaslog.appender 刷新到介质: 文件介质,或发送到远端的 TCP/UDP 服务地址。

Note:

同时请留意: seaslog.appender_retry seaslog.remote_host seaslog.remote_port

参数

此函数没有参数。

返回值

刷新成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::flushBuffer example

<?php

SeasLog::info('info log');
SeasLog::debug('debug log');
var_dump(SeasLog::getBuffer());
var_dump(SeasLog::flushBuffer());
var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

array(1) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(79) "2018-07-07 10:47:58 | INFO | 71910 | 5b4029ded6009 | 1530931678.877 | info log
"
    [1]=>
    string(81) "2018-07-07 10:47:58 | DEBUG | 71910 | 5b4029ded6009 | 1530931678.877 | debug log
"
  }
}
bool(true)
array(0) {
}

参见

SeasLog::getBasePath

获得 SeasLog 根目录

说明

public <span class="modifier">static string <span class="methodname">Seaslog::getBasePath ( <span class="methodparam">void )

使用函数 SeasLog::getBasePath 可以获得在 php.ini(seaslog.ini) 中设置的seaslog.default_basepath

如果使用函数 <span class="methodname">Seaslog::setBasePath,将改变函数取值。

参数

此函数没有参数。

返回值

Return seaslog.default_basepath as string.

范例

示例 #1 SeasLog::getBasePath example

<?php

var_dump(SeasLog::getBasePath());

?>

以上例程的输出类似于:

string(12) "/var/log/www"

SeasLog::getBuffer

获取内存中的日志缓存数组

说明

public <span class="modifier">static array <span class="methodname">SeasLog::getBuffer ( <span class="methodparam">void )

参数

此函数没有参数。

返回值

以 Array 形式返回内存中的日志缓存。

范例

示例 #1 SeasLog::getBuffer example

<?php

var_dump(SeasLog::info('info log'));
var_dump(SeasLog::debug('debug log'));
var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

bool(true)
bool(true)
array(1) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(79) "2018-07-07 10:43:32 | INFO | 71785 | 5b4028d4c58d5 | 1530931412.810 | info log
"
    [1]=>
    string(81) "2018-07-07 10:43:32 | DEBUG | 71785 | 5b4028d4c58d5 | 1530931412.810 | debug log
"
  }
}

参见

SeasLog::getBufferEnabled

Determin if buffer enabled

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::getBufferEnabled ( <span class="methodparam">void )

Result join seaslog.use_buffer and seaslog.buffer_disabled_in_cli.

参数

此函数没有参数。

返回值

Return TRUE on seaslog.use_buffer is true. If switch seaslog.buffer_disabled_in_cli on, and running in cli, seaslog.use_buffer setting will be discarded, Seaslog write to the Data Store IMMEDIATELY.

范例

示例 #1 SeasLog::getBufferEnabled example

<?php

var_dump(SeasLog::getBufferEnabled());

?>

以上例程的输出类似于:

bool(false)

参见

SeasLog::getDatetimeFormat

获取 SeasLog 日期格式

说明

public <span class="modifier">static string <span class="methodname">SeasLog::getDatetimeFormat ( <span class="methodparam">void )

获取 SeasLog 日期格式。 使用函数 <span class="methodname">SeasLog::getDatetimeFormat 将获取 php.ini(seaslog.ini) 配置的 seaslog.default_datetime_format 值。

参数

此函数没有参数。

返回值

获取 SeasLog 配置中的 seaslog.default_datetime_format 值。 使用函数 SeasLog::setDatetimeFormat 将改变本函数的取值。

范例

示例 #1 SeasLog::getDatetimeFormat example

<?php

var_dump(SeasLog::getDateTimeFormat());
var_dump(SeasLog::setDateTimeFormat('Ymd His'));
var_dump(SeasLog::getDateTimeFormat());

?>

以上例程的输出类似于:

string(11) "Y-m-d H:i:s"
bool(true)
string(7) "Ymd His"

参见

  • SeasLog::setDatetimeFormat

SeasLog::getLastLogger

获得 SeasLog 最近的一次 Logger 名称

说明

public <span class="modifier">static string <span class="methodname">SeasLog::getLastLogger ( <span class="methodparam">void )

使用函数 SeasLog::getLastLogger 将获取 php.ini(seaslog.ini) 中配置的 seaslog.default_logger 值。

参数

此函数没有参数。

返回值

使用函数 SeasLog::setLogger 将改变函数 SeasLog::getLastLogger 的取值。

范例

示例 #1 SeasLog::getLastLogger example

<?php

var_dump(SeasLog::getLastLogger());
SeasLog::setLogger('theNewLogger');
var_dump(SeasLog::getLastLogger());
?>

以上例程的输出类似于:

string(7) "default"
string(12) "theNewLogger"

参见

  • SeasLog::setLogger

SeasLog::getRequestID

获得当前 SeasLog 中用于区分请求的 request_id

说明

public <span class="modifier">static string <span class="methodname">SeasLog::getRequestID ( <span class="methodparam">void )

为了区分一个独立的请求,如果没有调用函数 <span class="methodname">SeasLog::setRequestId 进行指定,SeasLog 将会在请求初始化时,使用内置函数 `static char *get_uniqid ()` 生成一个 unique 值。

参数

此函数没有参数。

返回值

返回一个由内置函数 `static char *get_uniqid ()` 生成的、 或由用户调用函数 SeasLog::setRequestId 指定的字符串。

范例

示例 #1 SeasLog::getRequestID example

<?php

var_dump(SeasLog::getRequestID());
var_dump(SeasLog::setRequestID('reqeust_id_test_'.time()))
var_dump(SeasLog::getRequestID());

?>

以上例程的输出类似于:

string(13) "5b3f21a209519"
bool(true)
string(26) "reqeust_id_test_1530864034"

参见

SeasLog::getRequestVariable

Get SeasLog request variable

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::getRequestVariable ( <span class="methodparam">int $key )

Get SeasLog request variable.

参数

key
Constant int.

返回值

Return request variable value on set success.

范例

示例 #1 SeasLog::getRequestVariable example

<?php

$sDomainPort = 'domain:port';
$sRequestUri = 'uri';
$sRequestMethod = 'method';
$sClientIp = 'client_ip';

$iErrorKey = 1000;

$oSeasLog = new SeasLog();

var_dump($oSeasLog->setRequestVariable(SEASLOG_REQUEST_VARIABLE_DOMAIN_PORT, $sDomainPort));
var_dump($oSeasLog->setRequestVariable(SEASLOG_REQUEST_VARIABLE_REQUEST_URI, $sRequestUri));
var_dump($oSeasLog->setRequestVariable(SEASLOG_REQUEST_VARIABLE_REQUEST_METHOD, $sRequestMethod));
var_dump($oSeasLog->setRequestVariable(SEASLOG_REQUEST_VARIABLE_CLIENT_IP, $sClientIp));

var_dump($oSeasLog->setRequestVariable($iErrorKey,NULL));

var_dump($oSeasLog->getRequestVariable(SEASLOG_REQUEST_VARIABLE_DOMAIN_PORT) == $sDomainPort);
var_dump($oSeasLog->getRequestVariable(SEASLOG_REQUEST_VARIABLE_REQUEST_URI) == $sRequestUri);
var_dump($oSeasLog->getRequestVariable(SEASLOG_REQUEST_VARIABLE_REQUEST_METHOD) == $sRequestMethod);
var_dump($oSeasLog->getRequestVariable(SEASLOG_REQUEST_VARIABLE_CLIENT_IP) == $sClientIp);

var_dump($oSeasLog->getRequestVariable($iErrorKey));

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)

参见

  • SeasLog::setRequestVariable

SeasLog::info

Record info log information

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::info ( <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]] )

记录 info 日志

Note:

"INFO" - 重要事件、强调应用程序的运行过程。

参数

message
The log message.

content
"消息"包含占位符,实现用 content 数组中的值替换这些占位符。 例如'消息'是 `log info from {NAME}`, '内容'是 `array('NAME' => neeke)`, 日志信息是 `log info from neeke`

logger
当函数调用 SeasLog::setLogger() 时,就像临时 logger 一样,在第三个参数中使用这个"logger"。 如果 `logger` 为NULL 或 "",那么 SeasLog 将使用由 <span class="methodname">SeasLog::setLogger设置的最新日志记录程序。

返回值

记录日志信息成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::info example

<?php

var_dump(SeasLog::info('log message'));

//with content
var_dump(SeasLog::info('log message from {NAME}',array('NAME' => 'neeke')));

//with tmp logger
var_dump(SeasLog::info('log message from {NAME}',array('NAME' => 'neeke'),'tmp_logger'));

var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
array(2) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(81) "2018-07-07 11:45:49 | INFO | 73263 | 5b40376d1067c | 1530935149.68 | log message
"
    [1]=>
    string(92) "2018-07-07 11:45:49 | INFO | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
  ["/var/log/www/tmp_logger/20180707.log"]=>
  array(1) {
    [0]=>
    string(92) "2018-07-07 11:45:49 | INFO | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
}

参见

  • seaslog.default_template
  • SeasLog::debug
  • SeasLog::notice
  • SeasLog::warning
  • SeasLog::error
  • SeasLog::critical
  • SeasLog::alert
  • SeasLog::emergency
  • SeasLog::log

SeasLog::log

公共的日志记录函数

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::log ( <span class="type">string $level [, <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]]] )

公共的日志记录函数。可用于调用者扩展日志模板或级别。

参数

level
可以使用以下预设级别:

或者你可以自助创建新的级别。

message
日志消息

content
"消息"包含占位符,实现用 content 数组中的值替换这些占位符。 例如'消息'是 `log info from {NAME}`, '内容'是 `array('NAME' => neeke)`, 日志信息是 `log info from neeke`

logger
当函数调用 SeasLog::setLogger() 时,就像临时 logger 一样,在第三个参数中使用这个"logger"。 如果 `logger` 为 NULL 或 "",那么 SeasLog 将使用由 <span class="methodname">SeasLog::setLogger设置的最新 Logger。

返回值

记录日志信息成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::log example

<?php

var_dump(SeasLog::log(SEASLOG_INFO,'info log'));
var_dump(SeasLog::getBuffer());

//create a new level self-help.
var_dump(SeasLog::log('MySelfLevel','info log'));
var_dump(SeasLog::getBuffer());

//with `content`
var_dump(SeasLog::log('MySelfLevel','info log {NAME}',array('NAME' => 'neeke')));
var_dump(SeasLog::getBuffer());

//with `logger`
var_dump(SeasLog::log('MySelfLevel','info log {NAME}',array('NAME' => 'neeke'),'tmp_logger'));
var_dump(SeasLog::getBuffer());


?>

以上例程的输出类似于:

bool(true)
array(1) {
  ["/var/log/www/default/20180707.log"]=>
  array(1) {
    [0]=>
    string(79) "2018-07-07 11:12:37 | INFO | 72427 | 5b402fa56a2ea | 1530933157.436 | info log
"
  }
}

bool(true)
array(1) {
  ["/var/log/www/default/20180707.log"]=>
  array(1) {
    [0]=>
    string(86) "2018-07-07 11:13:59 | MySelfLevel | 72470 | 5b402ff781c5e | 1530933239.532 | info log
"
  }
}

bool(true)
array(1) {
  ["/var/log/www/tmp_logger/20180707.log"]=>
  array(1) {
    [0]=>
    string(92) "2018-07-07 11:28:12 | MySelfLevel | 72833 | 5b40334ce6a2f | 1530934092.946 | info log neeke
"
  }
}

bool(true)
array(1) {
  ["/var/log/www/default/20180707.log"]=>
  array(1) {
    [0]=>
    string(86) "2018-07-07 11:20:12 | INFO | 72616 | 5b40316c3641e | 1530933612.222 | info log neeke
"
  }
}

参见

  • seaslog.default_template
  • SeasLog::debug
  • SeasLog::info
  • SeasLog::notice
  • SeasLog::warning
  • SeasLog::error
  • SeasLog::critical
  • SeasLog::alert
  • SeasLog::emergency

SeasLog::notice

记录 notice 日志

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::notice ( <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]] )

记录 notice 日志。

Note:

"NOTICE" - 一般重要性事件、执行过程中较 INFO 级别更为重要的信息。

参数

message
日志的消息

content
"消息"包含占位符,实现用 content 数组中的值替换这些占位符。 例如'消息'是 `log info from {NAME}`, '内容'是 `array('NAME' => neeke)`, 日志信息是 `log info from neeke`

logger
当函数调用 SeasLog::setLogger() 时,就像临时 logger 一样,在第三个参数中使用这个"logger"。 如果 `logger` 为 NULL 或 "",那么 SeasLog 将使用由 <span class="methodname">SeasLog::setLogger设置的最新 Logger。

返回值

记录日志信息成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::notice example

<?php

var_dump(SeasLog::notice('log message'));

//with content
var_dump(SeasLog::notice('log message from {NAME}',array('NAME' => 'neeke')));

//with tmp logger
var_dump(SeasLog::notice('log message from {NAME}',array('NAME' => 'neeke'),'tmp_logger'));

var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
array(2) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(81) "2018-07-07 11:45:49 | NOTICE | 73263 | 5b40376d1067c | 1530935149.68 | log message
"
    [1]=>
    string(92) "2018-07-07 11:45:49 | NOTICE | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
  ["/var/log/www/tmp_logger/20180707.log"]=>
  array(1) {
    [0]=>
    string(92) "2018-07-07 11:45:49 | NOTICE | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
}

参见

  • seaslog.default_template
  • SeasLog::debug
  • SeasLog::info
  • SeasLog::warning
  • SeasLog::error
  • SeasLog::critical
  • SeasLog::alert
  • SeasLog::emergency
  • SeasLog::log

SeasLog::setBasePath

设置 SeasLog 根目录

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::setBasePath ( <span class="methodparam">string $base_path )

设置 SeasLog 根目录。

参数

base_path
String.

返回值

设置根目录成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::setBasePath example

<?php

/* ... */

?>

以上例程的输出类似于:

...

SeasLog::setDatetimeFormat

设置 SeasLog 日期格式

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::setDatetimeFormat ( <span class="methodparam">string $format )

设置 SeasLog 日期格式。

Warning

本函数还未编写文档,仅有参数列表。

参数

format
字符串。比如 `Y-m-d H:i:s` 或者 `Ymd His`。查看函数 <span class="function">date 的第一个参数 `format`。

返回值

Return TRUE on setted datetime format success, FALSE on failure.

范例

示例 #1 SeasLog::setDatetimeFormat example

<?php

var_dump(SeasLog::setDateTimeFormat('Ymd His'));

?>

以上例程的输出类似于:

bool(true)

参见

  • SeasLog::getDateTimeFormat

SeasLog::setLogger

设置 SeasLog 的 Logger 名

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::setLogger ( <span class="methodparam">string $logger )

使用函数 SeasLog::setLogger 将改变函数 SeasLog::getLastLogger 的取值。 这意味着,SeasLog 将会把日志信息记录在该 Logger 下。

参数

logger
Logger name.

返回值

设置 Logger 成功(在存储介质为文件时将创建目录或文件)返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::setLogger example

<?php

var_dump(SeasLog::setLogger('testModule/testLogger'));

?>

以上例程的输出类似于:

bool(true)

参见

  • SeasLog::getLastLogger

SeasLog::setRequestID

设置可以由 SeasLog 用于区分请求的 request_id

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::setRequestID ( <span class="methodparam">string $request_id )

为了区分一个独立的请求,如果没有调用函数 <span class="methodname">SeasLog::setRequestId 进行指定,SeasLog 将会在请求初始化时,使用内置函数 `static char *get_uniqid ()` 生成一个 unique 值。

参数

request_id
String.

返回值

设置 request_id 成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::setRequestID example

<?php

var_dump(SeasLog::setRequestID(time() . rand()));

?>

以上例程的输出类似于:

bool(true)

参见

  • SeasLog::getRequestID

SeasLog::setRequestVariable

Manually set SeasLog request variable

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::setRequestVariable ( <span class="methodparam">int $key , <span class="methodparam">string $value )

Manually set SeasLog request variable.

参数

key
Constant int.

value
The request variable value.

返回值

Return TRUE on set success, FALSE on failure.

范例

示例 #1 SeasLog::setRequestVariable example

<?php

$sDomainPort = 'domain:port';
$sRequestUri = 'uri';
$sRequestMethod = 'method';
$sClientIp = 'client_ip';

$iErrorKey = 1000;

$oSeasLog = new SeasLog();

var_dump($oSeasLog->setRequestVariable(SEASLOG_REQUEST_VARIABLE_DOMAIN_PORT, $sDomainPort));
var_dump($oSeasLog->setRequestVariable(SEASLOG_REQUEST_VARIABLE_REQUEST_URI, $sRequestUri));
var_dump($oSeasLog->setRequestVariable(SEASLOG_REQUEST_VARIABLE_REQUEST_METHOD, $sRequestMethod));
var_dump($oSeasLog->setRequestVariable(SEASLOG_REQUEST_VARIABLE_CLIENT_IP, $sClientIp));

var_dump($oSeasLog->setRequestVariable($iErrorKey,NULL));

var_dump($oSeasLog->getRequestVariable(SEASLOG_REQUEST_VARIABLE_DOMAIN_PORT) == $sDomainPort);
var_dump($oSeasLog->getRequestVariable(SEASLOG_REQUEST_VARIABLE_REQUEST_URI) == $sRequestUri);
var_dump($oSeasLog->getRequestVariable(SEASLOG_REQUEST_VARIABLE_REQUEST_METHOD) == $sRequestMethod);
var_dump($oSeasLog->getRequestVariable(SEASLOG_REQUEST_VARIABLE_CLIENT_IP) == $sClientIp);

var_dump($oSeasLog->getRequestVariable($iErrorKey));

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)

参见

  • SeasLog::getRequestVariable

SeasLog::warning

Record warning log information

说明

public <span class="modifier">static bool <span class="methodname">SeasLog::warning ( <span class="methodparam">string $message [, array $content [, <span class="type">string $logger ]] )

Record warning log information.

Note:

"WARNING" - 出现了非错误性的异常信息、潜在异常信息、需要关注并且需要修复。

参数

message
The log message.

content
"消息"包含占位符,实现用 content 数组中的值替换这些占位符。 例如'消息'是 `log info from {NAME}`, '内容'是 `array('NAME' => neeke)`, 日志信息是 `log info from neeke`

logger
当函数调用 SeasLog::setLogger() 时,就像临时 logger 一样,在第三个参数中使用这个"logger"。 如果 `logger` 为 NULL 或 "",那么 SeasLog 将使用由 <span class="methodname">SeasLog::setLogger设置的最新 Logger。

返回值

记录日志信息成功返回 TRUE,失败返回 FALSE。

范例

示例 #1 SeasLog::warning example

<?php

var_dump(SeasLog::warning('log message'));

//with content
var_dump(SeasLog::warning('log message from {NAME}',array('NAME' => 'neeke')));

//with tmp logger
var_dump(SeasLog::warning('log message from {NAME}',array('NAME' => 'neeke'),'tmp_logger'));

var_dump(SeasLog::getBuffer());

?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
array(2) {
  ["/var/log/www/default/20180707.log"]=>
  array(2) {
    [0]=>
    string(81) "2018-07-07 11:45:49 | WARNING | 73263 | 5b40376d1067c | 1530935149.68 | log message
"
    [1]=>
    string(92) "2018-07-07 11:45:49 | WARNING | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
  ["/var/log/www/tmp_logger/20180707.log"]=>
  array(1) {
    [0]=>
    string(92) "2018-07-07 11:45:49 | WARNING | 73263 | 5b40376d1067c | 1530935149.68 | log message from neeke
"
  }
}

参见

  • seaslog.default_template
  • SeasLog::debug
  • SeasLog::info
  • SeasLog::notice
  • SeasLog::error
  • SeasLog::critical
  • SeasLog::alert
  • SeasLog::emergency
  • SeasLog::log

本站为非盈利网站,作品由网友提供上传,如无意中有侵犯您的版权,请联系删除