Skip to content

Instantly share code, notes, and snippets.

@Seldaek
Created November 16, 2012 10:35
Show Gist options
  • Save Seldaek/4086282 to your computer and use it in GitHub Desktop.
Save Seldaek/4086282 to your computer and use it in GitHub Desktop.
LoggerInterface PSR Proposal
<?php
namespace PSR\Log;
/**
* Describes a logger instance
*
* The message MUST be a string.
*
* The context array can contain arbitrary data, the only assumption that
* can be made by implementors is that if an Exception instance is given
* to produce a stack trace, it MUST be in a key named "exception".
*/
interface LoggerInterface
{
/**
* System is unusable.
*
* @param string $message
* @param array $context
* @return null
*/
public function emergency($message, array $context = array());
/**
* Action must be taken immediately.
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param string $message
* @param array $context
* @return null
*/
public function alert($message, array $context = array());
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param string $message
* @param array $context
* @return null
*/
public function critical($message, array $context = array());
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param string $message
* @param array $context
* @return null
*/
public function error($message, array $context = array());
/**
* Exceptional occurrences that are not errors.
*
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
* @param string $message
* @param array $context
* @return null
*/
public function warning($message, array $context = array());
/**
* Normal but significant events.
*
* @param string $message
* @param array $context
* @return null
*/
public function notice($message, array $context = array());
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param string $message
* @param array $context
* @return null
*/
public function info($message, array $context = array());
/**
* Detailed debug information.
*
* @param string $message
* @param array $context
* @return null
*/
public function debug($message, array $context = array());
}
<?php
namespace PSR\Log;
/**
* This Logger can be used to avoid conditional log calls
*
* Logging should always be optional, and if no logger is provided to your
* library creating a NullLogger instance to have something to throw logs at
* is a good way to avoid littering your code with `if ($this->logger) { }`
* blocks.
*/
class NullLogger implements LoggerInterface
{
/**
* {@inheritDoc}
*/
public function emergency($message, array $context = array())
{
// noop
}
/**
* {@inheritDoc}
*/
public function alert($message, array $context = array())
{
// noop
}
/**
* {@inheritDoc}
*/
public function critical($message, array $context = array())
{
// noop
}
/**
* {@inheritDoc}
*/
public function error($message, array $context = array())
{
// noop
}
/**
* {@inheritDoc}
*/
public function warning($message, array $context = array())
{
// noop
}
/**
* {@inheritDoc}
*/
public function notice($message, array $context = array())
{
// noop
}
/**
* {@inheritDoc}
*/
public function info($message, array $context = array())
{
// noop
}
/**
* {@inheritDoc}
*/
public function debug($message, array $context = array())
{
// noop
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment