PHP Classes

File: example4.php

Recommend this page to a friend!
  Classes of Alessandro Quintiliani   Log Delta Time   example4.php   Download  
File: example4.php
Role: Example script
Content type: text/plain
Description: PHP script included in index.php and used as an example to show one type of log file (value of block code control variable prepended at each log statements)
Class: Log Delta Time
Log the time difference between PHP statements
Author: By
Last change:
Date: 8 years ago
Size: 2,938 bytes
 

Contents

Class file image Download
<?php
/*
 * ***************************************************************************************************
 *
 * File name: example4.php
 *
 * Copyright © 2015 Alessandro Quintiliani
 *
 * This file is part of LogDeltaTime.
 *
 * LogDeltaTime is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * LogDeltaTime is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LogDeltaTime. If not, see <http://www.gnu.org/licenses/>.
 *
 * ***************************************************************************************************
 */

// DEBUG OF example4.php WITH THE VALUE OF A BLOCK CODE CONTROL VARIABLE PREPENDED AT THE LOG STATEMENT INTO THE LOG FILE (invoked methods: setCtrlVar, wlog, end)

const MYVAR_VALUE = 10;
const
MAX_FACTORIAL = 14;

include (
"Class.LogDeltaTime.php");

$LOGDIR = 'log';
$LOGFILE = 'logexample4.txt';

$log = new LogDeltaTime ( $LOGDIR, $LOGFILE, 1 ); // replace the value of the third parameter with 2 to append the statements to logexample1.txt after each run of example1.php

$months = array (
       
"January",
       
"February",
       
"March",
       
"April",
       
"May",
       
"June",
       
"July",
       
"August",
       
"September",
       
"October",
       
"November",
       
"December"
);
$years = array (
       
2015,
       
2016,
       
2017,
       
2018,
       
2019,
       
2020
);

$log->setCtrlVar ( 'current_month' ); // this string must be the same name of the variable used as a
                                      // current element in the foreach loop
foreach ( $months as $current_month ) { // on each iteration, the current value of $current_month is prepended at
                                        // each message passed as an argument to any wlog method invoked inside this
                                        // loop before being written to the log file
   
$log->wlog ( "first debug message" );
   
$log->wlog ( "second debug message" );
   
$log->wlog ( "third debug message" );
}

$log->setCtrlVar ( 'current_year' ); // set a new control variable
foreach ( $years as $current_year ) { // on each iteration, the current value of $current_year is prepended at
                                      // each message passed as an argument to any wlog method invoked inside this
                                      // foreach loop before being written to the log file
   
$log->wlog ( "first debug message" );
   
$log->wlog ( "second debug message" );
   
$log->wlog ( "third debug message" );
}

$log->end ();
unset (
$log );
?>