Search
Table of ContentsDeveloper's Manual
Check form data Index Reading and writing of profile settings

### Logging and error messages

#### Where can I find the log data?

YANA writes all log entries in a table of the database. However, this is done only, when logging is enabled. You can disable this to reserve space. This feature is disabled by default.

#### How do I enable logging?

- Log on as administrator and open the administration menu in expert mode.
- Open the option "program setup".

  Figure: options, program setup

- Activate the Journal.

  Figure: activate logging

- Save your changes.
- You can then use this menu to view log entries. After clicking on "show journal entries" you get a list of all entries. An example is given in the following figure.

  Figure: List of journal entries

  The journal does not only provide information on errors, it also saves data of recently deleted records. f you should ever accidentally delete an important record, you my always manually recover this entry with the help of the information stored in the logs.

#### How do I create a log entry?

    <?php
    global $YANA;

    /* Write a text to the logs */
    $log = new Log("My log-entry");
    $YANA->report($log);

    /* Text and dump of data */
    $dump = $some_data;
    $log  = new Log("My Log-entry",$dump);
    $YANA->report($log);

    /* view the created log-entry */
    print $log->getLog();
    ?>

#### How do I create an error message?

##### Creating error messages

You may output a text message by calling $YANA->report(Report $report).

The parameter $report is an instance of one of the following classes. These classes have the same parent class "Report".

Class | Description
--- | ---
Log | for output to log-file
Message | Success messages (screen)
Warning | Warning
Alert | Note
Error | Error

accepted types for parameter $report

The constructor function is called as follows:

new Log(string $text [, mixed $data]);

The following example writes a message in the log file, then generates a text for output on the screen.

$YANA->report( new Log("IO-ERROR: Unable to read file $a") );
$YANA->report( new Error('NOT_READABLE', array('FILE' => $a) ) );

##### Use

The parameter $text may either be an error-code, or a text message. You should use error-codes for screen output. For output in log files you should use English texts. The $data parameter is optional and may provide additional information. For example, the data set, which could not be saved, or the name of a file that could not be opened.

Valid error codes for parameter $text include (EXCERPT):

Code | Description | Text excerpt
--- | --- | ---
200 | Success | Your changes have been saved. Thank You !!!
500 | Generic error message | An error occured...
403 | Error: Permission denied. | Password required. You are entering a protected area...
INPUT_INVALID | Error: invalid input | A chosen parameter is not valid...
404 | Error: File not found | Please check the URL and try again.
ALLREADY_EXISTS | Error: Entry already exists | Unable to create an entry with the id "%ID%" because another entry with the same name already exists.
FILE_NOT_CREATED | Error: IO failure | Unable to create file %FILE%.
NOT_WRITEABLE | Error: IO failure | Unable to perform write operation on resource "%FILE%". Data could not be saved.
NOT_READABLE | Error: IO failure | Unable to perform read operation on resource "%FILE%". Data could not be read.

accepted values for parameter $text

Included token, such as% FILE% will be replaced in the following manner:

    <?php
    $YANA->report( new Warning('FILE_NOT_CREATED', array('FILE' => $a)) );
    ?>

The special thing about $ YANA->report() is, that it may simultaneously be used to send text messages to a log file and output messages on the screen. If the method is called several times, several text messages are printed.

    <?php
    $YANA->report( new Warning('FILE_NOT_CREATED', array('FILE' => $a)) );
    /* ... */
    $YANA->report( new Alert('NOT_WRITEABLE', array('FILE' => $a)) );
    /* ... */
    $YANA->report( new Error('500') );
    $YANA->report( new Log("Input/Output Error in File $a.", $lost_data) );
    return false;
    ?>

The call to Yana->report only creates the text message, but does not exit the program. In order to exit the program, use the method Yana->exitTo. Note: Do NOT use the PHP methods exit () or die(). Otherwise, no output is produced.

##### Exiting the program

The method Yana->exitTo( [string $action] ) can be used to interrupt the program and define a follow-up action to be executed. This means that the processing of the current action will be canceled and instead the script will be continued with the action $action.

The framework will send all text messages to the browser, and then call itself again. The parameter $action corresponds to the URL parameter "action".

If the parameter $action is not specified, then the front page (whatever it is) will be called instead.

You may also use the special action "null", if you just want to quit the program and NOT continue with another action.

Here is a simple example:

    <?php
    // Creating some text messages
    $YANA->report( new Log('An entry for the logs') );
    $YANA->report( new Alert('NOT_WRITEABLE', array('FILE' => $a)) );
    // stop current program and continue with action 'index'
    $YANA->exitTo('index');

    // create error message
    $YANA->report( new Error('Access denied!') );
    // exit the program (do NOT continue with another action)
    $YANA->exitTo('null');

    // exit the program and go to the front page
    $YANA->exitTo();
    ?>

Check form data Index Reading and writing of profile settings

Thomas Meyer, www.yanaframework.net