Skip to content

Commit

Permalink
fix(gelf-subject): Set default subject limit in gelf logs ZMS-177 (#32)
Browse files Browse the repository at this point in the history
* add subject line limit to gelf in case of errors on gelf side

* add comment
  • Loading branch information
NickOvt authored Oct 14, 2024
1 parent 1f4eeb4 commit 36cc6af
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module.exports.init = function (app, done) {
const gridfsdb = app.db.gridfs;

const component = ((app.config.gelf && app.config.gelf.component) || 'mta').toUpperCase();

const maxSubjectLineLogLengthBytes = app.config.gelf.subjectLength || 32766 - 1; // 32766 is max gelf default, do -1 for good measure

const hostname = app.config.hostname || os.hostname();
const gelf =
app.config.gelf && app.config.gelf.enabled
Expand Down Expand Up @@ -1077,7 +1080,10 @@ module.exports.init = function (app, done) {
message._spam_score = Number(entry.score) || '';
message._interface = entry.interface;
message._proto = entry.transtype;
message._subject = entry.subject;
message._subject =
Buffer.byteLength(entry.subject, 'utf8') > maxSubjectLineLogLengthBytes
? entry.subject.substring(0, maxSubjectLineLogLengthBytes / 4) // divide by 4 to account for max utf-8 char size
: entry.subject;

message._authenticated_sender = username;
}
Expand Down

0 comments on commit 36cc6af

Please sign in to comment.