-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudit-streamer.service.ts
39 lines (36 loc) · 1.23 KB
/
audit-streamer.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Injectable, Logger } from '@nestjs/common';
import * as FileStreamRotator from 'file-stream-rotator';
import { KinesisService } from '../kinesis/kinesis.service';
import {
AUDIT_LOGSTREAM_DIR,
AUDIT_LOGSTREAM_MAX_LOGS,
AUDIT_LOGSTREAM_SIZE,
} from '../constants';
@Injectable()
export class AuditStreamerService {
private readonly logger = new Logger(AuditStreamerService.name);
private readonly rotatingLogStream: any;
/**
* Constructs the audit service
* @param kinesisService The Kinesis service to send audit logs to
*/
constructor(private readonly kinesisService: KinesisService) {
this.rotatingLogStream = FileStreamRotator.getStream({
filename: `${AUDIT_LOGSTREAM_DIR}/nr-broker-audit-%DATE%`,
frequency: 'daily',
date_format: 'YYYY-MM-DD',
size: AUDIT_LOGSTREAM_SIZE,
max_logs: AUDIT_LOGSTREAM_MAX_LOGS,
audit_file: `${AUDIT_LOGSTREAM_DIR}/nr-broker-audit.json`,
extension: '.log',
create_symlink: true,
symlink_name: 'nr-broker-tail-current.log',
});
}
putRecord(data: any) {
const stringData = JSON.stringify(data);
this.logger.debug(stringData);
this.rotatingLogStream.write(stringData);
this.kinesisService.putRecord(data);
}
}