/**
  * Called when this object is called as a function
  *
  * @param Context $context
  * @param OptionsFactory $optionsFactory
  * @throws \Exception if haltOnError setting is true
  */
 public function __invoke(Context $context, OptionsFactory $optionsFactory)
 {
     $getopt = $context->getopt(array_keys(self::$options));
     // Get directory list
     $dirListFactory = new DirectoryListFactory();
     $dirListFactory->loadFromCommandline($getopt->get(), 2);
     $dirListFactory->loadFromStdin(new StdinReader(3));
     $dirList = $dirListFactory->getList();
     $this->logger->addDebug('Found directories', [count($dirList)]);
     // Load base options
     $baseOptions = $optionsFactory->newInstance();
     $baseOptions->validateAllRequired();
     if ($baseOptions->preview) {
         $this->logger->addNotice('PREVIEW MODE');
     }
     foreach ($dirList as $dir) {
         try {
             $this->logger->addNotice('In directory', [$dir]);
             $this->processDirectory($dir, $baseOptions, $optionsFactory);
         } catch (\Exception $e) {
             if ($baseOptions->haltOnError) {
                 throw $e;
             } elseif ($baseOptions->verbosity == 2) {
                 $this->logger->addError($e, []);
             } else {
                 $this->logger->addError($e->getMessage(), []);
             }
         }
     }
 }
