Logger Help

Features

Logger can be used to log PHP errors and problems instead of showing them to the visitors. This way it's easieer for you to detect problemens in a website/application and solve them. And your visitors won't be bothered with ugly error messages.

There are 4 types of logging possible:

 

Use

1. Include

The first thing you need to do is including the class in your index.php file. If the class file(logger.php) is in the same directory as your current script you can use the following line of code. The next thing you need to do is create an instance of the class. The first parameter you add is the type of messages you want to log.

The second parameter is the manner of logging.

Add this code to the top of your index.php file.

include("logger.php");
$handler = new Logger(LOGGER_ALL, METHOD_PRINT);

This code above make a logger that prints all the errors to the screen.

If you use the METHOD_LOG there will be created a directory log in the same directory as the logger.php file where all the logs will be stored.

Don't forget to upload the logger.php file in the same directory as your index.php file.

2. Send emails

To send an email when there is an error you use the following code:

include("logger.php");
$handler = new Logger(LOGGER_WARNING, METHOD_EMAIL);
$handler->SetEmail("info@mymail.be");

Replace info@mymail.be in the code above with your own email address.

If there is an error in the website there will be send an email to the email address info@mymail.be with more information about the error.

It's recommended that you use LOGGER_WARNING or LOGGER_ERROR when using the mail log. Otherwise it's possible that you will be overwhelmed with mails.

3. Logger server

This function is particular handy when you have a lot of clients that you want to monitor for errors. If there is an error on one of your client websites there will be send a message to a central server. On this server you can view all the errors from all your clients.

First whe gonna install the Logger server. Open the file logserver/server.php in a texteditor and change the variable $logserver_psk to some random string you can choose. The key is needed to secure the server so that no unauthorized clients are allowed to send messages to our server. Copy the complete "logserver" directory to your own server.

The code you need to install on the clients websites is the following. Add this code to the top of the index.php file.

include("logger.php");
$handler = new Logger(LOGGER_WARNING, METHOD_SERVER);
$handler->SetServer("http://www.mywebsite.be/logserver/server.php");
$handler->SetServerPsk("the same string as $logserver_psk");

The first thing you need to change on the code above is the server address. This is the url this the server.php file you uploaded on your own server. The second thing you need to change is the server psk. That must be the same string you entered in the server.php file.