Git Product home page Git Product logo

Comments (8)

garyrussell avatar garyrussell commented on May 19, 2024

Just Add a <PatternLayout/> element to your config...

<RabbitMQ name="rabbitmq"
		addresses="localhost:5672"
		host="localhost" port="5672" user="guest" password="guest" virtualHost="/"
		exchange="log4j2Test" exchangeType="fanout" declareExchange="true" durable="true" autoDelete="false"
		applicationId="testAppId" routingKeyPattern="%X{applicationId}.%c.%p"
		contentType="text/plain" contentEncoding="UTF-8" generateId="true" deliveryMode="NON_PERSISTENT"
		charset="UTF-8"
		clientConnectionProperties="foo:bar,baz:qux"
		async="false"
		senderPoolSize="3" maxSenderRetries="5">
	<PatternLayout pattern="%d %5p [%t] %m%n" />
</RabbitMQ>

from spring-amqp-samples.

garyrussell avatar garyrussell commented on May 19, 2024

Please don't use github issues to ask questions; use Stack Overflow instead [spring-amqp] tag.

Issues are for reporting bugs or asking for new features.

from spring-amqp-samples.

artembilan avatar artembilan commented on May 19, 2024

I think we can add that <PatternLayout> into the sample to avoid similar questions in the future

from spring-amqp-samples.

agustinbs avatar agustinbs commented on May 19, 2024

Thank you so much for your patience and such a fast answer! Indeed it works, I just tried and I have log messages including the threadname. Now, a suggestion, that you may or may not consider worth of tracking via an Issue.
By using an AMQP reader program it can be found that a number of different log message fields are mapped to the AMQP message header structure as in this sample:

#contentHeader<basic>(
content-type=text/plain, 
content-encoding=UTF-8, 
headers={
     level=TRACE, 
     location=es.companyname.logging.demo.WriteLogs.main()[23], 
     categoryName=es.tsystems.logging.demo.WriteLogs
}, 
delivery-mode=2, 
priority=0, 
correlation-id=null, 
reply-to=null, 
expiration=null, 
message-id=null, 
timestamp=Thu Aug 10 14:02:03 CEST 2017, 
type=null, 
user-id=null, 
app-id=logging-amqp-log4j, 
cluster-id=null
)

When indexing and storing the logs via Logstash and Elasticsearch, for example, there will be always the need of obtaining the threadname, so that each execution path can be isolated for browsing, f.e. with Kibana.

With the patternlayout, now I have log messages as follows:

"message":"2017-08-11 17:37:38,104  INFO [pool-1-1] END something to log in one thread\r\n"

If I want to obtain the threadname ( 'pool-1-1' in the example), I need to code in logstash a filter to get it out of the message text. Not difficult, but error prone and dependent on message layout. Would it make more sense to have it included in the 'headers' structure, together with 'level', 'location' and 'categoryName'?

The other thing that strikes me is to see that '\r\n' at the end of each text message, I am not including a carriage feed at the end of the log messages, so, why is it there?
Thanks again!

from spring-amqp-samples.

garyrussell avatar garyrussell commented on May 19, 2024

I opened AMQP-761.

from spring-amqp-samples.

garyrussell avatar garyrussell commented on May 19, 2024

%n adds the newline; remove it from your pattern.

from spring-amqp-samples.

agustinbs avatar agustinbs commented on May 19, 2024

Yes, that was it... Thanks!

from spring-amqp-samples.

garyrussell avatar garyrussell commented on May 19, 2024

By the way; capturing the location (calling class and line) header is quite expensive; you might want to consider adding includeLocation="false" to your Logger elements...

<Logger name="foo" level="info" includeLocation="false">
	<AppenderRef ref="rabbitmq" />
</Logger>

from spring-amqp-samples.

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.