by
345 12
0
3
2,149
0
Top 1% !
Famous
Specified
Popularity: 9565th place

Published on:

No tags for this snippet yet.
LanguagePHP
SourceGitHub
SourceMyGists

custom log function for CodeIgniter

custom log function for CodeIgniter: 
log.php
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/591836/custom-log-function-for-CodeIgniter?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
<?php class example extends CI_Controller { /** * leave log message * * @access private * @param string $func (default: __FUNCTION__) * @param string $level (default: 'debug') * @param string $message (default: '') * @return void */ private function __log() { $num_arg = func_num_args(); $trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT ); $func = $trace[1]['function']; $line = $trace[0]['line']; $object = $trace[1]['object']; if ( is_object( $object ) ) $class = get_class( $object ); else $class = get_called_class(); $level = 'debug'; $message = ''; switch ( $num_arg ) { case 1: $message = func_get_arg( 0 ); break; case 2: $message = func_get_arg( 1 ); $func = method_exists( $this, func_get_arg( 0 ) ) ? func_get_arg( 0 ) : $func; $level = ( strcasecmp( $func, func_get_arg( 0 ) ) === 0 ) ? $level : func_get_arg( 0 ); break; default: list( $func, $level, $message ) = func_get_args(); if ( ! method_exists( $class, $func ) ) { // maybe swapped $temp = $func; $func = $level; $level = $func; } } $message = str_replace( PHP_EOL, '', $message ); log_message( $level, "{$class}::{$func}({$line}): {$message}" ); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus