2017 © Pedro Peláez
 

library logger

Php library to create logs easily and store them in Json format.

image

josantonius/logger

Php library to create logs easily and store them in Json format.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 7 Versions
  • 17 % Grown

The README.md

PHP Logger library

Latest Stable Version License, (*1)

Spanish version, (*2)

Php library to create logs easily and store them in Json format., (*3)



Requirements

This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher., (*4)

Installation

The preferred way to install this extension is through Composer., (*5)

To install PHP Logger library, simply:, (*6)

composer require Josantonius/Logger

The previous command will only install the necessary files, if you prefer to download the entire source code you can use:, (*7)

composer require Josantonius/Logger --prefer-source

You can also clone the complete repository with Git:, (*8)

$ git clone https://github.com/Josantonius/PHP-Logger.git, (*9)

Or install it manually:, (*10)

Download Logger.php:, (*11)

wget https://raw.githubusercontent.com/Josantonius/PHP-Logger/master/src/Logger.php

Download Json.php:, (*12)

wget https://raw.githubusercontent.com/Josantonius/PHP-Json/master/src/Json.php

Images

image image image image image, (*13)

Available Methods

Available methods in this library:, (*14)

- Initiator for site debug management

new Logger($path, $filename, $logNumber, $ip, $states);
Atttribute Description Type Required Default
$path Path name to save file with logs. string No null
$filename JSON file name that will save the logs. string No null
$logNumber Maximum number of logs to save to file. int No 200
$ip If you want to get to another library. string No null
$states Different states for logs. array No null

# Return (void), (*15)

- Save log line

Logger::save($type, $code, $msg, $line, $file, $data);
Atttribute Description Type Required Default
$type Error type or warning. string Yes
$code HTTP response status code. int Yes
$message Message. string Yes
$line Line from which the save is executed. int Yes
$file Filepath from which the method is called. string Yes
$data Extra custom parameters. array No 0

# Return (boolean), (*16)

- Save logs to Json file

Logger::store();

# Return (boolean), (*17)

- Get saved logs

Logger::get();

# Return (array) → logs saved, (*18)

- Define directory for scripts and get url from file

Logger::script($url);
Atttribute Description Type Required Default
$url File url. string Yes

# Return (string) → file url, (*19)

- Define directory for styles and get url from file

Logger::style($url);
Atttribute Description Type Required Default
$url File url. string Yes

# Return (string) → file url, (*20)

- Get number of logs added in the current section

Logger::added();

# Return (int) → logs added in the current section, (*21)

- Display logger section

Logger::render();

# Return (boolean true), (*22)

- Reset parameters

Logger::reset();

# Return (boolean true), (*23)

Quick Start

To use this library with Composer:, (*24)

require __DIR__ . '/vendor/autoload.php';

use Josantonius\Logger\Logger;

Or If you installed it manually, use it:, (*25)

require_once __DIR__ . '/Logger.php';
require_once __DIR__ . '/Json.php';

use Josantonius\Logger\Logger;

Usage

Example of use for this library:, (*26)

- Basic example

<?php
require __DIR__ . '/vendor/autoload.php';

use Josantonius\Logger\Logger;

new Logger();

Logger::save('SUCCESS',  100, 'msg', __LINE__, __FILE__);
Logger::save('JOIN',     200, 'msg', __LINE__, __FILE__);
Logger::save('INFO',     300, 'msg', __LINE__, __FILE__);
Logger::save('WARNING',  400, 'msg', __LINE__, __FILE__);
Logger::save('ERROR',    500, 'msg', __LINE__, __FILE__);
Logger::save('FATAL',    600, 'msg', __LINE__, __FILE__);
Logger::save('REQUEST',  700, 'msg', __LINE__, __FILE__);
Logger::save('RESPONSE', 800, 'msg', __LINE__, __FILE__);

Logger::storeLogs();

- Advanced example

<?php
require __DIR__ . '/vendor/autoload.php';

use Josantonius\Logger\Logger;

$states  = [

  'global'    => true,
  'exception' => true,
  'error'     => false,
  'notice'    => false,
  'fatal'     => true,
];

new Logger('/logger/', 'logs', 600, '58.80.84.44', $states);

Logger::save('EXCEPTION', 400, 'msg', __LINE__, __FILE__);
Logger::save('ERROR' ,    402, 'msg', __LINE__, __FILE__);
Logger::save('NOTICE',    100, 'msg', __LINE__, __FILE__);

$params = [

  'id-user'   => 68,
  'name-user' => 'Joe'
]; 

Logger::save('FATAL, 500, 'msg', __LINE__, __FILE__, $params);

Logger::storeLogs();

echo 'Logs added: ' . Logger::added();

echo 'Logs added: ' . count(Logger::get);

printf('<link href="%s">', Logger::style('http://site.com/public/css/'));

printf('<script src="%s">', Logger::script('http://site.com/public/js/'));

Logger::render();

Tests

To run tests you just need composer and to execute the following:, (*27)

git clone https://github.com/Josantonius/PHP-Logger.git

cd PHP-Logger

composer install

Run unit tests with PHPUnit:, (*28)

composer phpunit

Run PSR2 code standard tests with PHPCS:, (*29)

composer phpcs

Run PHP Mess Detector tests to detect inconsistencies in code style:, (*30)

composer phpmd

Run all previous tests:, (*31)

composer tests

If this project helps you to reduce your development time, you can sponsor me to support my open source work :blush:, (*32)

License

This repository is licensed under the MIT License., (*33)

Copyright © 2017-2022, Josantonius, (*34)

The Versions

06/01 2018

dev-master

9999999-dev

Php library to create logs easily and store them in Json format.

  Sources   Download

MIT

The Requires

 

The Development Requires

debug log php hhvm debugger

06/01 2018

1.1.5

1.1.5.0

Php library to create logs easily and store them in Json format.

  Sources   Download

MIT

The Requires

 

The Development Requires

debug log php hhvm debugger

12/11 2017

1.1.4

1.1.4.0

Php library to create logs easily and store them in Json format.

  Sources   Download

MIT

The Requires

 

The Development Requires

debug log php hhvm debugger

02/11 2017

1.1.3

1.1.3.0

Php library to create logs easily and store them in Json format.

  Sources   Download

MIT

The Requires

 

The Development Requires

debug log php hhvm debugger

17/10 2017

1.1.2

1.1.2.0

Php library to create logs easily and store them in Json format.

  Sources   Download

MIT

The Requires

 

The Development Requires

debug log php hhvm debugger

18/07 2017

1.1.1

1.1.1.0

Php library to create logs easily and store them in Json format.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

debug log php hhvm debugger

21/01 2017

1.0.0

1.0.0.0

Php library to create logs easily and store them in Json format.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

debug log php hhvm debugger