本文整理汇总了PHP中Monolog\Logger类的典型用法代码示例。如果您正苦于以下问题:PHP Logger类的具体用法?PHP Logger怎么用?PHP Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: interventionRequestAction
/**
*
* @param Request $request
* @param string $queryString
* @param string $filename
* @return Response
*/
public function interventionRequestAction(Request $request, $queryString, $filename)
{
$log = new Logger('InterventionRequest');
$log->pushHandler(new StreamHandler(ROADIZ_ROOT . '/logs/interventionRequest.log', Logger::INFO));
try {
$cacheDir = ROADIZ_ROOT . '/cache/rendered';
if (!file_exists($cacheDir)) {
mkdir($cacheDir);
}
$conf = new Configuration();
$conf->setCachePath($cacheDir);
$conf->setImagesPath(ROADIZ_ROOT . '/files');
/*
* Handle short url with Url rewriting
*/
$expander = new ShortUrlExpander($request);
$expander->injectParamsToRequest($queryString, $filename);
/*
* Handle main image request
*/
$iRequest = new InterventionRequest($conf, $request, $log);
$iRequest->handle();
return $iRequest->getResponse();
} catch (\Exception $e) {
if (null !== $log) {
$log->error($e->getMessage());
}
return new Response($e->getMessage(), Response::HTTP_NOT_FOUND, ['content-type' => 'text/plain']);
}
}
示例2: register
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$configPath = __DIR__ . '/../config/sql-logging.php';
$this->mergeConfigFrom($configPath, 'sql-logging');
if (config('sql-logging.log', false)) {
Event::listen('illuminate.query', function ($query, $bindings, $time) {
$data = compact('bindings', 'time');
// Format binding data for sql insertion
foreach ($bindings as $i => $binding) {
if ($binding instanceof \DateTime) {
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
} else {
if (is_string($binding)) {
$bindings[$i] = "'{$binding}'";
}
}
}
// Insert bindings into query
$query = str_replace(array('%', '?'), array('%%', '%s'), $query);
$query = vsprintf($query, $bindings);
$log = new Logger('sql');
$log->pushHandler(new StreamHandler(storage_path() . '/logs/sql-' . date('Y-m-d') . '.log', Logger::INFO));
// add records to the log
$log->addInfo($query, $data);
});
}
}
示例3: run
public static function run()
{
echo "say hello on " . date('Y-m-d H:i:s');
$log = new Logger('hello');
$log->pushHandler(new StreamHandler('app.log', Logger::INFO));
$log->addInfo("say hello on " . date('Y-m-d H:i:s'));
}
示例4: setUp
/**
* Instantiate mediavorus to register the mime types
*/
public function setUp()
{
parent::setUp();
$logger = new Logger('test');
$logger->pushHandler(new NullHandler());
$mediavorus = new MediaVorus(Reader::create($logger), Writer::create($logger), FFProbe::create());
}
示例5: register
public function register(Container $container)
{
$log = new Logger('grav');
$log_file = LOG_DIR . 'grav.log';
$log->pushHandler(new StreamHandler($log_file, Logger::WARNING));
$container['log'] = $log;
}
示例6: __construct
/**
* @param array $config
* @throws \Exception
*/
protected function __construct($config)
{
parent::__construct($config);
$this->memcache = new \Memcache();
/**
* This is something tricky in PHP. If you use pconnect (p=persistent) the connection will remain open all the time.
* This is not a bad thing since we're using the cache all the time (you don't turn off the light of the kitchen if you're running in and out, switching it too much would even consume more)
* In memcache, the old but stable implementation in PHP of memcached the persistent connection works like charm
* In memcached however there is a severe bug which leads to a memory leak. If you'd take over code from this class to implement memcached, DON'T use the persistent connect!
*/
if (!isset($this->config["host"])) {
// the default host for memcached localhost
$this->config["host"] = "localhost";
}
if (!isset($this->config["port"])) {
// the default port for memcached is 11211
$this->config["port"] = 11211;
}
if (!$this->memcache->pconnect($this->config["host"], $this->config["port"])) {
if (isset($this->config["log_dir"])) {
$log_dir = rtrim($this->config["log_dir"], "/");
$log = new Logger('cache');
$log->pushHandler(new StreamHandler($log_dir . "/log_" . date('Y-m-d') . ".txt", Logger::CRITICAL));
$log->addCritical("Could not connect to memcached.", $this->config);
} else {
/*
* if we have no log directory, it's no use to throw a TDTException
*/
throw new \Exception("No connection could be made to the memcache. Please check your given configuration.");
}
}
}
示例7: fetchAllRates
function fetchAllRates(Logger $logger)
{
$url = "https://api.vircurex.com/api/get_info_for_currency.json";
$logger->info($url);
$json = Fetch::jsonDecode(Fetch::get($url));
$result = array();
$ignored = 0;
foreach ($json as $pair2 => $pairs) {
if ($pair2 == "status") {
continue;
}
foreach ($pairs as $pair1 => $market) {
if ($market['last_trade'] == 0 || $market['lowest_ask'] == 0 || $market['highest_bid'] == 0) {
// ignore empty markets
$ignored++;
continue;
}
$currency1 = $this->getCurrencyCode($pair1);
$currency2 = $this->getCurrencyCode($pair2);
if (CurrencyOrder::hasOrder($currency1) && CurrencyOrder::hasOrder($currency2)) {
if (!CurrencyOrder::isOrdered($currency1, $currency2)) {
// do not duplicate ordered currencies
continue;
}
}
$rate = array("currency1" => $currency1, "currency2" => $currency2, "last_trade" => $market['last_trade'], "volume" => $market['volume'], 'bid' => $market['highest_bid'], 'ask' => $market['lowest_ask']);
$result[] = $rate;
}
}
$logger->info("Ignored " . $ignored . " markets with last trade price of 0");
return $result;
}
示例8: setUp
function setUp()
{
$logger = new \Monolog\Logger("test");
$logger->pushHandler(new SilentLogger());
$parser = new Parser($logger);
$this->result = $parser->load($this->getFile());
}
示例9: notify
public function notify(Service\Record $record, DOMDocument $config, Logger $logger)
{
$activity = $config->getElementsByTagName('activity')->item(0);
if ($activity !== null) {
$logger->info('Create user activity template');
try {
$templates = $activity->childNodes;
for ($i = 0; $i < $templates->length; $i++) {
$template = $templates->item($i);
if (!$template instanceof DOMElement) {
continue;
}
if ($template->nodeName == 'template') {
$type = $template->getAttribute('type');
$verb = $template->getAttribute('verb');
$table = $template->getAttribute('table');
$path = $template->getAttribute('path');
$summary = $template->nodeValue;
if (isset($this->registry['table.' . $table])) {
$table = $this->registry['table.' . $table];
} else {
throw new Exception('Invalid table ' . $table);
}
if (!empty($type) && !empty($verb) && !empty($table) && !empty($summary)) {
$this->sql->insert($this->registry['table.user_activity_template'], array('type' => $type, 'verb' => $verb, 'table' => $table, 'path' => $path, 'summary' => $summary));
$logger->info('> Created user activity template');
$logger->info($summary);
}
}
}
} catch (\Exception $e) {
$logger->error($e->getMessage());
}
}
}
示例10: setUpBeforeClass
/**
* This method is called before the first test of this test class is run.
*/
public static function setUpBeforeClass()
{
// First, generate the INI files
$buildNumber = time();
$resourceFolder = __DIR__ . '/../../resources/';
self::$buildFolder = __DIR__ . '/../../build/browscap-ua-test-' . $buildNumber . '/build/';
$cacheFolder = __DIR__ . '/../../build/browscap-ua-test-' . $buildNumber . '/cache/';
// create build folder if it does not exist
if (!file_exists(self::$buildFolder)) {
mkdir(self::$buildFolder, 0777, true);
}
if (!file_exists($cacheFolder)) {
mkdir($cacheFolder, 0777, true);
}
$logger = new Logger('browscap');
$logger->pushHandler(new NullHandler(Logger::DEBUG));
$buildGenerator = new BuildGenerator($resourceFolder, self::$buildFolder);
$writerCollectionFactory = new PhpWriterFactory();
$writerCollection = $writerCollectionFactory->createCollection($logger, self::$buildFolder);
$buildGenerator->setLogger($logger)->setCollectionCreator(new CollectionCreator())->setWriterCollection($writerCollection);
$buildGenerator->run($buildNumber, false);
$cache = new File([File::DIR => $cacheFolder]);
self::$browscap = new Browscap();
self::$browscap->setCache($cache)->setLogger($logger);
self::$browscapUpdater = new BrowscapUpdater();
self::$browscapUpdater->setCache($cache)->setLogger($logger);
self::$propertyHolder = new PropertyHolder();
}
示例11: storeSupportedCurrencies
function storeSupportedCurrencies($currencies, Logger $logger)
{
$logger->info("Storing " . count($currencies) . " currencies persistently");
// find all existing currencies
$existing = $this->getSupportedCurrencies(true);
// remove removed currencies
foreach ($existing as $currency) {
if (array_search($currency, $currencies) === false) {
$logger->info("Removing currency {$currency}");
$q = $this->db->prepare("DELETE FROM account_currencies WHERE exchange=? AND currency=?");
$q->execute(array($this->exchange->getCode(), $currency));
}
}
// add new currencies
foreach ($currencies as $currency) {
if (array_search($currency, $existing) === false) {
if (strlen($currency) != 3) {
$logger->info("Ignoring currency '" . $currency . "': not three characters long");
continue;
}
$logger->info("Adding currency {$currency}");
$q = $this->db->prepare("INSERT INTO account_currencies SET exchange=?, currency=?");
$q->execute(array($this->exchange->getCode(), $currency));
}
}
// reset cache
$this->cached_currencies = null;
}
示例12: createService
/**
* @param ServiceLocatorInterface $serviceLocator
* @return Logger
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$handler = new Handler\RotatingFileHandler('data/logs/error.log');
$logger = new Logger('error-handling');
$logger->pushHandler($handler);
return $logger;
}
示例13: setUp
public function setUp()
{
parent::setUp();
$this->monolog = new Monolog\Logger('log-decorator');
$this->handler = new Monolog\Handler\TestHandler();
$this->monolog->pushHandler($this->handler);
}
示例14: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$logger = new Logger('filefindtest');
self::$logger->pushHandler(new TestHandler());
self::$logger->pushHandler(new StreamHandler('test.log'));
}
示例15: testLogsFromListeners
public function testLogsFromListeners()
{
$output = new BufferedOutput();
$output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
$handler = new ConsoleHandler(null, false);
$logger = new Logger('app');
$logger->pushHandler($handler);
$dispatcher = new EventDispatcher();
$dispatcher->addListener(ConsoleEvents::COMMAND, function () use($logger) {
$logger->addInfo('Before command message.');
});
$dispatcher->addListener(ConsoleEvents::TERMINATE, function () use($logger) {
$logger->addInfo('Before terminate message.');
});
$dispatcher->addSubscriber($handler);
$dispatcher->addListener(ConsoleEvents::COMMAND, function () use($logger) {
$logger->addInfo('After command message.');
});
$dispatcher->addListener(ConsoleEvents::TERMINATE, function () use($logger) {
$logger->addInfo('After terminate message.');
});
$event = new ConsoleCommandEvent(new Command('foo'), $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface'), $output);
$dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
$this->assertContains('Before command message.', $out = $output->fetch());
$this->assertContains('After command message.', $out);
$event = new ConsoleTerminateEvent(new Command('foo'), $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface'), $output, 0);
$dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
$this->assertContains('Before terminate message.', $out = $output->fetch());
$this->assertContains('After terminate message.', $out);
}