mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 10:35:12 +00:00
parent
1f890c5bed
commit
50abb51ece
4 changed files with 52 additions and 11 deletions
|
@ -125,3 +125,8 @@ autoAdmin: true
|
||||||
|
|
||||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||||
#outgoingAddressFamily: ipv4
|
#outgoingAddressFamily: ipv4
|
||||||
|
|
||||||
|
# Syslog option
|
||||||
|
#syslog:
|
||||||
|
# host: localhost
|
||||||
|
# port: 514
|
||||||
|
|
|
@ -219,6 +219,7 @@
|
||||||
"stylus": "0.54.5",
|
"stylus": "0.54.5",
|
||||||
"stylus-loader": "3.0.2",
|
"stylus-loader": "3.0.2",
|
||||||
"summaly": "2.3.0",
|
"summaly": "2.3.0",
|
||||||
|
"syslog-pro": "1.0.0",
|
||||||
"systeminformation": "4.14.4",
|
"systeminformation": "4.14.4",
|
||||||
"syuilo-password-strength": "0.0.1",
|
"syuilo-password-strength": "0.0.1",
|
||||||
"terser-webpack-plugin": "1.4.1",
|
"terser-webpack-plugin": "1.4.1",
|
||||||
|
|
|
@ -45,6 +45,11 @@ export type Source = {
|
||||||
|
|
||||||
deliverJobConcurrency?: number;
|
deliverJobConcurrency?: number;
|
||||||
inboxJobConcurrency?: number;
|
inboxJobConcurrency?: number;
|
||||||
|
|
||||||
|
syslog: {
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,6 +6,9 @@ import { program } from '../argv';
|
||||||
import { getRepository } from 'typeorm';
|
import { getRepository } from 'typeorm';
|
||||||
import { Log } from '../models/entities/log';
|
import { Log } from '../models/entities/log';
|
||||||
import { genId } from '../misc/gen-id';
|
import { genId } from '../misc/gen-id';
|
||||||
|
import config from '../config';
|
||||||
|
|
||||||
|
const SyslogPro = require('syslog-pro');
|
||||||
|
|
||||||
type Domain = {
|
type Domain = {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -18,6 +21,7 @@ export default class Logger {
|
||||||
private domain: Domain;
|
private domain: Domain;
|
||||||
private parentLogger: Logger | null = null;
|
private parentLogger: Logger | null = null;
|
||||||
private store: boolean;
|
private store: boolean;
|
||||||
|
private syslogClient: any | null = null;
|
||||||
|
|
||||||
constructor(domain: string, color?: string, store = true) {
|
constructor(domain: string, color?: string, store = true) {
|
||||||
this.domain = {
|
this.domain = {
|
||||||
|
@ -25,6 +29,20 @@ export default class Logger {
|
||||||
color: color,
|
color: color,
|
||||||
};
|
};
|
||||||
this.store = store;
|
this.store = store;
|
||||||
|
|
||||||
|
if (config.syslog) {
|
||||||
|
this.syslogClient = new SyslogPro.RFC5424({
|
||||||
|
applacationName: 'Misskey',
|
||||||
|
timestamp: true,
|
||||||
|
encludeStructuredData: true,
|
||||||
|
color: true,
|
||||||
|
extendedColor: true,
|
||||||
|
server: {
|
||||||
|
target: config.syslog.host,
|
||||||
|
port: config.syslog.port,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public createSubLogger(domain: string, color?: string, store = true): Logger {
|
public createSubLogger(domain: string, color?: string, store = true): Logger {
|
||||||
|
@ -66,6 +84,17 @@ export default class Logger {
|
||||||
console.log(important ? chalk.bold(log) : log);
|
console.log(important ? chalk.bold(log) : log);
|
||||||
|
|
||||||
if (store) {
|
if (store) {
|
||||||
|
if (this.syslogClient) {
|
||||||
|
const send =
|
||||||
|
level === 'error' ? this.syslogClient.error :
|
||||||
|
level === 'warning' ? this.syslogClient.warning :
|
||||||
|
level === 'success' ? this.syslogClient.info :
|
||||||
|
level === 'debug' ? this.syslogClient.info :
|
||||||
|
level === 'info' ? this.syslogClient.info :
|
||||||
|
null as never;
|
||||||
|
|
||||||
|
send(message);
|
||||||
|
} else {
|
||||||
const Logs = getRepository(Log);
|
const Logs = getRepository(Log);
|
||||||
Logs.insert({
|
Logs.insert({
|
||||||
id: genId(),
|
id: genId(),
|
||||||
|
@ -79,6 +108,7 @@ export default class Logger {
|
||||||
} as Log);
|
} as Log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public error(x: string | Error, data?: Record<string, any> | null, important = false): void { // 実行を継続できない状況で使う
|
public error(x: string | Error, data?: Record<string, any> | null, important = false): void { // 実行を継続できない状況で使う
|
||||||
if (x instanceof Error) {
|
if (x instanceof Error) {
|
||||||
|
|
Loading…
Reference in a new issue