Commit f7ddd05f authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Affichage des logs dans l'interface d'administration

parent a89c8991
Loading
Loading
Loading
Loading

.jshintrc

0 → 100644
+3 −0
Original line number Diff line number Diff line
{
  "esversion": 6
}
 No newline at end of file
+17 −7
Original line number Diff line number Diff line
@@ -284,18 +284,28 @@ class AdministrationController extends AbstractOscarController implements UsePro
    public function logsAction()
    {
        $this->getOscarUserContextService()->check(Privileges::MAINTENANCE_MENU_ADMIN);

        $limit = 50;
        if ($this->isAjax()) {
            $response = shell_exec('tail -n 15 ' . $this->getOscarConfigurationService()->getLoggerFilePath());
            if ($response === null) {
                $response = "Impossible de charger les logs oscar";
            $out = [
                "file" => $this->getLoggerService()->getCurrentFile(),
                'log_level' => $this->getOscarConfigurationService()->getLoggerLevel(),
                'limits' => $limit,
            ];
            exec('tail -n 50 ' . $this->getLoggerService()->getCurrentFile(), $logs);
            if ($logs === null) {
                $logs = "Impossible de charger les logs oscar";
            }
            return $this->getResponseOk($response);
            else {
                $logs = array_reverse($logs);
                $logs = implode("\n", $logs);
            }
            $out['logs'] = $logs;
            return $this->jsonOutput($out);
        }
        return [
            'log_file'  => $this->getOscarConfigurationService()->getLoggerFilePath(),
            'log_level' => $this->getOscarConfigurationService()->getLoggerLevel(),

        ];

    }

    public function accountsAction()
+14 −0
Original line number Diff line number Diff line
@@ -9,6 +9,20 @@ use Oscar\Exception\OscarException;

class LoggerService extends Logger
{
    private string $currentFile = "";

    public function getCurrentFile(): string
    {
        return realpath($this->currentFile);
    }

    public function setCurrentFile(string $currentFile): self
    {
        $this->currentFile = $currentFile;
        return $this;
    }


    /**
     * @param $error
     * @param string $class
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ class LoggerServiceFactory implements FactoryInterface

        $logger = new LoggerService('oscar');
        $logger->pushHandler($stream);
        $logger->setCurrentFile($stream->getUrl());



        // Sortie standard (Built-in server)
        if( $configurationService->getConfiguration('log_stdout_enabled') ){
+13 −11
Original line number Diff line number Diff line
<section class="container">
    <h1><i class="icon-user-md"></i>Logs</h1>
    <p class="alert alert-info">
        Cet écran n'affiche que les 25 dernières lignes de la sortie standard <strong><?= $log_file ?></strong>. Pour afficher les logs en temps réél, connectez-vous à l'instance d'Oscar et utilisez la commande <code>tail -f <?= $log_file ?></code>.
    </p>

    <p>
        Le niveau de log est fixé à <code><?= $log_level ?></code>
    </p>

    <pre id="logs">
        TOTO

    </pre>

    <script>
@@ -20,14 +13,19 @@
                el: "#logs",
                data: {
                    logs: "Pas de logs...",
                    file: "Pas de fichier",
                    level: "INCONNU",
                    limits: 25,
                    refresh: 5,
                    loading: false
                },
                template: `
                  <div class="logger terminal" :class="{'loading': loading}">
                    <div class="terminal-header">
        <em>Mise à jour toute les {{refresh}} secondes</em>
        <i class="icon-hourglass-3"></i>
                      <em>Mise à jour toute les <strong>{{refresh}} secondes</strong>
                        des <strong>{{limits}} dernières entrées</strong><br>
                        <em>Fichier de log : <strong>{{file}}</strong>)</em><br>
                        <em>Niveau de log : <strong>{{level}}</strong></em>
                    </div>
                    <pre class="terminal-content">{{ logs }}</pre>
                  </div>`,
@@ -36,7 +34,11 @@
                        this.loading = true;
                        this.$http.get('').then(
                            ok => {
                                this.logs = ok.body;
                                console.log(ok);
                                this.logs = ok.body.logs;
                                this.level = ok.body.log_level;
                                this.limits = ok.body.limits;
                                this.file = ok.body.file;
                            },
                            ko => {
                                this.logs = "Impossible de connaitre l'état de OscarWorker : " + ko.body;
Loading