Skip to content

Instantly share code, notes, and snippets.

@Istar-Eldritch
Created June 24, 2016 16:40
Show Gist options
  • Save Istar-Eldritch/d487e5480f8f93bab9261b45b143a95f to your computer and use it in GitHub Desktop.
Save Istar-Eldritch/d487e5480f8f93bab9261b45b143a95f to your computer and use it in GitHub Desktop.
Bunyan Logger Class for ElasticSearch Client
import * as Bunyan from "bunyan";
type LogFunction = (content: any) => void;
interface Log {
error: LogFunction;
warning: LogFunction;
info: LogFunction;
debug: LogFunction;
trace: (method: string,
requestUrl: Object|string,
requestBody: string | boolean,
responseBody: string | boolean,
responseStatus: number | boolean) => void;
close: () => void;
}
interface ElasticBunyanOptions {
bunyan: Bunyan.Logger;
}
export default class ElasticBunyan implements Log {
bunyan: Bunyan.Logger;
constructor(options: ElasticBunyanOptions) {
this.bunyan = options.bunyan;
}
error = (content) => {
this.bunyan.error(content);
};
warning = (content) => {
this.bunyan.warn(content);
};
info = (content) => {
this.bunyan.info(content);
};
debug = (content) => {
this.bunyan.debug(content);
};
trace = (method: string,
requestUrl: Object|string,
requestBody: string | boolean,
responseBody: string | boolean,
responseStatus: number | boolean) => {
this.bunyan.trace({
method: method,
requestUrl: requestUrl,
body: requestBody,
responseBody: responseBody,
responseStatus: responseStatus
});
};
close = () => {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment