Created
June 24, 2016 16:40
-
-
Save Istar-Eldritch/d487e5480f8f93bab9261b45b143a95f to your computer and use it in GitHub Desktop.
Bunyan Logger Class for ElasticSearch Client
This file contains hidden or 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
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