Comments (10)
The current implementation does indeed seem to be doing too much. Would you like to send a pull request that changes that without breaking the classβs interface?
from logback-gelf.
Yes, I would send a pull request, but I need additional information.
What is the expected behavior of normalizeShortMessage()
?
- It should replace empty strings with a something like
"Empty message replaced by logback-gelf"
. - It should replace blank strings alike.
SeeGelfCodec
in graylog2-server
if (StringUtils.isBlank(shortMessageNode.asText()) && StringUtils.isBlank(messageNode.asText())) {
throw new IllegalArgumentException(prefix + "has empty mandatory \"short_message\" field.");
}
This could simply be implemented like this:
@Override
public String normalizeShortMessage(String shortMessage) {
if (shortMessage.isBlank()) {
addWarn("Log message was blank - replaced to prevent Graylog error");
return "Blank message replaced by logback-gelf";
}
return shortMessage;
}
-
Should it still trim leading and trailing whitespaces like the current implementation does? (Simply
return shortMessage.trim();
)
This can be helpful in some situations, but I don't think this is enforced by the GELF specification. Therefore we should not always enforce this. It could be an additional configurable feature (later). -
It should probably not replace any whitespace char with
' '
like the current implementation does? This is the nature of this issue. But I don't know the initial motivation for implementing it this way.
from logback-gelf.
- It should shorten the string to
maxShortMessageLength
.
from logback-gelf.
I'd say, it should:
- Strip leading whitespaces (using
String#stripLeading
) - Shorten the string to maxShortMessageLength, if longer than that
- Strip trailing whitespaces (using
String#stripTrailing
) - Replace blank strings with something like
"Empty message replaced by logback-gelf"
Stripping whitespaces could be optional (configurable).
from logback-gelf.
I just created the PR #101, which does not include the option to strip inner whitespaces.
But I wonder, if we should rethink the design:
- The
PatternLayout
formats theILoggingEvent
to a string.- This could include stripping or squashing of whitespaces.
- This could include trimming to a max length.
- Some of this is already possible with
PatternLayout
and an appropriate pattern (trimming like%.-250(%m)
). - Allowing custom implementations of
Layout
provides further flexibility.
- The
GelfEncoder
encodes that string and additional information to a json message, conforming to the GELF spec.- The already formatted string remains unchanged.
- Except the case of blank strings, that are replaced with
"Empty message replaced by logback-gelf"
.
from logback-gelf.
PR #101 is now mergeable.
What do you think of my previous comment?
from logback-gelf.
What do you think of my previous comment?
I think, you're absolutely right! I built the whole sanitising logic based on the misunderstanding of Graylog2/graylog2-server#4842
Formatting the message itself (including shortening, trimming, etc.) should be the sole responsibility of the pattern layout. Only the blank string handling has to be addresses β as you pointed out.
Could you create another PR for that?
from logback-gelf.
PR #102 is mergeable.
Will there be a patch or minor release soon?
from logback-gelf.
Will there be a patch or minor release soon?
A major release (due to breaking changes) is planned within the next two weeks.
from logback-gelf.
Just released 6.0.0 - thanks for your contribution!
from logback-gelf.
Related Issues (20)
- GelfHttpAppender does not set Uri HOT 1
- Markers are sent with Brackets. Like "[MARKER_NAME]" instead of "MARKER_NAME" without brackets HOT 1
- Add the possibility to filter included MDC keys HOT 3
- Add a configurable socket timeout HOT 5
- Macbook GelfUdpAppender garbled HOT 2
- GZIP Compression with GelfUdpAppender HOT 1
- Update logback-classic to 1.2.8 HOT 3
- Logback-classic release 1.2.9
- tcp configuration error HOT 3
- Add ability to log thread ID in addition to thread name HOT 2
- Enable adding multiple static fields via environment variable and/or logback.properties HOT 2
- Mutual TLS fails, HOT 1
- Add another method for adding static field to GelfEncoder HOT 2
- GelfMessage should fail on host = "", shortmessage="" HOT 4
- Add ability to log formatted time HOT 1
- Add use of structured arguments HOT 1
- JSON Encoding Performance HOT 1
- Several minor improvements HOT 1
- Faster MessageIdSupplier with less object allocation, error-prone HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logback-gelf.