Skip to content

Instantly share code, notes, and snippets.

@pyaesone17
Created January 3, 2018 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyaesone17/d5ab9356b0252575867bb74aa297ed22 to your computer and use it in GitHub Desktop.
Save pyaesone17/d5ab9356b0252575867bb74aa297ed22 to your computer and use it in GitHub Desktop.
<?php
class LogManager {
protected $logger;
public function __construct($logger) {
$this->logger = $loggervar;
}
public function log($msg, $level)
{
$this->logger->write($msg,$level);
}
}
class FileLogger {
public function write($msg, $level)
{
File::wite($msg, $level);
}
}
class RedisLogger {
public function write($msg, $level)
{
Redis::write($msg,$level);
}
}
class NullLogger {
public function write()
{
// Do nothing
}
}
$logManager = new LogManager(new FileLogger);
$logManager->log('Log to file', 'ALERT');
$logManager = new LogManager(new MemoryLogger);
$logManager->log('Log to redis memory', 'ALERT');
$logManager = new LogManager(new NullLogger);
$logManager->log('Do nothing', 'ALERT');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment