mirror of
https://github.com/mempool/mempool.git
synced 2025-01-05 21:24:27 +01:00
Merge pull request #449 from mempool/simon/syslog-config
Syslog is now configurable with minimum priority and facility option.
This commit is contained in:
commit
221fccf3bc
@ -39,6 +39,13 @@
|
|||||||
"USERNAME": "mempool",
|
"USERNAME": "mempool",
|
||||||
"PASSWORD": "mempool"
|
"PASSWORD": "mempool"
|
||||||
},
|
},
|
||||||
|
"SYSLOG": {
|
||||||
|
"ENABLED": true,
|
||||||
|
"HOST": "127.0.0.1",
|
||||||
|
"PORT": 514,
|
||||||
|
"MIN_PRIORITY": "info",
|
||||||
|
"FACILITY": "local7"
|
||||||
|
},
|
||||||
"STATISTICS": {
|
"STATISTICS": {
|
||||||
"ENABLED": true,
|
"ENABLED": true,
|
||||||
"TX_PER_SECOND_SAMPLE_PERIOD": 150
|
"TX_PER_SECOND_SAMPLE_PERIOD": 150
|
||||||
|
@ -41,6 +41,13 @@ interface IConfig {
|
|||||||
USERNAME: string;
|
USERNAME: string;
|
||||||
PASSWORD: string;
|
PASSWORD: string;
|
||||||
};
|
};
|
||||||
|
SYSLOG: {
|
||||||
|
ENABLED: boolean;
|
||||||
|
HOST: string;
|
||||||
|
PORT: number;
|
||||||
|
MIN_PRIORITY: 'emerg' | 'alert' | 'crit' | 'err' |'warn' | 'notice' | 'info' | 'debug';
|
||||||
|
FACILITY: string;
|
||||||
|
};
|
||||||
STATISTICS: {
|
STATISTICS: {
|
||||||
ENABLED: boolean;
|
ENABLED: boolean;
|
||||||
TX_PER_SECOND_SAMPLE_PERIOD: number;
|
TX_PER_SECOND_SAMPLE_PERIOD: number;
|
||||||
@ -96,6 +103,13 @@ const defaults: IConfig = {
|
|||||||
'USERNAME': 'mempool',
|
'USERNAME': 'mempool',
|
||||||
'PASSWORD': 'mempool'
|
'PASSWORD': 'mempool'
|
||||||
},
|
},
|
||||||
|
'SYSLOG': {
|
||||||
|
'ENABLED': true,
|
||||||
|
'HOST': '127.0.0.1',
|
||||||
|
'PORT': 514,
|
||||||
|
'MIN_PRIORITY': 'info',
|
||||||
|
'FACILITY': 'local7'
|
||||||
|
},
|
||||||
'STATISTICS': {
|
'STATISTICS': {
|
||||||
'ENABLED': true,
|
'ENABLED': true,
|
||||||
'TX_PER_SECOND_SAMPLE_PERIOD': 150
|
'TX_PER_SECOND_SAMPLE_PERIOD': 150
|
||||||
@ -117,6 +131,7 @@ class Config implements IConfig {
|
|||||||
CORE_RPC: IConfig['CORE_RPC'];
|
CORE_RPC: IConfig['CORE_RPC'];
|
||||||
CORE_RPC_MINFEE: IConfig['CORE_RPC_MINFEE'];
|
CORE_RPC_MINFEE: IConfig['CORE_RPC_MINFEE'];
|
||||||
DATABASE: IConfig['DATABASE'];
|
DATABASE: IConfig['DATABASE'];
|
||||||
|
SYSLOG: IConfig['SYSLOG'];
|
||||||
STATISTICS: IConfig['STATISTICS'];
|
STATISTICS: IConfig['STATISTICS'];
|
||||||
BISQ_BLOCKS: IConfig['BISQ_BLOCKS'];
|
BISQ_BLOCKS: IConfig['BISQ_BLOCKS'];
|
||||||
BISQ_MARKETS: IConfig['BISQ_MARKETS'];
|
BISQ_MARKETS: IConfig['BISQ_MARKETS'];
|
||||||
@ -129,6 +144,7 @@ class Config implements IConfig {
|
|||||||
this.CORE_RPC = configs.CORE_RPC;
|
this.CORE_RPC = configs.CORE_RPC;
|
||||||
this.CORE_RPC_MINFEE = configs.CORE_RPC_MINFEE;
|
this.CORE_RPC_MINFEE = configs.CORE_RPC_MINFEE;
|
||||||
this.DATABASE = configs.DATABASE;
|
this.DATABASE = configs.DATABASE;
|
||||||
|
this.SYSLOG = configs.SYSLOG;
|
||||||
this.STATISTICS = configs.STATISTICS;
|
this.STATISTICS = configs.STATISTICS;
|
||||||
this.BISQ_BLOCKS = configs.BISQ_BLOCKS;
|
this.BISQ_BLOCKS = configs.BISQ_BLOCKS;
|
||||||
this.BISQ_MARKETS = configs.BISQ_MARKETS;
|
this.BISQ_MARKETS = configs.BISQ_MARKETS;
|
||||||
|
@ -50,17 +50,11 @@ class Logger {
|
|||||||
public debug: ((msg: string) => void);
|
public debug: ((msg: string) => void);
|
||||||
|
|
||||||
private name = 'mempool';
|
private name = 'mempool';
|
||||||
private fac: any;
|
|
||||||
private loghost: string;
|
|
||||||
private logport: number;
|
|
||||||
private client: dgram.Socket;
|
private client: dgram.Socket;
|
||||||
private network: string;
|
private network: string;
|
||||||
|
|
||||||
constructor(fac) {
|
constructor() {
|
||||||
let prio;
|
let prio;
|
||||||
this.fac = fac != null ? fac : Logger.facilities.local0;
|
|
||||||
this.loghost = '127.0.0.1';
|
|
||||||
this.logport = 514;
|
|
||||||
for (prio in Logger.priorities) {
|
for (prio in Logger.priorities) {
|
||||||
if (true) {
|
if (true) {
|
||||||
this.addprio(prio);
|
this.addprio(prio);
|
||||||
@ -97,10 +91,12 @@ class Logger {
|
|||||||
}
|
}
|
||||||
const network = this.network ? ' <' + this.network + '>' : '';
|
const network = this.network ? ' <' + this.network + '>' : '';
|
||||||
prionum = Logger.priorities[priority] || Logger.priorities.info;
|
prionum = Logger.priorities[priority] || Logger.priorities.info;
|
||||||
syslogmsg = `<${(this.fac * 8 + prionum)}> ${this.name}[${process.pid}]: ${priority.toUpperCase()}${network} ${msg}`;
|
|
||||||
consolemsg = `${this.ts()} [${process.pid}] ${priority.toUpperCase()}:${network} ${msg}`;
|
consolemsg = `${this.ts()} [${process.pid}] ${priority.toUpperCase()}:${network} ${msg}`;
|
||||||
|
|
||||||
this.syslog(syslogmsg);
|
if (config.SYSLOG.ENABLED && Logger.priorities[priority] <= Logger.priorities[config.SYSLOG.MIN_PRIORITY]) {
|
||||||
|
syslogmsg = `<${(Logger.facilities[config.SYSLOG.FACILITY] * 8 + prionum)}> ${this.name}[${process.pid}]: ${priority.toUpperCase()}${network} ${msg}`;
|
||||||
|
this.syslog(syslogmsg);
|
||||||
|
}
|
||||||
if (priority === 'warning') {
|
if (priority === 'warning') {
|
||||||
priority = 'warn';
|
priority = 'warn';
|
||||||
}
|
}
|
||||||
@ -116,7 +112,7 @@ class Logger {
|
|||||||
private syslog(msg) {
|
private syslog(msg) {
|
||||||
let msgbuf;
|
let msgbuf;
|
||||||
msgbuf = Buffer.from(msg);
|
msgbuf = Buffer.from(msg);
|
||||||
this.client.send(msgbuf, 0, msgbuf.length, this.logport, this.loghost, function(err, bytes) {
|
this.client.send(msgbuf, 0, msgbuf.length, config.SYSLOG.PORT, config.SYSLOG.HOST, function(err, bytes) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
@ -146,4 +142,4 @@ class Logger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new Logger(Logger.facilities.local7);
|
export default new Logger();
|
||||||
|
Loading…
Reference in New Issue
Block a user