Skip to content

Instantly share code, notes, and snippets.

@xtfer
Created August 5, 2014 03:44
Show Gist options
  • Save xtfer/6666a2ec9e2dc75431b1 to your computer and use it in GitHub Desktop.
Save xtfer/6666a2ec9e2dc75431b1 to your computer and use it in GitHub Desktop.
Ghost: Logger
<?php
/**
* @file
* Examples for the Ghost Logger.
*
* @license GPL v2 http://www.fsf.org/licensing/licenses/gpl.html
* @author Chris Skene chris at previousnext dot com dot au
* @copyright Copyright(c) 2014 Previous Next Pty Ltd
*/
/**
* How to use the Ghost logger.
*/
function ghost_examples_logger() {
$some_var = 'Foo';
$logger = Drupal\ghost\Logger\Logger::init('ghost');
$logger->setMessage('Things are broken: %my_thing');
$logger->setVar('%my_thing', $some_var);
$logger->setSeverity(WATCHDOG_ERROR);
$logger->log();
}
/**
* Class MyGhostCustomLogger
*
* How to extend the Logger.
*/
class MyGhostCustomLogger extends \Drupal\ghost\Logger\Logger {
/**
* Implements LoggerInterface::logWrite().
*/
public function logWrite() {
// Fire up a custom log writer and send the log somehwere!
MyLogWriter::writeSomeLog($this->getMessage(), $this->getSeverity());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment