kutuluk / loglevel-plugin-remote

A loglevel plugin for sending browser logs to a server
MIT License
102 stars 36 forks source link

Custom request payload format #40

Open davidslaby opened 3 years ago

davidslaby commented 3 years ago

Allows devs to customize payload in JSON format + README updated

davidslaby commented 3 years ago

Tested by me - fully working solution

davidslaby commented 3 years ago

@kutuluk @Looooopy @roblangridge could you check please? :)

Thanks in advance!

Iorweth333 commented 3 years ago

Perhaps an option to turn off interpolation and export of the interpolate function would do the trick? Personally, all I wanted was to receive my args in the format funtion unchanged so that I could add some additional information in each log in JSON format, like:

const customJSON = (log, args) => ({ msg: log.message, additionalInformation: args, level: log.level.label, }); so that in the end I could receive something like this: { "logs":[ { "msg":"Error during parsing", "additionalInformation":{ "message":"InvalidTokenError: Invalid token specified: JSON.parse: unexpected character at line 1 column 1 of the JSON data", "parsed":"XD" }, "level":"error" } ] }

but that interpolation unfortunately mashed it all into a string...

davidslaby commented 3 years ago

Perhaps an option to turn off interpolation and export of the interpolate function would do the trick? Personally, all I wanted was to receive my args in the format funtion unchanged so that I could add some additional information in each log in JSON format, like:

const customJSON = (log, args) => ({ msg: log.message, additionalInformation: args, level: log.level.label, }); so that in the end I could receive something like this: { "logs":[ { "msg":"Error during parsing", "additionalInformation":{ "message":"InvalidTokenError: Invalid token specified: JSON.parse: unexpected character at line 1 column 1 of the JSON data", "parsed":"XD" }, "level":"error" } ] }

but that interpolation unfortunately mashed it all into a string...

Perhaps I don't understand your reply. My PR was about completely different thing, I need to send log in different format to remote not to add some information.

Iorweth333 commented 3 years ago

oh, that was the point, pardon me then

davidslaby commented 3 years ago

oh, that was the point, pardon me then

It's okay, descriptions is too short. I'm sending that to logz.io and the format is determined by object. So there was not any option to send logs like objects not in array by default.