Jump to content

Hook into message() or error()


thomas
 Share

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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"); 
}
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...