mperdeck / jsnlog.js

Tiny JavaScript logging library, simple and well documented. Lots of options to filter logging data.
js.jsnlog.com
Other
130 stars 43 forks source link

Support for a pre-request callback function #14

Closed mruoss closed 9 years ago

mruoss commented 9 years ago

Currently there is no possibility to modify the XHR before it is sent to the server. I would really like add custom headers to the request. Such an extension, probably to the setOptions-method would be great. @mperdeck do you agree?

mperdeck commented 9 years ago

I agree that would be useful. Am happy to accept your pull request, except for one problem.

Your modification puts the beforeSend property effectively on the entire library http://nodejs.jsnlog.com/Documentation/JSNLogJs/JL/SetOptions

However, it is very AjaxAppender specific. So it would be better to make it a property of the AjaxAppender object. That would also make it possible to have different ajax appenders with different beforeSend functions. http://nodejs.jsnlog.com/Documentation/JSNLogJs/AjaxAppender/SetOptions

Looking at the TypeScript code, the AjaxAppender object starts at the line export class AjaxAppender extends Appender implements JSNLogAjaxAppender

Close by is the setOptions function for AjaxAppender.

If you make the beforeSend property specific to the AjaxAppender object, rather than the entire JL object, and send me a new pull request, I'd be happy to accept that pull request. I'll also update the online documentation at jsnlog.com.

mruoss commented 9 years ago

Yes I agree the callback should indeed be defined on the appender. However, I left a defaultBeforeSend callback on the library as we also have a defaultAjaxUrl. Better like that?

mperdeck commented 9 years ago

Thanks for your pull request. I've released it as part of the latest release 2.8.0 which is now on NuGet. http://jsnlog.com/Documentation/JSNLogJs/AjaxAppender/SetOptions