2022-03-11 10:53:32 -08:00
|
|
|
import {
|
2024-12-13 00:27:30 -08:00
|
|
|
ChangeDetectorRef,
|
2022-03-11 10:53:32 -08:00
|
|
|
Component,
|
|
|
|
|
ElementRef,
|
2024-12-13 00:27:30 -08:00
|
|
|
OnDestroy,
|
2022-03-11 10:53:32 -08:00
|
|
|
OnInit,
|
|
|
|
|
ViewChild,
|
|
|
|
|
} from '@angular/core'
|
2024-12-09 13:14:48 -08:00
|
|
|
import { filter, takeUntil, timer } from 'rxjs'
|
2022-03-11 10:53:32 -08:00
|
|
|
import { LogService } from 'src/app/services/rest/log.service'
|
2024-12-06 00:26:38 -08:00
|
|
|
import { LoadingComponentWithPermissions } from '../../loading-component/loading.component'
|
2020-10-27 01:10:18 +01:00
|
|
|
|
|
|
|
|
@Component({
|
2023-09-14 14:03:28 -07:00
|
|
|
selector: 'pngx-logs',
|
2020-10-27 01:10:18 +01:00
|
|
|
templateUrl: './logs.component.html',
|
2022-03-11 10:53:32 -08:00
|
|
|
styleUrls: ['./logs.component.scss'],
|
2020-10-27 01:10:18 +01:00
|
|
|
})
|
2024-12-06 00:26:38 -08:00
|
|
|
export class LogsComponent
|
|
|
|
|
extends LoadingComponentWithPermissions
|
|
|
|
|
implements OnInit, OnDestroy
|
|
|
|
|
{
|
2024-01-16 23:00:18 -08:00
|
|
|
constructor(
|
|
|
|
|
private logService: LogService,
|
|
|
|
|
private changedetectorRef: ChangeDetectorRef
|
2024-12-06 00:26:38 -08:00
|
|
|
) {
|
|
|
|
|
super()
|
|
|
|
|
}
|
2020-11-02 01:26:21 +01:00
|
|
|
|
2023-08-22 22:11:53 -07:00
|
|
|
public logs: string[] = []
|
2020-11-02 15:56:14 +01:00
|
|
|
|
2023-08-22 22:11:53 -07:00
|
|
|
public logFiles: string[] = []
|
2020-11-02 01:26:21 +01:00
|
|
|
|
2023-08-22 22:11:53 -07:00
|
|
|
public activeLog: string
|
|
|
|
|
|
2024-12-09 13:14:48 -08:00
|
|
|
public autoRefreshEnabled: boolean = true
|
2023-11-30 19:08:03 -08:00
|
|
|
|
2021-03-15 09:56:17 -07:00
|
|
|
@ViewChild('logContainer') logContainer: ElementRef
|
|
|
|
|
|
2021-02-06 17:07:25 +01:00
|
|
|
ngOnInit(): void {
|
2023-08-22 22:11:53 -07:00
|
|
|
this.logService
|
|
|
|
|
.list()
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
|
|
|
|
.subscribe((result) => {
|
|
|
|
|
this.logFiles = result
|
2024-12-06 00:26:38 -08:00
|
|
|
this.loading = false
|
2023-08-22 22:11:53 -07:00
|
|
|
if (this.logFiles.length > 0) {
|
|
|
|
|
this.activeLog = this.logFiles[0]
|
|
|
|
|
this.reloadLogs()
|
|
|
|
|
}
|
2024-12-09 13:14:48 -08:00
|
|
|
timer(5000, 5000)
|
|
|
|
|
.pipe(
|
|
|
|
|
filter(() => this.autoRefreshEnabled),
|
|
|
|
|
takeUntil(this.unsubscribeNotifier)
|
|
|
|
|
)
|
|
|
|
|
.subscribe(() => {
|
|
|
|
|
this.reloadLogs()
|
|
|
|
|
})
|
2023-08-22 22:11:53 -07:00
|
|
|
})
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-22 22:11:53 -07:00
|
|
|
ngOnDestroy(): void {
|
2024-12-06 00:26:38 -08:00
|
|
|
super.ngOnDestroy()
|
2023-08-22 22:11:53 -07:00
|
|
|
}
|
|
|
|
|
|
2021-02-06 17:07:25 +01:00
|
|
|
reloadLogs() {
|
2024-12-06 00:26:38 -08:00
|
|
|
this.loading = true
|
2023-08-22 22:11:53 -07:00
|
|
|
this.logService
|
|
|
|
|
.get(this.activeLog)
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
|
|
|
|
.subscribe({
|
|
|
|
|
next: (result) => {
|
|
|
|
|
this.logs = result
|
2024-12-06 00:26:38 -08:00
|
|
|
this.loading = false
|
2024-01-16 23:00:18 -08:00
|
|
|
this.scrollToBottom()
|
2023-08-22 22:11:53 -07:00
|
|
|
},
|
|
|
|
|
error: () => {
|
|
|
|
|
this.logs = []
|
2024-12-06 00:26:38 -08:00
|
|
|
this.loading = false
|
2023-08-22 22:11:53 -07:00
|
|
|
},
|
|
|
|
|
})
|
2020-11-02 15:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-06 17:07:25 +01:00
|
|
|
getLogLevel(log: string) {
|
2022-03-11 10:53:32 -08:00
|
|
|
if (log.indexOf('[DEBUG]') != -1) {
|
2021-02-06 17:07:25 +01:00
|
|
|
return 10
|
2022-03-11 10:53:32 -08:00
|
|
|
} else if (log.indexOf('[WARNING]') != -1) {
|
2021-02-06 17:07:25 +01:00
|
|
|
return 30
|
2022-03-11 10:53:32 -08:00
|
|
|
} else if (log.indexOf('[ERROR]') != -1) {
|
2021-02-06 17:07:25 +01:00
|
|
|
return 40
|
2022-03-11 10:53:32 -08:00
|
|
|
} else if (log.indexOf('[CRITICAL]') != -1) {
|
2021-02-06 17:07:25 +01:00
|
|
|
return 50
|
|
|
|
|
} else {
|
|
|
|
|
return 20
|
|
|
|
|
}
|
2020-11-02 15:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-15 09:56:17 -07:00
|
|
|
scrollToBottom(): void {
|
2024-01-16 23:00:18 -08:00
|
|
|
this.changedetectorRef.detectChanges()
|
2021-03-15 09:56:17 -07:00
|
|
|
this.logContainer?.nativeElement.scroll({
|
|
|
|
|
top: this.logContainer.nativeElement.scrollHeight,
|
|
|
|
|
left: 0,
|
2022-03-11 10:53:32 -08:00
|
|
|
behavior: 'auto',
|
|
|
|
|
})
|
2021-03-15 09:56:17 -07:00
|
|
|
}
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|