mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 09:23:52 -05:00
add option for custom papertrail hostname (#4912)
This commit is contained in:
3
app.ts
3
app.ts
@@ -94,6 +94,7 @@ const opts = nopt({
|
||||
ensureNoIdClash: [Boolean],
|
||||
logHost: [String],
|
||||
logPort: [Number],
|
||||
hostnameForLogging: [String],
|
||||
suppressConsoleLog: [Boolean],
|
||||
metricsPort: [Number],
|
||||
loki: [String],
|
||||
@@ -172,7 +173,7 @@ const defArgs = {
|
||||
};
|
||||
|
||||
if (opts.logHost && opts.logPort) {
|
||||
logToPapertrail(opts.logHost, opts.logPort, defArgs.env.join('.'));
|
||||
logToPapertrail(opts.logHost, opts.logPort, defArgs.env.join('.'), opts.hostnameForLogging);
|
||||
}
|
||||
|
||||
if (opts.loki) {
|
||||
|
||||
@@ -55,22 +55,35 @@ export function makeLogStream(level: string, logger_: winston.Logger = logger):
|
||||
});
|
||||
}
|
||||
|
||||
type MyPapertrailTransportOptions = TransportStreamOptions & {
|
||||
host: string;
|
||||
port: number;
|
||||
identifier: string;
|
||||
hostnameForLogging?: string;
|
||||
};
|
||||
|
||||
// Our own transport which uses Papertrail under the hood but better adapts it to work in winston 3.0
|
||||
class MyPapertrailTransport extends TransportStream {
|
||||
private readonly hostname: string;
|
||||
private readonly program: string;
|
||||
public readonly transport: Papertrail;
|
||||
|
||||
constructor(opts: TransportStreamOptions & {host: string; port: number; identifier: string}) {
|
||||
constructor(opts: MyPapertrailTransportOptions) {
|
||||
super(opts);
|
||||
|
||||
this.hostname = os.hostname();
|
||||
this.program = opts.identifier;
|
||||
|
||||
if (opts.hostnameForLogging) {
|
||||
this.hostname = opts.hostnameForLogging;
|
||||
} else {
|
||||
this.hostname = os.hostname();
|
||||
}
|
||||
|
||||
this.transport = new Papertrail({
|
||||
host: opts.host,
|
||||
port: opts.port,
|
||||
logFormat: (level, message) => message,
|
||||
hostname: this.hostname,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -102,12 +115,15 @@ export function logToLoki(url) {
|
||||
logger.info('Configured loki');
|
||||
}
|
||||
|
||||
export function logToPapertrail(host: string, port: number, identifier: string) {
|
||||
const transport = new MyPapertrailTransport({
|
||||
export function logToPapertrail(host: string, port: number, identifier: string, hostnameForLogging?: string) {
|
||||
const settings: MyPapertrailTransportOptions = {
|
||||
host: host,
|
||||
port: port,
|
||||
identifier: identifier,
|
||||
});
|
||||
hostnameForLogging,
|
||||
};
|
||||
|
||||
const transport = new MyPapertrailTransport(settings);
|
||||
transport.transport.on('error', err => {
|
||||
logger.error(err);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user