2017 © Pedro Peláez
 

library log

Small group of classes to build upon. Logs timestamps in code

image

toeswade/log

Small group of classes to build upon. Logs timestamps in code

  • Monday, October 19, 2015
  • by aa222di
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Clog

- a simple logger class based on lydia/Clog

This class has no dependencies and can easily be implemented in any project. It saves timestamps in memory and renders a table at the end of the page., (*1)

Code Example

Create the $Clog object in the top of your script, (*2)

$Clog = new Toeswade\Log\Clog();

Later use it in the classes you want to log . Note that the logger has to be accessible from your class, (*3)

class Test 
{
    private $logger;

    public function __construct( \Toeswade\Log\Clog $Clog) {
        $this->logger = $Clog;
    }

    /*
     * Some method
     */
    public function test() {
        $this->logger->stamp(__CLASS__, __METHOD__, 'Method starts');
        // Some code
        $this->logger->stamp(__CLASS__, __METHOD__, 'Method ends');
    }
}

When you have logged all the timestamps of interest echo out the log table at the end of your script, (*4)

echo $Clog->renderLog();

To see the class in action look at the example that comes with the package, starting in toeswade/log/webroot/index.php, (*5)

Usage together with Anax-MVC

Installation

To start using toeswade/log together with Anax-MVC start with adding it to your composer.json "toeswade/log": "dev-master" and then run composer update to install the package., (*6)

Add the logger to DI and test it

Once you have downloaded that package add the logger to your DI-container, (*7)

        $this->setShared('logger', function () {
            $logger = new \Toeswade\Log\Clog();
            return $logger;
        });

Then you can use it to set timestamps where ever you need in your code. For example in src/ThemeEngine/CThemeBasic, (*8)

    public function render()
    {
        $this->di->logger->stamp(__CLASS__, __METHOD__, 'render starts');

        //...

        $this->di->logger->stamp(__CLASS__, __METHOD__, 'render ends');
    }

To see your log just echo it at the end of your script, (*9)

// Render the response using theme engine.
$app->theme->render();
echo $app->logger->renderLog();

Clean out the example code

Note that the code in webroot and src/Test isn't necessary for the package to work., (*10)

Motivation

This class is part of a task in the course phpmvc at BTH, Sweden., (*11)

Tests

Build Status Scrutinizer Code Quality Code Coverage, (*12)

The Versions

19/10 2015

dev-master

9999999-dev

Small group of classes to build upon. Logs timestamps in code

  Sources   Download

MIT

The Requires

  • php >=5.4

 

by Amanda Åberg

logger education

05/10 2015

v1.0

1.0.0.0

Small group of classes to build upon. Logs timestamps in code

  Sources   Download

MIT

The Requires

  • php >=5.4

 

by Amanda Åberg

logger education