winston-newrelic-logs-transport
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -9,26 +9,26 @@ "use strict"; | ||
const triple_beam_1 = require("triple-beam"); | ||
class Newrelic extends winston_transport_1.default { | ||
constructor(options = { licenseKey: '', apiUrl: '' }) { | ||
class WinstonNewrelicLogsTransport extends winston_transport_1.default { | ||
constructor(options) { | ||
var _a; | ||
super(); | ||
this.axiosClient = axios_1.default.create({ | ||
baseURL: options.apiUrl, | ||
timeout: 5000, | ||
headers: { | ||
'X-License-Key': options.licenseKey, | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
this.axiosClient = axios_1.default.create(Object.assign(Object.assign({ timeout: 5000 }, options.axiosOptions), { baseURL: options.apiUrl, headers: Object.assign(Object.assign({}, (_a = options.axiosOptions) === null || _a === void 0 ? void 0 : _a.headers), { "X-License-Key": options.licenseKey, "Content-Type": "application/json" }) })); | ||
} | ||
log(info, callback) { | ||
setImmediate(() => this.emit('logged', info)); | ||
this.axiosClient.post('/log/v1', { | ||
this.axiosClient | ||
.post("/log/v1", { | ||
timestamp: Date.now(), | ||
message: info[triple_beam_1.MESSAGE], | ||
logtype: info[triple_beam_1.LEVEL] | ||
logtype: info[triple_beam_1.LEVEL], | ||
}) | ||
.then(() => { | ||
this.emit("logged", info); | ||
callback(null); | ||
}) | ||
.catch((err) => { | ||
this.emit("error", err); | ||
callback(err); | ||
}); | ||
callback(); | ||
} | ||
} | ||
exports.default = Newrelic; | ||
; | ||
exports.default = WinstonNewrelicLogsTransport; | ||
//# sourceMappingURL=index.js.map |
76
index.ts
@@ -1,37 +0,57 @@ | ||
import axios, { AxiosInstance } from 'axios'; | ||
import TransportStream from 'winston-transport'; | ||
import { LEVEL, MESSAGE } from 'triple-beam'; | ||
import axios, { AxiosInstance, AxiosRequestConfig } from "axios"; | ||
import TransportStream from "winston-transport"; | ||
import { LEVEL, MESSAGE } from "triple-beam"; | ||
export interface WinstonNewrelicLogsTransportOptions { | ||
licenseKey: string; | ||
apiUrl: string; | ||
axiosOptions?: AxiosRequestConfig; | ||
} | ||
/** | ||
* Transport for reporting errors to newrelic. | ||
* @type {Newrelic} | ||
* | ||
* @type {WinstonNewrelicLogsTransport} | ||
* @extends {TransportStream} | ||
*/ | ||
export default class Newrelic extends TransportStream { | ||
axiosClient: AxiosInstance; | ||
export default class WinstonNewrelicLogsTransport extends TransportStream { | ||
axiosClient: AxiosInstance; | ||
constructor(options = { licenseKey: '', apiUrl: '' }) { | ||
super(); | ||
constructor(options: WinstonNewrelicLogsTransportOptions) { | ||
super(); | ||
this.axiosClient = axios.create({ | ||
baseURL: options.apiUrl, | ||
timeout: 5000, | ||
headers: { | ||
'X-License-Key': options.licenseKey, | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
} | ||
this.axiosClient = axios.create({ | ||
timeout: 5000, | ||
...options.axiosOptions, | ||
baseURL: options.apiUrl, | ||
headers: { | ||
...options.axiosOptions?.headers, | ||
"X-License-Key": options.licenseKey, | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
} | ||
log(info: { [x in symbol]: string; }, callback: () => void) { | ||
setImmediate(() => this.emit('logged', info)); | ||
log(info: { [x in symbol]: string }, callback: (error?: Error) => void) { | ||
// The implementation of log callbacks isn't documented and the exported type | ||
// definitions appear to be wrong too. This implementation has been compied | ||
// https://github.com/winstonjs/winston-mongodb/blob/master/lib/winston-mongodb.js#L229-L235 | ||
// However I don't know what the second argument for callback is supposed to | ||
// indicate. | ||
this.axiosClient.post('/log/v1', { | ||
timestamp: Date.now(), | ||
message: info[MESSAGE], | ||
logtype: info[LEVEL] | ||
}); | ||
callback(); | ||
} | ||
}; | ||
this.axiosClient | ||
.post("/log/v1", { | ||
timestamp: Date.now(), | ||
message: info[MESSAGE], | ||
logtype: info[LEVEL], | ||
}) | ||
.then(() => { | ||
this.emit("logged", info); | ||
callback(null); | ||
}) | ||
.catch((err) => { | ||
this.emit("error", err); | ||
callback(err); | ||
}); | ||
} | ||
} |
{ | ||
"name": "winston-newrelic-logs-transport", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "NewRelic Logs API Transport for Winston", | ||
@@ -14,14 +14,15 @@ "main": "dist/index.js", | ||
"prepublish": "tsc", | ||
"start": "tsc && node dist/app.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "vitest" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"logform": "^2.5.1", | ||
"winston-transport": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/triple-beam": "^1.3.2", | ||
"axios": "^0.21.1", | ||
"newrelic": "^7.1.0", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.1.3", | ||
"winston": "^3.0.0", | ||
"winston-transport": "^4.2.0" | ||
"typescript": "^4.9.5", | ||
"vitest": "^0.29.2" | ||
} | ||
} |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
8482
3
11
171
1
4
+ Addedlogform@^2.5.1
+ Addedms@2.1.3(transitive)
- Removed@types/triple-beam@^1.3.2
- Removednewrelic@^7.1.0
- Removedtslint@^6.1.3
- Removedtypescript@^4.1.3
- Removedwinston@^3.0.0
- Removed@babel/code-frame@7.24.2(transitive)
- Removed@babel/helper-validator-identifier@7.24.5(transitive)
- Removed@babel/highlight@7.24.5(transitive)
- Removed@dabh/diagnostics@2.0.3(transitive)
- Removed@grpc/grpc-js@1.10.8(transitive)
- Removed@grpc/proto-loader@0.5.60.7.13(transitive)
- Removed@js-sdsl/ordered-map@4.4.2(transitive)
- Removed@newrelic/aws-sdk@3.1.0(transitive)
- Removed@newrelic/koa@5.0.0(transitive)
- Removed@newrelic/native-metrics@6.0.2(transitive)
- Removed@newrelic/superagent@4.0.0(transitive)
- Removed@protobufjs/aspromise@1.1.2(transitive)
- Removed@protobufjs/base64@1.1.2(transitive)
- Removed@protobufjs/codegen@2.0.4(transitive)
- Removed@protobufjs/eventemitter@1.1.0(transitive)
- Removed@protobufjs/fetch@1.1.0(transitive)
- Removed@protobufjs/float@1.0.2(transitive)
- Removed@protobufjs/inquire@1.1.0(transitive)
- Removed@protobufjs/path@1.1.2(transitive)
- Removed@protobufjs/pool@1.1.0(transitive)
- Removed@protobufjs/utf8@1.1.0(transitive)
- Removed@types/long@4.0.2(transitive)
- Removed@types/node@20.12.12(transitive)
- Removed@tyriar/fibonacci-heap@2.0.9(transitive)
- Removedagent-base@5.1.1(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@3.2.14.3.0(transitive)
- Removedargparse@1.0.10(transitive)
- Removedasync@3.2.5(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedbuiltin-modules@1.1.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcliui@8.0.1(transitive)
- Removedcolor@3.2.1(transitive)
- Removedcolor-convert@1.9.32.0.1(transitive)
- Removedcolor-name@1.1.31.1.4(transitive)
- Removedcolor-string@1.9.1(transitive)
- Removedcolorspace@1.1.4(transitive)
- Removedcommander@2.20.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconcat-stream@2.0.0(transitive)
- Removeddebug@4.3.4(transitive)
- Removeddiff@4.0.2(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedenabled@2.0.0(transitive)
- Removedescalade@3.1.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedesprima@4.0.1(transitive)
- Removedfn.name@1.1.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedglob@7.2.3(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttps-proxy-agent@4.0.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedis-arrayish@0.3.2(transitive)
- Removedis-core-module@2.13.1(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-stream@2.0.1(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedkuler@2.0.0(transitive)
- Removedlodash.camelcase@4.3.0(transitive)
- Removedlong@4.0.05.2.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedms@2.1.2(transitive)
- Removednan@2.19.0(transitive)
- Removednewrelic@7.5.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedone-time@1.0.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpicocolors@1.0.1(transitive)
- Removedprotobufjs@6.11.47.3.0(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsimple-swizzle@0.2.2(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstack-trace@0.0.10(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtext-hex@1.0.0(transitive)
- Removedtslib@1.14.1(transitive)
- Removedtslint@6.1.3(transitive)
- Removedtsutils@2.29.0(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedtypescript@4.9.5(transitive)
- Removedundici-types@5.26.5(transitive)
- Removedwinston@3.13.0(transitive)
- Removedwrap-ansi@7.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedy18n@5.0.8(transitive)
- Removedyargs@17.7.2(transitive)
- Removedyargs-parser@21.1.1(transitive)