本文整理汇总了PHP中Safe::syslog方法的典型用法代码示例。如果您正苦于以下问题:PHP Safe::syslog方法的具体用法?PHP Safe::syslog怎么用?PHP Safe::syslog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Safe
的用法示例。
在下文中一共展示了Safe::syslog方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: remember
/**
* remember an event
*
* This script adds a line to temporary/log.txt, or to temporary/debug.txt.
*
* It the selected store is 'log', the function also submits a message to [code]syslog()[/code], to enable
* distributed logging.
*
* Each line of the log store is made of fields separated by tabulations:
* - time stamp (year-month-day hour:minutes:seconds)
* - surfer name, if any, or '-'
* - the label
* - the description, if any
*
* Each line of the debug store is made of fields separated by tabulations:
* - time stamp (year-month-day hour:minutes:seconds)
* - the label
* - the description, if any
*
* The description is truncated after 4 kbytes.
*
* @param string a one-line label that can be used as a mail title (e.g. 'creation of a new article')
* @param mixed a more comprehensive description, if any
* @param string either 'log' or 'debug'
* @return void
*/
public static function remember($label, $description = '', $store = 'log')
{
global $context;
// ensure we have a string
$description = Logger::to_string($description, $store != 'debug');
// cap the description, just in case...
$description = substr($description, 0, 8192);
// event saved for debugging purpose
if ($store == 'debug') {
$store = 'temporary/debug.txt';
// stamp the line
$line = gmdate('Y-m-d H:i:s') . "\t" . $label . ' ' . $description;
// event saved for later review
} else {
$store = 'temporary/log.txt';
// surfer name -- surfer.php may not be loaded yet
if (isset($_SESSION['surfer_name'])) {
$name = preg_replace('/(@.+)$/', '', $_SESSION['surfer_name']);
} else {
$name = '-';
}
// cap the description, just in case...
$description = substr($description, 0, 2048);
// strip control chars, encode new lines, single space
$from = array('/\\r/', '/\\n/', '/\\s+/');
$to = array('', '\\n', ' ');
// make a line
$line = gmdate('Y-m-d H:i:s') . "\t" . $name . "\t" . preg_replace($from, $to, strip_tags($label)) . "\t" . preg_replace($from, $to, $description);
// save it through syslog
Safe::syslog(LOG_INFO, $line);
}
// save it in a local file
if ($handle = Safe::fopen($context['path_to_root'] . $store, 'a')) {
fwrite($handle, $line . "\n");
fclose($handle);
}
}