What will you learn?
- How to log data.
When developing an application, or when it is live, in some cases you want to log data. SpoonLog provides this functionality.
It will rotate the logs automatically, this means if the logfile exceeds a predefined size (500kb) it will be archived.
Using SpoonLog is very easy, just require the class and you're ready to start logging. In the example below you can see how we store a simple message.
// required classes require_once 'spoon/spoon.php'; // store a cool quote SpoonLog::write('Guards! Arrest all Gypsies driving fire engines.');
If you look in the folder that is on the same level as the spoon-folder you will see a new file called error.log. Offcourse a quote isn't a real error, in the example below you'll see how to fix this.
// required classes require_once 'spoon/spoon.php'; // store a cool quote SpoonLog::write('With a 22mm shell, "just wounding" may be difficult.', 'custom');
As you can see a new file is created, called custom.log. In the example above we added an extra parameters which indicates the type of message, possible values are: error and custom.
All of this logging is really cool, but the logfiles should have a decent location, this can be achieved by setting the logpath. The path will be used for all errors/message you log from then on. In the example below you can see how to set the path.
// required classes require_once 'spoon/spoon.php'; // set the path for the logfiles SpoonLog::setPath('/Users/tijs/Sites/spoon.local/logs'); // store a cool quote SpoonLog::write('God Moaning. The resist-once have accqo-aired a bum. They are going to ex-plod the whaleway brodge.', 'custom');
You're able to log (custom) data.