-
Notifications
You must be signed in to change notification settings - Fork 34
functions_essentials_logging
Initializes the logging mechanism. Will use the ini_get('error_log') setting to ensure working logger functionality by default. You may configure multiple loggers of different classes, default is 'Logger'. Specify configuration in CONFIG variable as follows: $CONFIG['system']['logging'][<alias>] = array(<key> => <value>); <alias> is a meanful name for the logger (in fact it can be used to log to only one logger instead of logging to all). Rest is an array of key-value pairs. Following keys are supported: 'path' := absolute path in filesystem where to log 'filename_pattern' := pattern of filename. see logging_extend_logger for details 'log_severity' := true|false defines if severity shall we written to logs 'max_filesize' := maximum filesize of logs in bytes (will start rotation if hit) 'keep_for_days' := when rotated (max_filesize is set) specifies how many days rotated logs will be kept 'min_severity' := minimum severity. see Logger class for constants, but define as string like so: "WARNING" 'max_trace_depth' := maximum depth of stacktraces 'class' := Class to be used as logger (when other that 'Logger', see TraceLogger as example)
Definition: public function logging_init()
Returns: void
Add a logger.
Definition: public function logging_add_logger($alias, $conf)
Returns: void
Parameters:
-
string $aliasName for the logger -
array $confConfiguration as described in <loggin_init>
Remove a logger.
Definition: public function logging_remove_logger($alias)
Returns: void
Parameters:
-
string $aliasName for the logger
Returns a logger.
Definition: public function logging_get_logger($alias)
Returns: Logger
Parameters:
-
string $aliasName of the logger to get
Registers a class to act as request logger.
Definition: public function register_request_logger($classname)
Returns: void
Parameters:
-
string $classnameClassname of the handler, must be subclass of RequestLogEntry
Checks if there's enough memory.
Definition: public function logging_mem_ok()
Returns: bool true if ok, else false
INTERNAL Global error handler. See set_error_handler
INTERNAL Global exception handler. See set_exception_handler
INTERNAL Global shutdown handler. See
Extends a logger with a named variable. You may use this to recreate the logfile name. Variables used here will match placeholders in the logfile name (see filename_pattern config key). Currently all classes derivered from Logger know about the SERVER variable, so all keys in there will work without the need to call logging_extend_logger.
Samples: 'error{REMOTE_ADDR}.log' will become 'error_192.168.1.123.log' 'error{REMOTE_ADDR}{username}.log' will become 'error_192.168.1.123.log' until you call logging_extend_logger(<alias>,'username','daniels') and the be 'error_192.168.1.123_daniels.log'.
Note that setting extensions is only supported on a per logger basis, so you'll need a valid alias as set in initial configuration.
Definition: public function logging_extend_logger($alias, $key, $value)
Returns: void
Parameters:
-
string $aliasThe loggers alias name -
string $keyKey to use -
string $valueValue to use
Adds a category to all loggers.
Definition: public function logging_add_category($name)
Returns: void
Parameters:
-
string $nameCategory to add
Checks if a category has been added.
Definition: public function logging_has_category($name)
Returns: bool Whether the category is present.
Parameters:
-
string $nameCategory to check for
Removes a category from all loggers.
Definition: public function logging_remove_category($name)
Returns: void
Parameters:
-
string $nameCategory to remove
Sets the minimum severity to log.
Definition: public function logging_set_level($min_severity)
Returns: bool
Parameters:
-
string $min_severityA valid severity string
DEPRECATED Use logging_add_category instead Tries to set up a category for a logged in user. Checks the object store for an object with id $object_storage_id that contains a field $fieldname. Then adds content of that field as category to all loggers.
Note: This will NOT extend the logger with information as logging_extend_logger does!
SHORTCUT Logs to specified severity
SHORTCUT Logs to severity TRACE
SHORTCUT Logs to severity DEBUG
SHORTCUT Logs to severity INFO
SHORTCUT Logs to severity WARN
SHORTCUT Logs to severity ERROR
SHORTCUT Logs to severity FATAL
Logs the $label and $value arguments and then returns the $value argument. Use case:
function x($a){ return log_return("this is a",$a); } Definition: public function log_return($label, $value)
Returns: mixed $value
Parameters:
-
string $labelLabel to log -
mixed $valueValue to log
Calls log_debug if the condition is TRUE and then returns the condition. Use case:
log_if( !isset($some_var), "Missing data"); Definition: public function log_if($condition, $args)
Returns: bool Returns the $condition itself (true|false)
Parameters:
-
bool $conditiontrue or false -
mixed $argsValues to be logged
Calls log_debug if the condition is FALSE and then returns the condition. Use case:
if( log_if_not( isset($some_var), "Missing data") )
{
do_something_with($some_var);
} Definition: public function log_if_not($condition, $args)
Returns: bool
Parameters:
-
bool $conditiontrue or false -
mixed $argsValues to be logged
Starts a report named $name Returns an object of type LogReport, see doc there. Use log_report to finally write the report to logs.
Definition: public function log_start_report($name)
Returns: LogReport The new report
Parameters:
-
string $nameReport name
Writes a log-report to the logs. Use log_start_report to generate a report.
Definition: public function log_report(LogReport $report, $severity)
Returns: void
Parameters:
-
LogReport $reportThe report to log -
string $severitySeverity to log to
Renders a variable into a string representation. Feel free to use alias function render_var instead as it is shorter
Definition: public function logging_render_var($content, $stack, $indent)
Returns: string The content rendered as string
Parameters:
-
mixed $contentContent to be rendered -
array $stackIGNORE (just to detect circular references) -
string $indentIGNORE (just to have nice readable output)
SHORTCUT logging_render_var
Starts a named timer.
Definition: public function start_timer($name, $label=false)
Returns: string Timer name (the $name parameter)
Parameters:
-
string $nameName of the timer -
string $labelOptional label, defaults to $name
Set a marker in a named timer.
Definition: public function hit_timer($name, $label)
Returns: void
Parameters:
-
string $nameTimer name -
string $labelLabel to be written
Finishes a timer and writes it to log.
Definition: public function finish_timer($name, $min_ms=false)
Returns: void
Parameters:
-
string $nameTimer name -
int $min_msMinimum milliseconds that must be reached for the timer to be written to log