1
0
Fork 0

add logging

This commit is contained in:
Lukas Winkler 2017-09-23 14:53:07 +02:00
parent 2d3851d78f
commit 5e3e5bc802
4 changed files with 108 additions and 5 deletions

View file

@ -7,7 +7,8 @@
"slim/twig-view": "^2.2",
"knplabs/github-api": "^2.5",
"php-http/guzzle6-adapter": "^1.1",
"cache/filesystem-adapter": "^1.0"
"cache/filesystem-adapter": "^1.0",
"monolog/monolog": "^1.23"
},
"autoload":{
"psr-0":{

80
src/composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "2eaa08c8b2f79e9ac3b6669bc524c639",
"content-hash": "14a0b7b897b18b882ea252fcf4b478bd",
"packages": [
{
"name": "cache/adapter-common",
@ -694,6 +694,84 @@
],
"time": "2017-08-06T17:41:04+00:00"
},
{
"name": "monolog/monolog",
"version": "1.23.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"psr/log": "~1.0"
},
"provide": {
"psr/log-implementation": "1.0.0"
},
"require-dev": {
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
"doctrine/couchdb": "~1.0@dev",
"graylog2/gelf-php": "~1.0",
"jakub-onderka/php-parallel-lint": "0.9",
"php-amqplib/php-amqplib": "~2.4",
"php-console/php-console": "^3.1.3",
"phpunit/phpunit": "~4.5",
"phpunit/phpunit-mock-objects": "2.3.0",
"ruflin/elastica": ">=0.90 <3.0",
"sentry/sentry": "^0.13",
"swiftmailer/swiftmailer": "^5.3|^6.0"
},
"suggest": {
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
"doctrine/couchdb": "Allow sending log messages to a CouchDB server",
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
"ext-mongo": "Allow sending log messages to a MongoDB server",
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
"mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver",
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
"php-console/php-console": "Allow sending log messages to Google Chrome",
"rollbar/rollbar": "Allow sending log messages to Rollbar",
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
"sentry/sentry": "Allow sending log messages to a Sentry server"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Monolog\\": "src/Monolog"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
}
],
"description": "Sends your logs to files, sockets, inboxes, databases and various web services",
"homepage": "http://github.com/Seldaek/monolog",
"keywords": [
"log",
"logging",
"psr-3"
],
"time": "2017-06-19T01:22:40+00:00"
},
{
"name": "nikic/fast-route",
"version": "v1.2.0",

View file

@ -13,25 +13,35 @@ use Github\Client;
use Github\ResultPager;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Monolog\Logger;
class GithubImporter {
private $client;
public function __construct(Client $client)
private $logger;
public function __construct(Client $client, Logger $logger)
{
$this->client = $client;
$this->logger = $logger;
}
public function import($organization, $repository, $numIssuesPerPage)
{
$issues = $this->fetchAllIssues($organization, $repository);
$this->logger->info("saving pages");
$issuesList = new Page();
$issuesList->save($issues, $numIssuesPerPage);
$this->logger->info("saved pages");
$this->logger->info("fetching comments for issues");
foreach ($issues as $issue) {
$comments = $this->fetchAllComments($organization, $repository, $issue);
$this->logger->debug("saving comments for #" . $issue["number"]);
$instance = new Issue();
$instance->save($issue, $comments);
}
@ -55,6 +65,7 @@ class GithubImporter {
private function fetchAllIssues($organization, $repository)
{
$this->logger->info("fetching all issues");
$params = array(
$organization,
$repository,
@ -64,13 +75,15 @@ class GithubImporter {
$paginator = new ResultPager($this->client);
$issuesApi = $this->client->api('issue');
$issues = $paginator->fetchAll($issuesApi, 'all', $params);
$this->logger->info("fetched all issues");
return $issues;
}
private function fetchAllComments($organization, $repository, $issue)
{
$this->logger->debug("fetching comments for #" . $issue["number"]);
if (empty($issue['comments'])) {
$this->logger->debug("no comments for #" . $issue["number"]);
return array();
}

View file

@ -13,10 +13,21 @@
require '../vendor/autoload.php';
require '../config/config.php';
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$logger = new Logger('import_log');
$logger->pushHandler(new StreamHandler(__DIR__ . '/../tmp/import.log', Logger::DEBUG));
if (DEBUG_ENABLED) {
$logger->pushHandler(new \Monolog\Handler\ErrorLogHandler());
}
$logger->info("authenticating");
$client = helpers\GithubImporter::buildClient(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET);
$importer = new helpers\GithubImporter($client);
$importer = new helpers\GithubImporter($client, $logger);
try {
$logger->info("starting import");
$importer->import(GITHUB_ORGANIZATION, GITHUB_REPOSITORY, NUMBER_OF_ISSUES_PER_PAGE);
} catch (Exception $e) {
helpers\Mail::sendEmail('Import error', $e->getMessage(), PROJECT_EMAIL, PROJECT_EMAIL);