-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split long messages #29
Comments
Do you really need to send unhandled exceptions to telegram ? Maybe you can configure the logger to not send them to telegram and configure another logger to take care of them ? Something similar to this: https://github.com/winstonjs/winston#exceptions |
@ivanmarban, thanks a lot for the quick response! Yes, that is the case. I need to send some debugging data also. I expect that message splitting is handled on the library side but not on the main application level. That would be awesome if the message splitting feature could be implemented in winston-telegram. |
Logging to the console or the file works as expected, by the way. The problem is when the long message is sent to the telegram. |
I will try to implement the functionality to automatically split messages longer than 4096 characters as soon as my free time let me. Thanks for your feedback ! |
BTW any help is welcome of course. At first sight my idea is to make a function that wraps around 'send' to add the split functionality. |
Splitting for chunks function could be something like this: function chunkString (str, len) {
const size = Math.ceil(str.length/len);
const arr = Array(size);
let offset = 0;
for (let i = 0; i < size; i++) {
arr[i] = str.substr(offset, len);
offset += len;
}
return arr;
} Source: https://stackoverflow.com/a/14349616 Seems that it is one of the fastest and the simplest solutions to split the string into chunks. |
@dec0dOS could you please give a try at the code on feature/split-long-messages branch and give some feedback ? |
@ivanmarban, it works as expected in all my use cases. Thanks a lot! |
@ivanmarban, is it going to be merged into the main branch? |
Released new feature on v2.5.0 |
Hello, thanks for the awesome project!
I have an issue with the long messages as all unhandled exceptions from the server are sent to telegram.
For example:
Logger.error is used for logging messages to telegram.
This line throws the following exception:
The message should be split after 4096 characters to fix unexpected logging exceptions.
For now, I'm using the following technique to cut the message:
The text was updated successfully, but these errors were encountered: