GithubHelp home page GithubHelp logo

fyrelog's Introduction

FyreLog

FyreLog is a free, open-source logging library for PHP.

Table Of Contents

Installation

Using Composer

composer require fyre/log

In PHP:

use Fyre\Log\Log;

Methods

Clear

Clear instances and configs.

Log::clear();

Get Config

Get a Logger config.

  • $key is a string representing the Logger key.
$config = Log::getConfig($key);

Alternatively, if the $key argument is omitted an array containing all configurations will be returned.

$config = Log::getConfig();

Get Key

Get the key for a Logger instance.

$key = Log::getKey($logger);

Has Config

Check if a Logger config exists.

  • $key is a string representing the Logger key, and will default to Log::DEFAULT.
$hasConfig = Log::hasConfig($key);

Is Loaded

Check if a Logger instance is loaded.

  • $key is a string representing the Logger key, and will default to Log::DEFAULT.
$isLoaded = Log::isLoaded($key);

Load

Load a Logger.

  • $config is an array containing configuration options.
$logger = Log::load($config);

Set Config

Set the Logger config.

  • $key is a string representing the Logger key.
  • $options is an array containing configuration options.
Log::setConfig($key, $options);

Alternatively, a single array can be provided containing key/value of configuration options.

Log::setConfig($config);

Unload

Unload a Logger.

  • $key is a string representing the Logger key, and will default to Log::DEFAULT.
$unloaded = Log::unload($key);

Use

Load a shared Logger instance.

  • $key is a string representing the Logger key, and will default to Log::DEFAULT.
$logger = Log::use($key);

Loggers

You can load a specific logger by specifying the className option of the $config variable above.

Custom loggers can be created by extending \Fyre\Log\Logger, ensuring all below methods are implemented.

Can Handle

Determine if a log level can be handled.

  • $level is a number indicating the log level.
$canHandle = $logger->canHandle($level);

By default, this method will return true if the $level is below or equal to the threshold defined in the logger config, otherwise false.

Handle

Handle a message log.

  • $type is a string representing the type of log.
  • $message is a string representing the log message.
$logger->handle($type, $message);

File

The File logger can be loaded using custom configuration.

  • $key is a string representing the logger key.
  • $options is an array containing configuration options.
    • className must be set to \Fyre\Log\Handlers\FileLogger.
    • dateFormat is a string representing the date format, and will default to "Y-m-d H:i:s".
    • threshold is a number representing the log threshold, and will default to 0.
    • suffix is a string representing the filename suffix, and will default to null.
    • path is a string representing the directory path, and will default to "/var/log".
    • extension is a string representing the file extension, and will default to "log".
    • maxSize is a number representing the maximum file size before log rotation, and will default to 1048576.
Log::setConfig($key, $options);

$logger = Log::use($key);

Logging

Generally, logging is done by calling the static methods of the Log class.

This will call the canHandle method of all defined logger configs, and if that returns true then the handle method will also be called.

The default log levels are shown below (in order of severity).

  • $message is a string representing the log message.
  • $data is an array containing data to insert into the message string.
Log::emergency($message, $data);   // 1
Log::alert($message, $data);       // 2
Log::critical($message, $data);    // 3
Log::error($message, $data);       // 4
Log::warning($message, $data);     // 5
Log::notice($message, $data);      // 6
Log::info($message, $data);        // 7
Log::debug($message, $data);       // 8

There are default placeholders that can also be used in log messages:

  • {post_vars} will be replaced with the $_POST data.
  • {get_vars} will be replaced with the $_GET data.
  • {server_vars} will be replaced with the $_SERVER data.
  • {session_vars} will be replaced with the $_SESSION data.
  • {backtrace} will be replaced with the backtrace.

See the MessageFormatter::formatMessage method for details about message formatting.

fyrelog's People

Contributors

elusivecodes avatar

Watchers

 avatar

Forkers

deawx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.