Welcome Guest, Not a member yet? Register   Sign In
Modify the Log message (error, critical exceptions, etc)
#1

What is the recommended method to extend the file log to automatically append additional debug information to the log messages (ie IP address and current URL)? I want to keep exactly the same functionality, just adding some dynamic text to the log messages.
Reply
#2

You need to extend the system\Log\Logger.php into your app/Libraries
Then you would need to add your code to all the method that return the log message.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 10-29-2023, 06:40 AM by 5flex.)

(10-19-2023, 11:47 AM)Luppo Wrote:
What is the recommended method to extend the file log to automatically append additional debug information to the log messages (ie IP address and current URL)? I want to keep exactly the same functionality, just adding some dynamic text to the log messages.

It's very simple task... Go to app folder and open exist file Common.php. Add to file:
PHP Code:
function log_message($level$message$context = []): void
{
    $message "["$_SERVER['REMOTE_ADDR']."] ".$message;
    $logger service('logger');
    $logger->log($level$message$context);


and on exit you get (as example...):

Code:
DEBUG - 2023-10-29 07:14:52 --> [192.168.0.1] This your debug message....


Your existing function call log_message() function DON'T NEED CHANGE AT ALL!
Reply
#4

(10-29-2023, 06:39 AM)Thanks for the ideas. I ended up extending the FileHandler with a custom hahandle.5flex Wrote:
(10-19-2023, 11:47 AM)Luppo Wrote:
What is the recommended method to extend the file log to automatically append additional debug information to the log messages (ie IP address and current URL)? I want to keep exactly the same functionality, just adding some dynamic text to the log messages.

It's very simple task... Go to app folder and open exist file Common.php. Add to file:
PHP Code:
function log_message($level$message$context = []): void
{
    $message "["$_SERVER['REMOTE_ADDR']."] ".$message;
    $logger service('logger');
    $logger->log($level$message$context);


and on exit you get (as example...):

Code:
DEBUG - 2023-10-29 07:14:52 --> [192.168.0.1] This your debug message....


Your existing function call log_message() function DON'T NEED CHANGE AT ALL!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB