Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logger to allow logging into multiple channels #77

Closed
AlexSkrypnyk opened this issue Mar 11, 2024 · 0 comments · Fixed by #81
Closed

Improve logger to allow logging into multiple channels #77

AlexSkrypnyk opened this issue Mar 11, 2024 · 0 comments · Fixed by #81
Assignees

Comments

@AlexSkrypnyk
Copy link
Member

Blocked by:


We need to use a centralised logging solution that would:

  1. Support logging to CLI
  2. Support logging to a file using different formats
  3. For this ticket, the logging output to CLI and files will be the same - just put everything to the log.

For logger, the solution is to use https://github.com/Seldaek/monolog as a logger with support of the logging formatters described in https://github.com/Seldaek/monolog/blob/main/doc/02-handlers-formatters-processors.md#formatters

Note that monolog uses log levels set via -v|vv|vvv to output messages:

22:58:55 ERROR     [git-artifact] ERROR
22:58:55 CRITICAL  [git-artifact] CRITICAL
22:58:55 ALERT     [git-artifact] ALERT
22:58:55 EMERGENCY [git-artifact] EMERGENCY

-v
22:59:04 NOTICE    [git-artifact] NOTICE
22:59:04 ERROR     [git-artifact] ERROR
22:59:04 CRITICAL  [git-artifact] CRITICAL
22:59:04 ALERT     [git-artifact] ALERT
22:59:04 EMERGENCY [git-artifact] EMERGENCY

-vv
22:59:08 NOTICE    [git-artifact] NOTICE
22:59:08 INFO      [git-artifact] INFO
22:59:08 ERROR     [git-artifact] ERROR
22:59:08 CRITICAL  [git-artifact] CRITICAL
22:59:08 ALERT     [git-artifact] ALERT
22:59:08 EMERGENCY [git-artifact] EMERGENCY

-vvv
$this->logger->notice('NOTICE');
$this->logger->info('INFO');
$this->logger->debug('DEBUG');
$this->logger->error('ERROR');
$this->logger->critical('CRITICAL');
$this->logger->alert('ALERT');
$this->logger->emergency('EMERGENCY');

Solution direction

  1. Add monolog/monolog as a dependency
  2. Create a LogTrait.php (for re-usability between projects). Example code below - please adjust as necessary:
<?php

namespace DrevOps\GitArtifact;

use Monolog\Logger;
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
use Symfony\Component\Console\Output\OutputInterface;

trait LogTrait {

  public static function logInit(OutputInterface $output) {
    return (new Logger('git-artifact'))->pushHandler(new ConsoleHandler($output));
  }

  public function logInfo(string $message) {
    $this->logger->notice($message);
  }

  public function logOkay(string $message) {
    $this->logger->info($message);
  }

}
  1. Add trait to the ArtifactCommand class and replace all calls to the $this->output->write() with calls to the logging trait's functions.
  2. Review and update existing Functional tests to assert that output messages are present in the output. They may also be present and no updates are required. Note: we already have a CLI command runner test helper runGitArtifactCommand() that deals with running the artifact executable and allows to assert for the output.
  3. Review and update existing testReport() to make sure that all of the logged messages are present in the report.

Add/update Functional tests to assert that output messages are present in the output. Note: we already have a CLI command runner test helper runGitArtifactCommand() that deals with running the artifact executable and allows to assert for the output, so it should be a matter of updating existing tests. It may also be a case that tests should not be updated because they already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants