Jump to content

Recommended Posts

Posted

Hello,

I'd like to log all the messages and errors my site throws. Is there a way to hook into these methods?

Thanks,

thomas

Posted

I think you can do something like this:

For messages (warnings/informational)

$this->message($noticemessage, Notice::logOnly);'
 

For errors

$this->error($errormessage, Notice::logOnly);
 

Change logOnly to log if you want to have show the error/message on screen as well.

/Jasper

  • Like 1
Posted

Hello Jasper,

thanks for the answer. I'd like to build my own logging system so I can see exactly which messages a certain user gets. The errors and messages are already in place so I am looking for a way to hook my own logging system onto that.

Any more ideas?

Thanks,

thomas

Posted

All of the message() and error() calls end up in an API variable called $notices. You could hook after Page::render and do something like this:

$mylog = new FileLog(wire('config')->paths->logs, "mylog"); 
foreach(wire('notices') as $notice) {
  $text = $notice instanceof NoticeError ? "Error" : "Message";
  $mylog->save("$text: $notice->text"); 
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...