diff --git a/src-ui/src/app/components/manage/logs/logs.component.html b/src-ui/src/app/components/manage/logs/logs.component.html index be14faf1d..8a2a28ef8 100644 --- a/src-ui/src/app/components/manage/logs/logs.component.html +++ b/src-ui/src/app/components/manage/logs/logs.component.html @@ -1,27 +1,18 @@ -
- -
- -
-
-
-
+ + + +
+ +

- {{log.created | customDate:'short'}} - {{getLevelText(log.level)}} - {{log.message}} -

+ class="m-0 p-0 log-entry-{{getLogLevel(log)}}" + *ngFor="let log of logs" style="white-space: pre;">{{log}}

diff --git a/src-ui/src/app/components/manage/logs/logs.component.scss b/src-ui/src/app/components/manage/logs/logs.component.scss index dee9b10dc..a99506c12 100644 --- a/src-ui/src/app/components/manage/logs/logs.component.scss +++ b/src-ui/src/app/components/manage/logs/logs.component.scss @@ -13,4 +13,12 @@ .log-entry-50 { color: lightcoral !important; font-weight: bold; +} + +.log-container { + + overflow: scroll; + + height: calc(100vh - 190px); + top: 70px; } \ No newline at end of file diff --git a/src-ui/src/app/components/manage/logs/logs.component.ts b/src-ui/src/app/components/manage/logs/logs.component.ts index b131796ee..0754e4253 100644 --- a/src-ui/src/app/components/manage/logs/logs.component.ts +++ b/src-ui/src/app/components/manage/logs/logs.component.ts @@ -1,5 +1,4 @@ -import { Component, OnInit } from '@angular/core'; -import { LOG_LEVELS, LOG_LEVEL_INFO, PaperlessLog } from 'src/app/data/paperless-log'; +import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; import { LogService } from 'src/app/services/rest/log.service'; @Component({ @@ -11,38 +10,42 @@ export class LogsComponent implements OnInit { constructor(private logService: LogService) { } - logs: PaperlessLog[] = [] - level: number = LOG_LEVEL_INFO + @ViewChild('logContainer') private logContainer: ElementRef + + logs: string[] = [] + + logFiles: string[] = [] + + activeLog: string ngOnInit(): void { - this.reload() - } - - reload() { - this.logService.list(1, 50, 'created', true, {'level__gte': this.level}).subscribe(result => this.logs = result.results) - } - - getLevelText(level: number) { - return LOG_LEVELS.find(l => l.id == level)?.name - } - - onScroll() { - let lastCreated = null - if (this.logs.length > 0) { - lastCreated = new Date(this.logs[this.logs.length-1].created).toISOString() - } - this.logService.list(1, 25, 'created', true, {'created__lt': lastCreated, 'level__gte': this.level}).subscribe(result => { - this.logs.push(...result.results) + this.logService.list().subscribe(result => { + this.logFiles = result + if (this.logFiles.length > 0) { + this.activeLog = this.logFiles[0] + this.reloadLogs() + } }) } - getLevels() { - return LOG_LEVELS + reloadLogs() { + this.logService.get(this.activeLog).subscribe(result => { + this.logs = result + }) } - setLevel(id) { - this.level = id - this.reload() + getLogLevel(log: string) { + if (log.indexOf("[DEBUG]") != -1) { + return 10 + } else if (log.indexOf("[WARNING]") != -1) { + return 30 + } else if (log.indexOf("[ERROR]") != -1) { + return 40 + } else if (log.indexOf("[CRITICAL]") != -1) { + return 50 + } else { + return 20 + } } } diff --git a/src-ui/src/app/data/paperless-log.ts b/src-ui/src/app/data/paperless-log.ts deleted file mode 100644 index 61a6fce99..000000000 --- a/src-ui/src/app/data/paperless-log.ts +++ /dev/null @@ -1,27 +0,0 @@ -export const LOG_LEVEL_DEBUG = 10 -export const LOG_LEVEL_INFO = 20 -export const LOG_LEVEL_WARNING = 30 -export const LOG_LEVEL_ERROR = 40 -export const LOG_LEVEL_CRITICAL = 50 - -export const LOG_LEVELS = [ - {id: LOG_LEVEL_DEBUG, name: "DEBUG"}, - {id: LOG_LEVEL_INFO, name: "INFO"}, - {id: LOG_LEVEL_WARNING, name: "WARNING"}, - {id: LOG_LEVEL_ERROR, name: "ERROR"}, - {id: LOG_LEVEL_CRITICAL, name: "CRITICAL"} -] - -export interface PaperlessLog { - - id?: number - - group?: string - - message?: string - - created?: Date - - level?: number - -} diff --git a/src-ui/src/app/services/rest/log.service.ts b/src-ui/src/app/services/rest/log.service.ts index 797d9b6b9..3abf2fb6f 100644 --- a/src-ui/src/app/services/rest/log.service.ts +++ b/src-ui/src/app/services/rest/log.service.ts @@ -1,14 +1,21 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { PaperlessLog } from 'src/app/data/paperless-log'; -import { AbstractPaperlessService } from './abstract-paperless-service'; +import { Observable } from 'rxjs'; +import { environment } from 'src/environments/environment'; @Injectable({ providedIn: 'root' }) -export class LogService extends AbstractPaperlessService { +export class LogService { - constructor(http: HttpClient) { - super(http, 'logs') + constructor(private http: HttpClient) { + } + + list(): Observable { + return this.http.get(`${environment.apiBaseUrl}logs/`) + } + + get(id: string): Observable { + return this.http.get(`${environment.apiBaseUrl}logs/${id}/`) } }