Pretty Logging

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Pretty Logging

Al Grant
How do I enable pretty output of the XML to the console? All the examples on
StackOverflow seem to use a XML configuration file, but everything I am
doing is in code.



--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Pretty Logging

cschneider
See CXF Message Logging docs at
http://cxf.apache.org/docs/message-logging.html
and
https://github.com/apache/cxf/blob/master/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java

You can simply instantiate the LoggingFeature class and set properties on
it:
logging = new LoggingFeature();
logging.setPrettyLogging(true);

Then you add it as a feature on the bus, endpoin or client:

https://github.com/cschneider/talk-logging/blob/master/sample-rest/src/main/java/net/lr/talk/logging/rest/ServiceStarter.java

Christian

2018-02-05 12:12 GMT+01:00 Al Grant <[hidden email]>:

> How do I enable pretty output of the XML to the console? All the examples
> on
> StackOverflow seem to use a XML configuration file, but everything I am
> doing is in code.
>
>
>
> --
> Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
>



--
--
Christian Schneider
http://www.liquid-reality.de

Computer Scientist
http://www.adobe.com
Reply | Threaded
Open this post in threaded view
|

Re: Pretty Logging

Al Grant
Thanks.

Do you actually mean to instantiate it:

        LoggingFeature logging = new LoggingFeature();
        logging.setPrettyLogging(true);

The github example is a Server - I want to do it in a client and print to
log4j and console?

So after the above two lines how do I write to console request and response?

Cheers

AG




--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Pretty Logging

cschneider
It is a bit more than the two lines as you also have to add the feature to
your client. What API do you use to create the client?

The LoggingFeature by default logs to slf4j. So the easiest way to get
output on the console is to use a logging backend like log4j and configure
it to log to the console. You can also selectively configure to only log
the requests and responses by limiting the settings to a logger name.

Another way is to implement your own LogEventSender and set it on the
LoggingFeature. This is pretty simple to do and gives you full access on
all logged data.

https://github.com/apache/cxf/blob/master/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jEventSender.java

Christian


2018-02-06 6:48 GMT+01:00 Al Grant <[hidden email]>:

> Thanks.
>
> Do you actually mean to instantiate it:
>
>         LoggingFeature logging = new LoggingFeature();
>         logging.setPrettyLogging(true);
>
> The github example is a Server - I want to do it in a client and print to
> log4j and console?
>
> So after the above two lines how do I write to console request and
> response?
>
> Cheers
>
> AG
>
>
>
>
> --
> Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
>



--
--
Christian Schneider
http://www.liquid-reality.de

Computer Scientist
http://www.adobe.com
Reply | Threaded
Open this post in threaded view
|

Re: Pretty Logging

Al Grant
Hi,

This is the client created here :

        org.apache.cxf.endpoint.Client client =
org.apache.cxf.frontend.ClientProxy.getClient(irsiService);
        org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();





--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Pretty Logging

Al Grant
In reply to this post by cschneider
I do actually get the message on the console, but its all run together, no
new lines or indentation.

Is that what the pretty part would do if i had it going?





--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Pretty Logging

Al Grant
In reply to this post by cschneider
This is what worked for me for the benefit of anyone else:

        // LOGGING
        LoggingOutInterceptor loi = new LoggingOutInterceptor();
        loi.setPrettyLogging(true);
        LoggingInInterceptor lii = new LoggingInInterceptor();
        lii.setPrettyLogging(true);

        org.apache.cxf.endpoint.Client client =
org.apache.cxf.frontend.ClientProxy.getClient(isalesService);
        org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();

        cxfEndpoint.getOutInterceptors().add(loi);
        cxfEndpoint.getInInterceptors().add(lii);



--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html