mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[splunk-bunyan-logger] Adding new type definition (#27041)
This commit is contained in:
parent
6c7e7b5a33
commit
6361591c22
28
types/splunk-bunyan-logger/index.d.ts
vendored
Normal file
28
types/splunk-bunyan-logger/index.d.ts
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// Type definitions for splunk-bunyan-logger 0.9
|
||||
// Project: http://dev.splunk.com
|
||||
// Definitions by: Alex Brick <https://github.com/bricka>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Stream as BunyanStream } from 'bunyan';
|
||||
import {
|
||||
Config,
|
||||
EventFormatter,
|
||||
Logger as SplunkLogger,
|
||||
SendContext
|
||||
} from 'splunk-logging';
|
||||
|
||||
export interface SplunkStream extends NodeJS.WritableStream {
|
||||
logger: SplunkLogger;
|
||||
}
|
||||
|
||||
export interface SplunkBunyanStream extends BunyanStream {
|
||||
flush(callback?: (error: Error, req: any, res: any) => void): void;
|
||||
on(event: string, callback: (err: Error, context: SendContext) => void): void;
|
||||
setEventFormatter(eventFormatter: EventFormatter): void;
|
||||
stream: SplunkStream;
|
||||
}
|
||||
|
||||
export function createStream(config: Config): SplunkBunyanStream;
|
||||
62
types/splunk-bunyan-logger/splunk-bunyan-logger-tests.ts
Normal file
62
types/splunk-bunyan-logger/splunk-bunyan-logger-tests.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import { createStream } from 'splunk-bunyan-logger';
|
||||
import { Config } from 'splunk-logging';
|
||||
import { createLogger } from 'bunyan';
|
||||
|
||||
const config = {
|
||||
token: "your-token-here",
|
||||
url: "https://splunk.local:8088"
|
||||
};
|
||||
|
||||
const splunkStream = createStream(config);
|
||||
// Enable SSL certificate validation
|
||||
splunkStream.stream.logger.requestOptions.strictSSL = true;
|
||||
|
||||
splunkStream.on("error", (err, context) => {
|
||||
// Handle errors here
|
||||
console.log("Error", err, "Context", context);
|
||||
});
|
||||
|
||||
splunkStream.flush((err, resp, body) => {
|
||||
// If successful, body will be { text: 'Success', code: 0 }
|
||||
console.log("Response from Splunk", body);
|
||||
});
|
||||
|
||||
splunkStream.setEventFormatter((message, severity) => {
|
||||
let event = `[${severity}]`;
|
||||
|
||||
if (typeof message === "object") {
|
||||
for (const key in message) {
|
||||
event += `${key}=${message[key]} `;
|
||||
}
|
||||
} else {
|
||||
event += "message=" + message;
|
||||
}
|
||||
|
||||
return event;
|
||||
});
|
||||
|
||||
// Note: splunkStream must be set to an element in the streams array
|
||||
const Logger = createLogger({
|
||||
name: "my logger",
|
||||
streams: [
|
||||
splunkStream
|
||||
]
|
||||
});
|
||||
|
||||
// Fully-specified config
|
||||
|
||||
const fullConfig: Config = {
|
||||
token: 'token',
|
||||
name: 'loggerName',
|
||||
host: 'splunkHost',
|
||||
maxRetries: 2,
|
||||
path: 'splunkPath',
|
||||
protocol: 'https',
|
||||
port: 234,
|
||||
level: 'info',
|
||||
batchInterval: 200,
|
||||
maxBatchSize: 300,
|
||||
maxBatchCount: 400,
|
||||
};
|
||||
|
||||
createStream(fullConfig);
|
||||
23
types/splunk-bunyan-logger/tsconfig.json
Normal file
23
types/splunk-bunyan-logger/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictFunctionTypes": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"splunk-bunyan-logger-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/splunk-bunyan-logger/tslint.json
Normal file
1
types/splunk-bunyan-logger/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
3
types/splunk-logging/index.d.ts
vendored
3
types/splunk-logging/index.d.ts
vendored
@ -35,10 +35,11 @@ export interface SendContext {
|
||||
}
|
||||
|
||||
export type Callback = (error: Error | undefined, req: any, res: any) => void;
|
||||
export type EventFormatter = (message: any, severity: string) => any;
|
||||
|
||||
export class Logger {
|
||||
error: (error: Error, context: SendContext) => void;
|
||||
eventFormatter: (message: any, severity: string) => any;
|
||||
eventFormatter: EventFormatter;
|
||||
requestOptions: RequestOptions;
|
||||
readonly serializedEventQueue: any[];
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user