Exemple #2
0
 protected function writeEntry($level, $message, $indent, $category = "", $additionalData = [])
 {
     $message = str_pad($category, 16, " ", STR_PAD_RIGHT) . "\t" . str_repeat("  ", $indent) . $message;
     switch ($level) {
         case Log::BULK_DATA_LEVEL:
             $this->logger->addDebug($message, $additionalData);
             break;
         case Log::DEBUG_LEVEL:
             $this->logger->addDebug($message, $additionalData);
             break;
         case Log::ERROR_LEVEL:
             $this->logger->addError($message, $additionalData);
             break;
         case Log::PERFORMANCE_LEVEL:
             $this->logger->addNotice($message, $additionalData);
             break;
         case Log::WARNING_LEVEL:
             $this->logger->addWarning($message, $additionalData);
             break;
         case Log::REPOSITORY_LEVEL:
             $this->logger->addNotice($message, $additionalData);
             break;
         default:
             $this->logger->addNotice($message, $additionalData);
     }
 }
 public function log($message, $priority = self::INFO)
 {
     if ($message instanceof \Exception) {
         $message = $message->getMessage();
         $context = [];
     } elseif (is_string($message)) {
         $context = [];
     } else {
         $context = $message;
         unset($context[0]);
         unset($context[1]);
         if (isset($message[1])) {
             $message = preg_replace('#\\s*\\r?\\n\\s*#', ' ', trim($message[1]));
         }
     }
     switch ($priority) {
         case self::DEBUG:
             return $this->monolog->addDebug($message, $context);
         case self::CRITICAL:
             return $this->monolog->addCritical($message, $context);
         case self::ERROR:
             return $this->monolog->addError($message, $context);
         case self::EXCEPTION:
             return $this->monolog->addEmergency($message, $context);
         case self::WARNING:
             return $this->monolog->addWarning($message, $context);
         case 'access':
             return $this->monolog->addNotice($message, $context);
         case 'emergency':
             return $this->monolog->addEmergency($message, $context);
         default:
             return $this->monolog->addInfo($message, $context);
     }
 }
 /**
  * Log a message
  *
  * @param string $message
  * @param int    $level
  * @param array $context
  * @return void
  */
 public function log($message, $level = Logger::INFO, array $context = [])
 {
     if (!$this->logger) {
         return;
     }
     if (null === $level) {
         $level = Logger::INFO;
     }
     switch ($level) {
         case Logger::DEBUG:
             $this->logger->addDebug($message, $context);
             break;
         case Logger::INFO:
             $this->logger->addInfo($message, $context);
             break;
         case Logger::NOTICE:
             $this->logger->addNotice($message, $context);
             break;
         case Logger::WARNING:
             $this->logger->addWarning($message, $context);
             break;
         case Logger::ERROR:
             $this->logger->addError($message, $context);
             break;
         case Logger::CRITICAL:
             $this->logger->addCritical($message, $context);
             break;
         case Logger::EMERGENCY:
             $this->logger->addEmergency($message, $context);
             break;
         default:
             break;
     }
 }
 protected function findTextByKey($steps, $count)
 {
     $node = $this->source;
     foreach (explode('.', $steps) as $step) {
         if (!isset($node[$step])) {
             $this->log->addWarning("Translation for '{$steps}' not found, missing key '{$step}'", [$this->language]);
             return NULL;
         }
         $node = $node[$step];
     }
     if (!is_array($node)) {
         if ($count !== NULL) {
             $this->log->addNotice("Translation for '{$steps}' has no plurals, but count '{$count}' was passed", [$this->language]);
         }
         return $node;
     }
     if ($count === NULL) {
         $this->log->addNotice("Translation for '{$steps}' has plurals, but no count was passed", [$this->language]);
     }
     $keys = $this->countToKey($count);
     foreach ($keys as $key) {
         if (isset($node[$key])) {
             return $node[$key];
         }
     }
     $this->log->addWarning("Translation for '{$steps}' is missing plurals", [$this->language]);
     return NULL;
 }
 /**
  * Отправляет сообщение в лог
  *
  * @param string $message сообщение
  * @param int    $level   уровень
  *
  * @return void
  */
 public function log($message, $level = AbstractLogger::NOTICE)
 {
     if ($level < $this->severity) {
         return;
     }
     switch ($level) {
         case AbstractLogger::EMERGENCY:
             $this->impl->addEmergency($message);
             break;
         case AbstractLogger::ALERT:
             $this->impl->addAlert($message);
             break;
         case AbstractLogger::CRITICAL:
             $this->impl->addCritical($message);
             break;
         case AbstractLogger::ERROR:
             $this->impl->addError($message);
             break;
         case AbstractLogger::WARNING:
             $this->impl->addWarning($message);
             break;
         case AbstractLogger::NOTICE:
             $this->impl->addNotice($message);
             break;
         case AbstractLogger::INFO:
             $this->impl->addInfo($message);
             break;
         case AbstractLogger::DEBUG:
             $this->impl->addDebug($message);
             break;
     }
 }
 public function run(Message $message, Discord $discord, WebSocket $webSocket, Logger $log, &$audioStreams, Channel $channel, cURL $curl)
 {
     $exp = explode(" ", $message->content);
     unset($exp[0]);
     $youtubeLink = implode(" ", $exp);
     // URL Checker
     $parts = parse_url($youtubeLink);
     if (!stristr($parts["host"], "youtube.com")) {
         return $message->reply("Error, you can only use youtube links!");
     }
     // Generate song md5
     $md5 = md5($youtubeLink);
     // Now get the mp3 from the cache
     $songFile = __DIR__ . "/../../../../../cache/songs/{$md5}.mp3";
     $dl = new YoutubeDl(["extract-audio" => true, "audio-format" => "mp3", "audio-quality" => 0, "output" => $songFile]);
     $title = "";
     try {
         $video = $dl->download($youtubeLink);
         $title = $video->getTitle();
         $log->addNotice("Downloading {$title} from YouTube");
     } catch (NotFoundException $e) {
         $log->addError("Error: the song was not found: {$e->getMessage()}");
         $message->reply("Error: the song was not found: {$e->getMessage()}");
     } catch (PrivateVideoException $e) {
         $log->addError("Error: song has been made private: {$e->getMessage()}");
         $message->reply("Error: song has been made private: {$e->getMessage()}");
     } catch (CopyrightException $e) {
         $log->addError("Error: song is under copyright: {$e->getMessage()}");
         $message->reply("Error: song is under copyright: {$e->getMessage()}");
     } catch (\Exception $e) {
         $log->addError("Error: {$e->getMessage()}");
         $message->reply("Error: {$e->getMessage()}");
     }
     $webSocket->joinVoiceChannel($channel)->then(function (VoiceClient $vc) use($message, $discord, $webSocket, $log, &$audioStreams, $channel, $curl, $songFile, $title) {
         $guildID = $message->getChannelAttribute()->guild_id;
         if (file_exists($songFile)) {
             // Add this audio stream to the array of audio streams
             $audioStreams[$guildID] = $vc;
             $vc->setFrameSize(40)->then(function () use($vc, &$audioStreams, $guildID, $songFile, $log, $message, $title, $channel) {
                 $vc->setBitrate(128000);
                 $message->reply("Now playing **{$title}** in {$channel->name}");
                 $vc->playFile($songFile, 2)->done(function () use($vc, &$audioStreams, $guildID) {
                     unset($audioStreams[$guildID]);
                     $vc->close();
                 });
             });
         }
     });
 }
 /**
  * @test
  */
 public function it_correctly_identifies_the_info()
 {
     $bugsnag = new Bugsnag_Client(self::APIKEY);
     $logger = new Logger('my_logger');
     $logger->pushHandler(new BugsnagHandler(Logger::INFO, true, 'BugsnagMonolog', $bugsnag));
     $logger->addInfo('info', ['some' => 'message']);
     $logger->addError('error', ['some' => 'message']);
     $logger->addAlert('alert', ['some' => 'message']);
     $logger->addCritical('critical', ['some' => 'message']);
     $logger->addDebug('debug', ['some' => 'message']);
     $logger->addWarning('warning', ['some' => 'message']);
     $logger->addEmergency('emergency', ['some' => 'message']);
     $logger->addNotice('notice', ['some' => 'message']);
     $this->assertTrue(true);
 }
 /**
  * Writes log in file. Do NOT actually saves the task run
  * @return bool
  */
 public function saveTaskRun()
 {
     //if monolog not found does nothing
     if (!class_exists('Monolog\\Logger')) {
         return false;
     }
     $logger = new Logger('cron_logger');
     $logger->pushHandler(new RotatingFileHandler($this->logs_folder . $this->log_name));
     $task = TaskFile::taskGet($this->task_id);
     if (self::RUN_STATUS_STARTED == $this->status) {
         $message = 'task ' . $task->getCommand() . ' just started';
     } else {
         $message = 'task ' . $task->getCommand() . ' ended with status ' . $this->status . ', execution time ' . $this->execution_time . ', output: ' . PHP_EOL . $this->output;
     }
     return $logger->addNotice($message);
 }
