Jump to content

Recommended Posts

Posted

Hi,

First off, thank you developers for this beautiful framework. I love it.

2 questions:

Is there a processwire function to log custom messages? Database or file. I'd like to use it for noncritical errors.

What is the processwirish way to deal with critical errors? Now I just throw an Exception() (gets caught).

Thanks!

Posted
Is there a processwire function to log custom messages? Database or file. I'd like to use it for noncritical errors.

bpz, welcome to the forums. Good question. You'll want to use the FileLog class:

<?php
$log = new FileLog($config->paths->logs, 'your-log-name'); 
$log->save("Your log message goes here"); 

In 'your-log-name', leave off an extension as it automatically adds a .txt extension. You'll find your log file in /site/assets/logs/.

What is the processwirish way to deal with critical errors? Now I just throw an Exception() (gets caught).

Throwing an exception is what you'd want to do if the error is fatal and you want execution to stop. It's preferable to throw a WireException rather than a normal Exception. Pass the error message to the exception. i.e.

throw new WireException("your error message here"); 

Here are the most common exception classes in PW:

WirePermissionException – what to throw when access denied and execution should stop

Wire404Exception – what to throw when resource doesn't exist and 404 page should appear

WireException – any other fatal error

Posted

Thank you for your quick reply, I will look into it. And when I get the project done, I will let you know via PM - you'll see how cool your framework is ha! :)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...