Skip to content

Commit

Permalink
Move winston-gelf code into the project to fix an upstream issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bnazare committed Jan 24, 2025
1 parent 151f2ea commit 3fd8920
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 23 deletions.
3 changes: 2 additions & 1 deletion opencti-platform/opencti-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"express-session": "1.18.1",
"fast-json-patch": "3.1.1",
"file-type": "19.6.0",
"gelf-pro": "1.4.0",
"github-api": "3.4.0",
"graphql": "16.9.0",
"graphql-constraint-directive": "5.4.3",
Expand Down Expand Up @@ -159,7 +160,7 @@
"validator": "13.12.0",
"winston": "3.17.0",
"winston-daily-rotate-file": "5.0.0",
"winston-gelf": "1.7.0",
"winston-transport": "4.9.0",
"ws": "8.18.0",
"xml2js": "0.6.2"
},
Expand Down
52 changes: 52 additions & 0 deletions opencti-platform/opencti-graphql/src/config/gelf-transport.js
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);
}

Check warning on line 26 in opencti-platform/opencti-graphql/src/config/gelf-transport.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/config/gelf-transport.js#L23-L26

Added lines #L23 - L26 were not covered by tests

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());
}

Check warning on line 45 in opencti-platform/opencti-graphql/src/config/gelf-transport.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/config/gelf-transport.js#L29-L45

Added lines #L29 - L45 were not covered by tests

setConfig(opts) {
this.logger.setConfig(opts.gelfPro);
}

Check warning on line 49 in opencti-platform/opencti-graphql/src/config/gelf-transport.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/config/gelf-transport.js#L48-L49

Added lines #L48 - L49 were not covered by tests
}

module.exports = exports = GelfTransport;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { format } from 'winston';
import GelfTransport from 'winston-gelf';
import GelfTransport from './gelf-transport';

/**
* Create a new log shipping transport.
Expand Down
34 changes: 13 additions & 21 deletions opencti-platform/opencti-graphql/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8649,12 +8649,12 @@ __metadata:
languageName: node
linkType: hard

"gelf-pro@npm:^1.2.2":
version: 1.3.11
resolution: "gelf-pro@npm:1.3.11"
"gelf-pro@npm:1.4.0":
version: 1.4.0
resolution: "gelf-pro@npm:1.4.0"
dependencies:
lodash: "npm:~4.17.21"
checksum: 10/a1b06e5238fdfe0f963fe79422e6018910c91ce9fb2bfb327a30a55c74c0bee1e03b0a2c243636c2e7e6e3cb670dd2baf5691bac79d77fe7abc293f0580c59bf
checksum: 10/65fa4a38f1d9c4f48fbbb4bc8cd11fe9333cd26dce387ca96e52ea91b5bfc0eaf5370ab49e7a2db1e7f262d74751a5e5e2c8d5d37fa03aa3b427b1db7b13bcde
languageName: node
linkType: hard

Expand Down Expand Up @@ -11478,6 +11478,7 @@ __metadata:
fast-glob: "npm:3.3.3"
fast-json-patch: "npm:3.1.1"
file-type: "npm:19.6.0"
gelf-pro: "npm:1.4.0"
github-api: "npm:3.4.0"
graphql: "npm:16.9.0"
graphql-constraint-directive: "npm:5.4.3"
Expand Down Expand Up @@ -11539,7 +11540,7 @@ __metadata:
vitest: "npm:2.0.5"
winston: "npm:3.17.0"
winston-daily-rotate-file: "npm:5.0.0"
winston-gelf: "npm:1.7.0"
winston-transport: "npm:4.9.0"
ws: "npm:8.18.0"
xml2js: "npm:0.6.2"
languageName: unknown
Expand Down Expand Up @@ -14538,12 +14539,14 @@ __metadata:
languageName: node
linkType: hard

"winston-gelf@npm:1.7.0":
version: 1.7.0
resolution: "winston-gelf@npm:1.7.0"
"winston-transport@npm:4.9.0, winston-transport@npm:^4.9.0":
version: 4.9.0
resolution: "winston-transport@npm:4.9.0"
dependencies:
gelf-pro: "npm:^1.2.2"
checksum: 10/a9242bc1455baecadb59e367f8432d5f8ac3613838789b953b032f9e147eafd393d83aa065f041a8c001c166706f0071c296f760e6853c75c6817c4c9c796352
logform: "npm:^2.7.0"
readable-stream: "npm:^3.6.2"
triple-beam: "npm:^1.3.0"
checksum: 10/5946918720baadd7447823929e94cf0935f92c4cff6d9451c6fcb009bd9d20a3b3df9ad606109e79d1e9f4d2ff678477bf09f81cfefce2025baaf27a617129bb
languageName: node
linkType: hard

Expand All @@ -14558,17 +14561,6 @@ __metadata:
languageName: node
linkType: hard

"winston-transport@npm:^4.9.0":
version: 4.9.0
resolution: "winston-transport@npm:4.9.0"
dependencies:
logform: "npm:^2.7.0"
readable-stream: "npm:^3.6.2"
triple-beam: "npm:^1.3.0"
checksum: 10/5946918720baadd7447823929e94cf0935f92c4cff6d9451c6fcb009bd9d20a3b3df9ad606109e79d1e9f4d2ff678477bf09f81cfefce2025baaf27a617129bb
languageName: node
linkType: hard

"winston@npm:3.17.0":
version: 3.17.0
resolution: "winston@npm:3.17.0"
Expand Down

0 comments on commit 3fd8920

Please sign in to comment.