Exemple #10
0
 /**
  * Execution d'un plugin
  *
  * @param string  $name    Nom de l'étape
  * @param Command $command Command courante
  *
  * @return self
  * @throws Exception Des plugins
  * @throws Stop      Lors d'une demande d'arret de l'aspiration
  * @throws Abort     Pour une annulation de l'ordre d'aspi courant
  */
 private function execPlugin($name, Command $command = null)
 {
     try {
         foreach ($this->plugins as $plugin) {
             if (method_exists($plugin, $name)) {
                 $plugin->{$name}($command, $this->curContent, $this);
             }
         }
     } catch (Abort $exc) {
         $this->log->addNotice('Annulation ordre', [$command, $exc]);
         throw $exc;
     } catch (Stop $exc) {
         $this->stop();
         throw $exc;
     }
     return $this;
 }
Exemple #11
0
 /**
  * Scan entire website
  * @return void
  */
 public function scan()
 {
     // Add the root URL to the list of pages
     if ($this->rootUrl != '*') {
         $this->pages[] = $this->rootUrl;
     }
     // Give feedback on the CLI
     $this->logger->addNotice('Scanning ' . $this->rootUrl);
     // Current index at $this->pages
     $curPageIndex = 0;
     // Start looping
     while (true) {
         // Get the current pageUrl
         $curPageUrl = $this->pages[$curPageIndex];
         // Scan a single page. Returns the mixed content (if any)
         $mixedContent = $this->scanPage($curPageUrl);
         // Got mixed content
         if ($mixedContent) {
             // Add an alert for the URL
             $this->logger->addError(sprintf('%05d', $curPageIndex) . ' - ' . $curPageUrl);
             foreach ($mixedContent as $url) {
                 $this->logger->addWarning($url);
             }
         } else {
             $this->logger->addInfo(sprintf('%05d', $curPageIndex) . ' - ' . $curPageUrl);
         }
         // Done scanning all pages? Then quit! Otherwise: scan the next page
         if ($curPageIndex + 1 == sizeof($this->pages)) {
             break;
         } else {
             $curPageIndex++;
         }
     }
     // Give feedback on the CLI
     $this->logger->addNotice('Scanned ' . sizeof($this->pages) . ' pages for Mixed Content');
 }
Exemple #12
0
use sforsman\Rest\Server;
use sforsman\Rest\AbstractJsonService;
use League\Event\Emitter;
use League\Event\AbstractEvent;
use League\Event\CallbackListener;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// Setup a logger
$log = new Logger('API');
$log->pushHandler(new StreamHandler('/tmp/api_log.txt', Logger::WARNING));
// We are interested in some events generated by the server
$emitter = new Emitter();
// This will be emitted right before control is dispatched to the actual service
$callback = function (AbstractEvent $event, $param = null) use($log) {
    // In the real world, you would (for an example) validate OAuth2 headers here
    $log->addNotice(serialize($param));
};
$emitter->addListener('dispatch', CallbackListener::fromCallable($callback));
// This will be emitted when an exception is going to be processed and "converted" into JSON
$callback = function ($event, $param) use($log) {
    $log->addError($param['exception']->getMessage());
};
$emitter->addListener('exception', CallbackListener::fromCallable($callback));
// This will be emitted when an PHP error (warning, notice, fatal) has happened and the processing
$callback = function ($event, $errorStr) use($log) {
    $log->addWarning($errorStr);
};
$emitter->addListener('error', CallbackListener::fromCallable($callback));
// Create the actual REST server
$api = new Server($emitter);
// Use the built-in error handlers that prevent any default PHP behavior and ensure all errors are
 public function matchReportAction(Logger $log, Request $request)
 {
     $log->addNotice("Match data received from " . $request->getClientIp());
     $teamOneBZIDs = $this->params->get('teamOnePlayers');
     $teamTwoBZIDs = $this->params->get('teamTwoPlayers');
     $teamOnePlayers = $this->bzidsToIdArray($teamOneBZIDs);
     $teamTwoPlayers = $this->bzidsToIdArray($teamTwoBZIDs);
     $teamOne = $this->getTeam($teamOnePlayers);
     $teamTwo = $this->getTeam($teamTwoPlayers);
     // If we fail to get the the team ID for either the teams or both reported teams are the same team, we cannot
     // report the match due to it being illegal.
     // An invalid team could be found in either or both teams, so we need to check both teams and log the match
     // failure respectively.
     $error = true;
     if (!$teamOne->isValid()) {
         $log->addNotice("The BZIDs ({$teamOneBZIDs}) were not found on the same team. Match invalidated.");
     } elseif (!$teamTwo->isValid()) {
         $log->addNotice("The BZIDs ({$teamTwoBZIDs}) were not found on the same team. Match invalidated.");
     } else {
         $error = false;
     }
     if ($error) {
         throw new ForbiddenException("An invalid player was found during the match. Please message a referee to manually report the match.");
     }
     if ($teamOne->getId() == $teamTwo->getId()) {
         $log->addNotice("The '" . $teamOne->getName() . "' team played against each other in an official match. Match invalidated.");
         throw new ForbiddenException("Holy sanity check, Batman! The same team can't play against each other in an official match.");
     }
     $match = Match::enterMatch($teamOne->getId(), $teamTwo->getId(), $this->params->get('teamOneWins'), $this->params->get('teamTwoWins'), $this->params->get('duration'), null, $this->params->get('matchTime'), $teamOnePlayers, $teamTwoPlayers, $this->params->get('server'), $this->params->get('port'), $this->params->get('replayFile'), $this->params->get('mapPlayed'));
     $log->addNotice("Match reported automatically", array('winner' => array('name' => $match->getWinner()->getName(), 'score' => $match->getScore($match->getWinner())), 'loser' => array('name' => $match->getLoser()->getName(), 'score' => $match->getScore($match->getLoser())), 'eloDiff' => $match->getEloDiff()));
     // Output the match stats that will be sent back to BZFS
     return $match->getName();
 }
Exemple #14
0
 public function notice($message, $array = array())
 {
     $log = new Logger($this->logName);
     $log->pushHandler(new StreamHandler($this->logFile, Logger::NOTICE));
     $log->addNotice($message, $array);
 }
 /**
  * Adds a log record at the NOTICE level.
  *
  * @param string $message The log message
  * @param array $context The log context
  * @return Boolean Whether the record has been processed
  * @static 
  */
 public static function addNotice($message, $context = array())
 {
     return \Monolog\Logger::addNotice($message, $context);
 }
