How can i append the username (principal) to each log line in Wildfly? - wildfly

I am working with Wildfly 10 and I am using its logging subsystem.
Now, I need to append the LoginName of the currently logged in User (principal) from the session to every log message that is processed by the JBoss Logging Subsystem.
Is there a generic way to do this, rather than appending the UserName to every Log Message in my Application?
For example i could do:
HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
UserModel user = (UserModel)request.getSession().getAttribute("user");
String username = user.getName();
But how can i get the Logging Subsystem to do this for every Log Message?

As James R. Perkins suggested, this can be done be using MDC (Mapped Diagnostic Context).
An example of how this works can be found here:
https://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/

I encountered the same situation as yours and found that there is no Wildfly in built support for the same.
Hence the two options that you can have are-
Append username to the logs manually as what you mentioned already in your question. Personally I prefer this to keep the logging minimum and relevant.
Use MDC and along with that implement 'filter' attribute of logging in Wildfly, so that you can keep only relevant log messages in your log file.

Related

How can we remove a specific message from jboss mq using jboss cli

I want to remove messages from jboss mq using certain filter , as I have googled the only filter available seems to be message-id
I am looking to use other properties of message, ex. JMSTimestamp
I am looking for something like
/subsystem=messaging-activemq/server=default/jms-queue="queuename"/:remove-message(timestamp>somevalue)
You should use the remove-messages operation that takes a filter as parameter.
Just for the information
This is the syntax I used
/subsystem=messaging-activemq/server=default/jms-queue="queuename"/: remove-messages(filter=JMSTimestamp > somevalue)

How to fix the missing BLINDTRANSFER and ATTENDEDTRANSFER log entries in the queue_log file?

I write a wallboard for asterisk queue system. The document says that when a call is transferred away by an agent an ATTENDEDTRANSFER (or BLINDTRANSFER) event log should be added to the queue_log file automatically. Unfortunately there is no line for any transferred calls in the log file (queue_log in my case). Is there any setting to be changed to let the system to log them properly ?
When I check the CEL files, I see the transfer logs. So the system is logging correctly for CEL but not for queue_log.
I tried to transfer the call to another agent, to an IVR and to another user who is not an agent for any queue. The result is the same, no log for the transfer process.
Any suggestions ?
I use the following:
Asterisk Version: 13.22.0
Freepbx 14.0.5.25
All trunks and clients are connected via SIP
If your phone do transfer via internal features - no log entries.
You have parse AMI events for needed info.
Write your own queue wallboard is VERY hard task. Queue module have really alot of issues.
Can recommend read some already written modules like https://www.asternic.net or queuemetric

Play 2.6 using Logging Markers to carry request uuid similar to Java MDC

I'm trying to use Logging Markers to carry contextual information during the whole cycle of a request. Basically, I want to assign a uuid to a request and after that, all logging related to that HTTP request, should print that request uuid.
https://www.playframework.com/documentation/2.6.x/ScalaLogging#using-markers-and-marker-contexts
I see the example with logstash, but I don't use logstash.
I know it can be done with the MDC. Can/How can it be done with Logging Markers ?
You don't say what your logging configuration looks like. The examples from your link use the marker to annotate each log entry. If you go to the next link, SettingsLogger, you will see how to configure logback to print out your logs to a file. You will need to modify the layout encoder to add "%marker" to the pattern layout. For instance,
"%-5level (%marker)[%thread]: %message%n"
will print out your log item with the UUID just before the thread name.

Camel password being partially logged after sanitization

This question is a follow on from :
Camel http4 and url-encoded passwords being interpreted as separate arguments
and is somewhat related to this update put in as part of Camel 2.14.x and 2.15.x for sanitizing password information...
We're using Camel 2.14.4 with http4 component to communicate with a webservice, and using the RAW syntax. However, if the password within RAW contains an ampersand, the santizeUri method only masks some of the password text.
E.g. Say my password is me##123, and is injected into the URI so that it becomes a part of the overall URI as follows:
...password=RAW(me##123)..., when the sanitizeURI method is called, it only sanitizes up to the ampersand, and sees the 123 as a different key, so you end up with ******&123 being logged at WARN level in the logs from this code.
Is there any way of avoiding this ?
Yeah we should remove that WARN logging as its not in use anymore. I have logged a ticket about this: https://issues.apache.org/jira/browse/CAMEL-10395
In the older Camel 2.14.4 version you can only configure your logging library to use ERROR level or OFF for the logger name that logs that WARN message.

Not able to get output from camel routing

I have defined a camel context with a camel route and I am having below code.
from("jetty:http://localhost:9090/camelcxfdemo/rest/cxf/camelRouter?matchOnUriPrefix=true").
to("jetty:http://localhost:9090/camelcxfdemo/rest/cxf/getPersonData?bridgeEndpoint=true&throwExceptionOnFailure=false")
.to("jetty:http://localhost:9090/camelcxfdemo/rest/cxf/processPersonData?bridgeEndpoint=true&throwExceptionOnFailure=false")
.to("log:output");
All the three urls shown above are Rest services which takes some post xml and return xml response.
I want my camel router to start working when /camelRouter is called and its output should go to /getPersonData url and the output of /getPersonData go to /processPersonData. And to user I should finally display the output of /processPersonData.
So each url is dependent on it's previous urls output.
But the problem is when I invoke /camelRouter url, I always get /camelRouter response, not the final output. The output is not routing from one service to other.
So is there is any probelm in my code? Hoping for some help.
Thanks
It appears to me that the Jetty component can be used as either a producer or consumer but not both as you appear to be attempting to use it.