作者:justinpoct
项目:roadi
/**
*
* @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']);
}
}
作者:oscaragc
项目:sql-loggin
/**
* 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);
});
}
}
作者:gudongku
项目:greetin
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'));
}
作者:ilosad
项目:chamilo-lms-icpn
/**
* 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());
}
作者:loci
项目:corporation-documentatio
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;
}
作者:Tjooste
项目:cach
/**
* @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.");
}
}
}
作者:opencler
项目:exchange
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;
}
作者:soundaslee
项目:phpdoc
function setUp()
{
$logger = new \Monolog\Logger("test");
$logger->pushHandler(new SilentLogger());
$parser = new Parser($logger);
$this->result = $parser->load($this->getFile());
}
作者:visap
项目:amu
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());
}
}
}
作者:browsca
项目:browsca
/**
* 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();
}
作者:phpsourc
项目:opencler
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;
}
作者:Tigerlee198
项目:modules.zendframework.co
/**
* @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;
}
作者:olegpopadk
项目:log-decorato
public function setUp()
{
parent::setUp();
$this->monolog = new Monolog\Logger('log-decorator');
$this->handler = new Monolog\Handler\TestHandler();
$this->monolog->pushHandler($this->handler);
}
作者:ubermichae
项目:filefinde
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$logger = new Logger('filefindtest');
self::$logger->pushHandler(new TestHandler());
self::$logger->pushHandler(new StreamHandler('test.log'));
}
作者:egma
项目:symfon
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);
}
作者:opencler
项目:job
/**
* Find the next job that should be executed.
* By default, just selects any job instance that is in the database that isn't
* already executing, hasn't already been finished, and hasn't errored out.
* @return a job array (id, job_type, [user_id], [arg_id]) or {@code false} if there is none
*/
function findJob(Connection $db, Logger $logger)
{
// TODO timeout jobs
// mark all repeatedly failing jobs as failing
$execution_limit = Config::get("job_execution_limit", 5);
$q = $db->prepare("SELECT * FROM jobs WHERE is_executed=0 AND is_executing=0 AND execution_count >= ?");
$q->execute(array($execution_limit));
if ($failed = $q->fetchAll()) {
$logger->info("Found " . number_format(count($failed)) . " jobs that have executed too many times ({$execution_limit})");
foreach ($failed as $f) {
$q = $db->prepare("UPDATE jobs SET is_executed=1,is_error=1 WHERE id=?");
$q->execute(array($f['id']));
$logger->info("Marked job " . $f['id'] . " as failed");
}
}
// find first a job that has zero execution count
$q = $db->prepare("SELECT * FROM jobs WHERE " . $this->defaultFindJobQuery() . " AND execution_count=0 LIMIT 1");
$q->execute();
if ($job = $q->fetch()) {
return $job;
}
// or, any job
$q = $db->prepare("SELECT * FROM jobs WHERE " . $this->defaultFindJobQuery() . " LIMIT 1");
$q->execute();
return $q->fetch();
}
作者:Anon21
项目:movi
public function runRequest($request)
{
$c = $this->loadController($request);
$sess = \Sessionx::start();
$sess->refreshCookie();
if (is_callable(array($c, 'load'))) {
$c->name = $request;
$c->load();
$c->checkSession();
$c->dispatch();
// If the controller ask to display a different page
if ($request != $c->name) {
$new_name = $c->name;
$c = $this->loadController($new_name);
$c->name = $new_name;
$c->load();
$c->dispatch();
}
// We display the page !
$c->display();
} else {
$log = new Logger('movim');
$log->pushHandler(new SyslogHandler('movim'));
$log->addError(t("Could not call the load method on the current controller"));
}
}
作者:Nyc
项目:movi
/**
* Error Handler...
*/
function systemErrorHandler($errno, $errstr, $errfile, $errline, $errcontext = null)
{
$log = new Logger('movim');
$log->pushHandler(new SyslogHandler('movim'));
$log->addError($errstr);
return false;
}
作者:stokekl
项目:UCRes
/**
* Método constructor de la clase.
*
* Construye el log de Monolog y lo asigna a la variable de clase log.
*/
private function __construct()
{
$log = new Logger("Sistema." . $this->getAppEnv());
$log->pushHandler(new StreamHandler(__DIR__ . "/../../../storage/logs/System.log"));
$log->pushProcessor(new WebProcessor());
$this->log = $log;
}
作者:ansa
项目:php-componen
/**
* {@inheritDoc}
*/
public function register(Container $container)
{
// Append custom settings with missing params from default settings
$container['settings']['database'] = self::mergeWithDefaultSettings($container['settings']['database']);
$settings = $container['settings']['database'];
$logLevel = $settings['logger']['level'] ?? null;
$logPath = $settings['logger']['path'] ?? null;
$className = $settings['classname'] ?? null;
if (!$className) {
$className = 'Propel\\Runtime\\Connection\\ConnectionWrapper';
if ($logLevel == Logger::DEBUG) {
$className = 'Propel\\Runtime\\Connection\\ProfilerConnectionWrapper';
}
}
$manager = new ConnectionManagerSingle();
$manager->setConfiguration(['classname' => $className, 'dsn' => $settings['dsn'], 'user' => $settings['user'], 'password' => $settings['password'], 'settings' => $settings['settings']]);
$manager->setName($settings['connection']);
/** @var StandardServiceContainer $serviceContainer */
$serviceContainer = Propel::getServiceContainer();
$serviceContainer->checkVersion($settings['version']);
$serviceContainer->setAdapterClass($settings['connection'], $settings['adapter']);
$serviceContainer->setConnectionManager($settings['connection'], $manager);
$serviceContainer->setDefaultDatasource($settings['connection']);
if ($logPath && $logLevel) {
$logger = new Logger('defaultLogger');
$logger->pushHandler(new StreamHandler($logPath, $logLevel));
$serviceContainer->setLogger('defaultLogger', $logger);
if ($logLevel == Logger::DEBUG) {
/** @var ConnectionWrapper $con */
$con = Propel::getConnection();
$con->useDebug(true);
}
}
}