Exemple #16
0
 /**
  * Default log method
  * @param string $msg
  * @param array $context
  * @return bool
  */
 public function defaultLog($msg = '', $context = [])
 {
     return $this->logger->addNotice($msg, $this->addMinimalContext($context));
 }
Exemple #17
0
 /**
  * Prints out notice to the log
  *
  * @param $logMessage
  * @param $logData
  */
 public function notice($logMessage, $logData = array())
 {
     $this->log->addNotice($logMessage, $logData);
 }
Exemple #18
0
require 'vendor/autoload.php';
Predis\Autoloader::register();
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$app = new Slim\Slim(array('view' => new Slim\Views\Twig()));
$view = $app->view();
$view->parserExtensions = array(new \Slim\Views\TwigExtension());
$redis = new Predis\Client(array("scheme" => "tcp", "host" => "127.0.0.1", "port" => 6379));
$app->get('/hello/:name', function ($name) use($app) {
    $logPath = '/tmp/mono.log';
    $logger = new Logger('foo_test');
    $logger->pushHandler(new StreamHandler($logPath, Logger::DEBUG));
    // $logger->info()
    $logger->addInfo('info_bar');
    // $logger->notice()
    $logger->addNotice('notice_bar');
    // $logger->warning(), $logger->warn()
    $logger->addWarning('warning_bar');
    // $logger->error(), $logger->err()
    $logger->addError('error_bar');
    // $logger->critical(), $logger->crit()
    $logger->addCritical('critical_bar');
    // $logger->alert()
    $logger->addAlert('alert_bar');
    // $logger->emergency(), $logger->emerg()
    $logger->addEmergency('emergency_bar');
    $app->render('index.html', array('name' => $name));
});
$app->get('/redis', function () use($redis) {
    // PING
    echo $redis->ping();
Exemple #19
0
 public function notice($message, array $context = array())
 {
     if (isset($this->logger)) {
         $this->logger->addNotice($message, $context);
     }
 }
Exemple #20
0
 /**
  * @param string $message
  * @param array $context
  * @return bool
  */
 public function addNotice($message, array $context = array())
 {
     return parent::addNotice($message, $context);
 }
<?php

include '../vendor/autoload.php';
use Websoftwares\Monolog\Handler\ZMQHandler;
use Monolog\Logger;
try {
    $context = new \ZMQContext();
    $publisher = new \ZMQSocket($context, \ZMQ::SOCKET_PUB);
    $publisher->bind("tcp://127.0.0.1:5556");
    $handler = new ZMQHandler($publisher, \ZMQ::MODE_SNDMORE, true);
    $log = new Logger('log-channel');
    $log->pushHandler($handler);
    $i = 0;
    print "Publising on port 5556";
    while (true) {
        if ($i % 2 == 0) {
            // Log something
            $log->addWarning("Something is going wrong...");
        } else {
            // Log something
            $log->addNotice("Something is going fine :D");
        }
        $i++;
        sleep(1);
    }
} catch (\Exception $e) {
    echo $e->getMessage();
}
Exemple #22
0
 /**
  * @param ServerRequestInterface   $request
  * @param ResponseInterface        $response
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
 {
     // Log the message
     $this->logger->addNotice(sprintf('Page %s was not found', (string) $request->getUri()));
     return $this->view->render($response, 'errors/404.twig')->withStatus(404);
 }
 /**
  * @param $contents
  *
  * @return mixed
  */
 public function message($contents)
 {
     return $this->log->addNotice($contents);
 }
Exemple #24
0
<?php

use Monolog\Logger;
return array('logger' => function () {
    $logger = new Logger('HOFB');
    //$logger->pushHandler(new \Monolog\Handler\ErrorLogHandler());
    $logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stderr'));
    //$logger->pushHandler(new \Monolog\Handler\StreamHandler('/storage/logs/server.log', Logger::INFO));
    //
    //$logger->pushHandler(new \Monolog\Handler\StreamHandler('/storage/logs/server.log', Logger::DEBUG));
    $logger->addNotice('da fuq!!!');
    return $logger;
});
Exemple #25
0
 /**
  * @param $desc
  * @param $file
  */
 public static function app($desc, $file)
 {
     $log = new Logger('Project');
     $log->pushHandler(new StreamHandler(__DIR__ . "/../log/{$file}.log", Logger::INFO));
     $log->addNotice(json_encode($desc));
 }