-
Notifications
You must be signed in to change notification settings - Fork 981
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move winston-gelf code into the project to fix an upstream issue
- Loading branch information
Showing
4 changed files
with
68 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
opencti-platform/opencti-graphql/src/config/gelf-transport.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires, no-multi-assign, guard-for-in, no-restricted-syntax, no-param-reassign -- | ||
* This is a straight copy of https://github.com/fchristle/winston-gelf/blob/5420e52bc6a9830dc4a56494097c752fddcfcabc/index.js | ||
* with a single change, noted below. | ||
* We disable the eslint rules that would cause warnings in the original code. | ||
*/ | ||
|
||
const Transport = require('winston-transport'); | ||
const logger = require('gelf-pro'); | ||
|
||
const levels = { | ||
emerg: 'emergency', | ||
alert: 'alert', | ||
crit: 'critical', | ||
error: 'error', | ||
warn: 'warn', | ||
notice: 'notice', | ||
info: 'info', | ||
debug: 'debug', | ||
}; | ||
|
||
class GelfTransport extends Transport { | ||
constructor(opts) { | ||
super(opts); | ||
this.logger = Object.create(logger); | ||
this.logger.setConfig(opts.gelfPro); | ||
} | ||
|
||
log({ level, message, ...extra }, callback) { | ||
setImmediate(() => { | ||
this.emit('logged', { level, message, extra }); | ||
}); | ||
|
||
if (typeof extra === 'object') { | ||
for (const key in extra) { | ||
const value = extra[key]; | ||
if (value instanceof Error) { | ||
extra = value; | ||
} | ||
} | ||
} | ||
|
||
const graylogLevel = levels[level] || levels.info; | ||
// CHANGE: use "callback" as the callback of the logging function | ||
this.logger[graylogLevel](message, extra, () => callback()); | ||
} | ||
|
||
setConfig(opts) { | ||
this.logger.setConfig(opts.gelfPro); | ||
} | ||
} | ||
|
||
module.exports = exports = GelfTransport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters