forked from mirror/misskey
parent
1f890c5bed
commit
50abb51ece
@ -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,17 +84,29 @@ export default class Logger {
|
|||||||
console.log(important ? chalk.bold(log) : log);
|
console.log(important ? chalk.bold(log) : log);
|
||||||
|
|
||||||
if (store) {
|
if (store) {
|
||||||
const Logs = getRepository(Log);
|
if (this.syslogClient) {
|
||||||
Logs.insert({
|
const send =
|
||||||
id: genId(),
|
level === 'error' ? this.syslogClient.error :
|
||||||
createdAt: new Date(),
|
level === 'warning' ? this.syslogClient.warning :
|
||||||
machine: os.hostname(),
|
level === 'success' ? this.syslogClient.info :
|
||||||
worker: worker.toString(),
|
level === 'debug' ? this.syslogClient.info :
|
||||||
domain: [this.domain].concat(subDomains).map(d => d.name),
|
level === 'info' ? this.syslogClient.info :
|
||||||
level: level,
|
null as never;
|
||||||
message: message,
|
|
||||||
data: data,
|
send(message);
|
||||||
} as Log);
|
} else {
|
||||||
|
const Logs = getRepository(Log);
|
||||||
|
Logs.insert({
|
||||||
|
id: genId(),
|
||||||
|
createdAt: new Date(),
|
||||||
|
machine: os.hostname(),
|
||||||
|
worker: worker.toString(),
|
||||||
|
domain: [this.domain].concat(subDomains).map(d => d.name),
|
||||||
|
level: level,
|
||||||
|
message: message,
|
||||||
|
data: data,
|
||||||
|
} as Log);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user