示例#1
0
 /**
  * Basic instantiation and config of a new Syslog Channel object
  */
 public function testSyslog()
 {
     $obj = ChannelFactory::Syslog('MyTestLogger');
     $this->assertInstanceOf('Talkback\\Channel\\Syslog', $obj);
     $this->assertInstanceOf('Talkback\\Channel\\ChannelAbstract', $obj);
     $this->assertInstanceOf('Talkback\\Object', $obj);
     $this->assertInstanceOf('Talkback\\Channel\\Channelinterface', $obj);
     $this->assertEquals('MyTestLogger', $obj->getName());
     $obj->setOption(LOG_ODELAY | LOG_PID);
     // should be fine
     $obj->setFacility(LOG_CRON);
     // should be fine
 }
示例#2
0
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @category  File
 * @package   talkback
 * @author    Chris Noden <*****@*****.**>
 * @copyright 2013 Chris Noden
 * @license   http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
 * @link      https://github.com/chrisnoden
 */
require '../vendor/autoload.php';
/**
 * Create a Talkback collection
 *
 * A File channel outputs all events to /tmp/test.log
 * A Basic channel will output CRITICAL events to console
 * A Growl channel will show all INFO events
 */
$logger = \Talkback\Logger::getLogger('complex logger');
$logger->addChannel(array(\Psr\Log\LogLevel::ERROR, \Psr\Log\LogLevel::CRITICAL, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::EMERGENCY, \Psr\Log\LogLevel::INFO, \Psr\Log\LogLevel::NOTICE, \Psr\Log\LogLevel::WARNING, \Psr\Log\LogLevel::DEBUG), \Talkback\Channel\ChannelFactory::File('/tmp/test.log'))->addChannel(\Psr\Log\LogLevel::CRITICAL, \Talkback\Channel\ChannelFactory::Basic())->addChannel(\Psr\Log\LogLevel::INFO, \Talkback\Channel\ChannelFactory::Growl('Bundle'));
/**
 * Send an INFO event which will appear in the File log and on Growl
 */
$logger->info('My goodness this is good information');
// dump the log file to the console
$file = file_get_contents('/tmp/test.log');
echo "Your file contains:" . PHP_EOL . $file;
// clean up
unlink('/tmp/test.log');
示例#3
0
 /**
  * Write out the log message to the assigned channels
  *
  * @param mixed|string $level
  * @param string       $message
  * @param array        $context
  * @return null|void
  */
 public function log($level = LogLevel::INFO, $message, array $context = array())
 {
     $oSource = self::buildSourceObject();
     $logFilename = $oSource->getFilename();
     // Populate our internal contexts if still part of the defined field list
     $aContexts = $this->_aFields;
     if (isset($this->_aFields['linenum'])) {
         $aContexts['linenum'] = $oSource->getLineNum();
     }
     if (isset($this->_aFields['filename'])) {
         $aContexts['filename'] = $logFilename;
     }
     if (isset($this->_aFields['time'])) {
         $aContexts['time'] = date('r');
     }
     if (isset($this->_aFields['level'])) {
         $aContexts['level'] = self::errorAsString($level);
     }
     // Replace with any contexts supplied in the log method request
     if (count($context) > 0) {
         $aContexts = array_replace($aContexts, $context);
     }
     if (isset($this->_aChannels[$level])) {
         /**
          * @var $oHandler ChannelAbstract
          */
         foreach ($this->_aChannels[$level] as $oHandler) {
             $oHandler->setFieldValues($aContexts);
             $oHandler->setLevel($level);
             if ($this->_block) {
                 $oHandler->disable();
             }
             $oHandler->write($message);
             $oHandler->enable();
         }
     } else {
         switch ($level) {
             case LogLevel::EMERGENCY:
             case LogLevel::ALERT:
             case LogLevel::CRITICAL:
             case LogLevel::ERROR:
             case LogLevel::WARNING:
                 $oHandler = ChannelFactory::Basic();
                 $oHandler->setFieldValues($aContexts);
                 $oHandler->setLevel($level);
                 if ($this->_block) {
                     $oHandler->disable();
                 }
                 $oHandler->write($message);
                 $oHandler->enable();
                 $oHandler = null;
                 break;
         }
     }
     // Iterate our loggers and send the message to them at the appropriate level
     /**
      * @var $oLogger \Talkback\Log\LogAbstract
      */
     foreach ($this->_aLoggers as $oLogger) {
         $oLogger->log($level, $message, $context);
     }
 }
 /**
  * Basic assertions of a new Prowl Channel object
  */
 public function testCommsProwl()
 {
     if (class_exists('Prowl\\Message')) {
         $obj = ChannelFactory::Prowl('My Test App', 'testapikey');
         $this->assertInstanceOf('Talkback\\Channel\\Prowl', $obj);
         $this->assertInstanceOf('Talkback\\Channel\\ChannelAbstract', $obj);
         $this->assertInstanceOf('Talkback\\Object', $obj);
         $this->assertInstanceOf('Talkback\\Channel\\Channelinterface', $obj);
     }
 }
示例#5
0
 /**
  * You should be able to chain the addHandler calls
  *
  * @depends testAddingValidHandler
  */
 public function testChainedHandlers()
 {
     $obj = new Router();
     $obj->addChannel(array(LogLevel::EMERGENCY, LogLevel::ERROR), ChannelFactory::Basic())->addChannel(LogLevel::INFO, ChannelFactory::Growl('Test App'));
 }