better logger format, some comments

This commit is contained in:
fabrixxm 2014-04-27 15:08:21 +02:00
parent ef4ce5f795
commit 0b83432bf3
3 changed files with 30 additions and 10 deletions

View File

@ -19,6 +19,8 @@ function ref_session_read ($id) {
if(count($r)) { if(count($r)) {
$session_exists = true; $session_exists = true;
return $r[0]['data']; return $r[0]['data'];
} else {
logger("no data for session $id", LOGGER_TRACE);
} }
return ''; return '';
}} }}

View File

@ -1,4 +1,9 @@
<?php <?php
/*
* This is the old template engine, now deprecated.
* Friendica's default template engine is Smarty3 (see include/friendica_smarty.php)
*
*/
require_once 'object/TemplateEngine.php'; require_once 'object/TemplateEngine.php';
define("KEY_NOT_EXISTS", '^R_key_not_Exists^'); define("KEY_NOT_EXISTS", '^R_key_not_Exists^');

View File

@ -1,13 +1,5 @@
<?php <?php
// This is our template processor.
// $s is the string requiring macro substitution.
// $r is an array of key value pairs (search => replace)
// returns substituted string.
// WARNING: this is pretty basic, and doesn't properly handle search strings that are substrings of each other.
// For instance if 'test' => "foo" and 'testing' => "bar", testing could become either bar or fooing,
// depending on the order in which they were declared in the array.
require_once("include/template_processor.php"); require_once("include/template_processor.php");
require_once("include/friendica_smarty.php"); require_once("include/friendica_smarty.php");
@ -661,6 +653,9 @@ function attribute_contains($attr,$s) {
}} }}
if(! function_exists('logger')) { if(! function_exists('logger')) {
/* setup int->string log level map */
$LOGGER_LEVELS = array();
/** /**
* log levels: * log levels:
* LOGGER_NORMAL (default) * LOGGER_NORMAL (default)
@ -678,9 +673,16 @@ function logger($msg,$level = 0) {
// turn off logger in install mode // turn off logger in install mode
global $a; global $a;
global $db; global $db;
global $LOGGER_LEVELS;
if(($a->module == 'install') || (! ($db && $db->connected))) return; if(($a->module == 'install') || (! ($db && $db->connected))) return;
if (count($LOGGER_LEVEL)==0){
foreach (get_defined_constants() as $k=>$v){
if (substr($k,0,7)=="LOGGER_") $LOGGER_LEVELS[$v] = substr($k,7,7);
}
}
$debugging = get_config('system','debugging'); $debugging = get_config('system','debugging');
$loglevel = intval(get_config('system','loglevel')); $loglevel = intval(get_config('system','loglevel'));
$logfile = get_config('system','logfile'); $logfile = get_config('system','logfile');
@ -688,8 +690,19 @@ function logger($msg,$level = 0) {
if((! $debugging) || (! $logfile) || ($level > $loglevel)) if((! $debugging) || (! $logfile) || ($level > $loglevel))
return; return;
$callers = debug_backtrace();
$logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n",
datetime_convert(),
session_id(),
$LOGGER_LEVELS[$level],
basename($callers[0]['file']),
$callers[0]['line'],
$callers[1]['function'],
$msg
);
$stamp1 = microtime(true); $stamp1 = microtime(true);
@file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND); @file_put_contents($logfile, $logline, FILE_APPEND);
$a->save_timestamp($stamp1, "file"); $a->save_timestamp($stamp1, "file");
return; return;
}} }}