Code Monkey home page Code Monkey logo

Comments (4)

osiegmar avatar osiegmar commented on August 17, 2024

Indeed, multiple markers are not yet supported. Could you give an example of logstash handles multiple markers / properties?

from logback-gelf.

danjo133 avatar danjo133 commented on August 17, 2024

When you add multiple markers with and, they get added as a reference, from
https://github.com/logstash/logstash-logback-encoder/blob/master/src/main/java/net/logstash/logback/marker/LogstashMarker.java

    /**
     * Adds the given marker as a reference, and returns this marker.
     * <p>
     * This can be used to chain markers together fluently on a log line. For example:
     * 
     * <pre>
     * {@code
     * import static net.logstash.logback.marker.Markers.*
     *     
     * logger.info(append("name1", "value1).and(append("name2", "value2")), "log message");
     * }
     * </pre>
     * 
     * @param <T> subtype of LogstashMarker
     * @param reference The marker to add
     * @return A marker with this marker and the given marker
     */
    @SuppressWarnings("unchecked")
    public <T extends LogstashMarker> T and(Marker reference) {
        add(reference);
        return (T) this;
    }

Then they can be added as a string as they are in that file

public String toString() {
     String self = toStringSelf();
     if (!hasReferences()) {
         return self;
     }

     StringBuilder sb = new StringBuilder(self);
     boolean appendSeparator = !self.isEmpty();
     for (Marker marker : this) {
         if (appendSeparator) {
             sb.append(", ");
         }
         String referenceToString = marker.toString();
         sb.append(referenceToString);
         appendSeparator = !referenceToString.isEmpty();
     }

     return sb.toString();
 }

or as json properties as in:

https://github.com/logstash/logstash-logback-encoder/blob/master/src/main/java/net/logstash/logback/marker/MapEntriesAppendingMarker.java

    @Override
    public void writeTo(JsonGenerator generator) throws IOException {
        if (map != null) {
            for (Map.Entry<?, ?> entry : map.entrySet()) {
                generator.writeFieldName(String.valueOf(entry.getKey()));
                generator.writeObject(entry.getValue());
            }
        }
    }

Which is then added the same way as mdc properties.

from logback-gelf.

osiegmar avatar osiegmar commented on August 17, 2024

I've added support for multiple markers in the bugfix/multiple-markers branch. Could you please check and confirm, that this also fixes your issue? I'm not sure where your LS_APPEND_OBJECT comes from.

from logback-gelf.

osiegmar avatar osiegmar commented on August 17, 2024

Fix released in 2.2.0.

from logback-gelf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.