TRAINING – EXERCISE LOGGING © 2014 Talend – All rights reserved 1/15 Contents 1 Prerequisits .....................................................................................3 2 Logging server installation ...................................................................4 3 4 5 6 2.1 Objective ..................................................................................................... 4 2.2 Overview ...................................................................................................... 4 2.3 Expected Outcome .......................................................................................... 5 2.4 Conclusion .................................................................................................... 5 Logging Agent Installation ....................................................................6 3.1 Objective ..................................................................................................... 6 3.2 Overview ...................................................................................................... 6 3.3 Detailed Instructions ........................................................................................ 6 3.4 Expected Outcome .......................................................................................... 7 3.5 Conclusion .................................................................................................... 7 Add logging to greeter demo .................................................................8 4.1 Objective ..................................................................................................... 8 4.2 Overview ...................................................................................................... 8 4.3 Detailed Instructions ........................................................................................ 8 4.4 Expected Outcome ......................................................................................... 12 Bonus Tasks – Retrieve Log Events over REST ............................................ 13 5.1 Objectives ................................................................................................... 13 5.2 Overview ..................................................................................................... 13 5.3 Conclusion ................................................................................................... 13 References .................................................................................... 14 © 2014 Talend – All rights reserved 2/15 1 PREREQUISITS Java Development Kit at least version 1.7 Apache Maven at least version 3.0.4 Eclipse IDE at least version 4.3 Two running Talend ESBs o Infra running on port 8040 o App running on port 8041 Infra container will be used as server and app container as client. The server hosts all infrastructure services. The client hosts a business application which is using the infrastructure. In the training VM they are located at: The server relevant parts will be installed in ~/Training/container-infra/ The client relevant parts will be installed in ~/Training/container-app/ © 2014 Talend – All rights reserved 3/15 2 LOGGING SERVER INSTALLATION 2.1 OBJECTIVE 1. Set up server side of the Talend Logging Framework. 2.2 OVERVIEW In this part of the exercise you will install and configure the Talend Logging and Auditing Framework in the given infrastructure container. Steps: 1. Install Features and Bundles 2. Configure Logging server persistence 3. Configure REST Logging ServiceDetailed Instructions These instructions are based on the ESB Infrastructure Services Guide – Chapter Logging Service and the ESB Installation Guide – Chapter Logging Service. Please refer to this documentation for more details. 2.2.1 INSTALL FEATURES AND BUNDLES 1. Start infra container using ~/Training/container-infra/bin/trun. 2. Install and start the Talend Logging Framework. Install Derby features:install tesb-datasource-derby features:install tesb-derby-starter Logging (Server parts like Rest collector + lookup service) features:install tesb-el-server features:install tesb-el-rest-service 3. Verify bundles were installed successfully. Verify list © 2014 Talend – All rights reserved 4/15 2.2.2 CONFIGURE REST LOGGING SERVICE 1. Adjust configuration file. org.talend.eventlogging.service.cfg config:edit org.talend.eventlogging.service config:propset eventlogging.authentication "BASIC" config:propset eventlogging.retrieval.api.enabled "true" config:update 2.3 EXPECTED OUTCOME Some of the installation steps require installing the binaries first and then do the configuring. To be sure all configuration changes are successfully applied please follow the following steps: 1. Shutdown the container with STRG+D. 2. Start the container with ~/Training/container-infra/bin/trun. 3. Validate that the rest client is available by using firefox. URL http://localhost:8040/services/eventlogging Credentials tadmin//tadmin 2.4 CONCLUSION In this exercise you installed the server relevant parts of Talend ESB logging. You installed and configured the following components: Logging Server REST (Collector) Service © 2014 Talend – All rights reserved 5/15 3 LOGGING AGENT INSTALLATION 3.1 OBJECTIVE 1. Set up client side of the Talend Logging Framework. 3.2 OVERVIEW In this part of the exercise you will install and configure the Talend Logging Framework in the given application container. Steps 1. Install Features 2. Configure Logging Agent 3. Configure REST Sender 3.3 DETAILED INSTRUCTIONS 3.3.1 INSTALL FEATURES 1. Start app container using ~/Training/container-app/bin/trun. 2. Install and start the Talend Logging Framework. Logging Client parts features:install features:install features:install features:install tesb-el-sender-rest tesb-el-agent tesb-el-listener-log tesb-el-listener-osgi 3.3.2 CONFIGURE LOGGING AGENT 1. Adjust configuration file. 3.3.3 org.talend.eventlogging.agent.cfg config:edit org.talend.eventlogging.agent config:propset agentid "app-container-agent" config:propset event.subject.map.attribute "principal.username" config:update CONFIGURE REST SENDER 1. Adjust configuration file. org.talend.eventlogging.sender.rest.cfg config:edit org.talend.eventlogging.sender.rest config:propset sender.destination.service.authentication "BASIC" config:propset sender.aggregation.sendtimeout "3" config:update Note: We switched on basic authentication and changed the aggregation parameter for timeout. The new aggregation settings mean that a log event will be sent to the logging server latest with a maximum delay of 3 seconds. © 2014 Talend – All rights reserved 6/15 3.4 EXPECTED OUTCOME The logging agent should now be installed and configured on the app runtime. Some of the installation steps require installing the binaries first and then do the configuring. To be sure all configuration changes are successfully applied please follow the following steps: 1. Restart Event-Logging-Agent and Event-Logging-Sender-REST. Event Logging Agent restart event-logging-agent Event Logging Sender REST restart event-logging-sender-rest 2. Start the container using ~/Training/container-infra/bin/trun. 3. Validate that log events have been received at the logging server by using Firefox. URL http://localhost:8040/services/eventlogging/events Credentials tadmin//tadmin Note: You should see a similar outcome as you can see on this screenshot. The list should contain an outline of several logging and OSGi events. 3.5 CONCLUSION In this exercise you have installed the client side parts of the logging system and attached the logging of the app container to the infra container. In the final step you used the REST interface of the logging server to validate that log messages are created, transferred and stored on the log server. © 2014 Talend – All rights reserved 7/15 4 ADD LOGGING TO GREETER DEMO 4.1 OBJECTIVE 1. Use Talend Logging and Auditing Framework within an OSGi Bundle 4.2 OVERVIEW In this part of the exercise you will create some logging statements within an existing OSGi ‘Greeter’ service to deploy the corresponding OSGi bundles afterwards into the prepared Talend ESB. Steps: 1. 2. 3. 4. Add slf4j API Add Logging with marker to Greeter Consumer Add Logging with MDC to Greeter Provider Build and Deploy the project 4.3 DETAILED INSTRUCTIONS Before starting the hands-on you need to import the corresponding maven projects into eclipse (File -> Import -> Maven -> Existing Maven Projects). They are located in ~/Training/exercises/logging/04-application. © 2014 Talend – All rights reserved 8/15 4.3.1 ADD SLF4J API The SLF4J API is used as logging interface in the container. The Project needs a dependency to this API. Edit pom.xml of parent pom in the greeter project and add the slf4j dependency. This will make slf4j available in all subprojects. 1. Add slf4j dependency to greeter root pom. <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.6</version> </dependency> </dependencies> © 2014 Talend – All rights reserved 9/15 4.3.2 ADD LOGGING WITH MARKER TO GREETER CONSUMER 1. Add Logger, Marker and Log Statement to GreeterClient. 1. private static final Logger LOG = LoggerFactory.getLogger(GreeterClient.class); 2. private static final Marker CALL = MarkerFactory.getMarker("CALL"); 3. LOG.warn(CALL, "Calling greeter"); Note: Use slf4j imports not commons logging. © 2014 Talend – All rights reserved 10/15 4.3.3 ADD LOGGING WITH MDC TO GREETER PROVIDER 1. Add Logger, MDC and Log Statement to GreeterServiceImpl. 1. private static final Logger LOG = LoggerFactory.getLogger(GreeterServiceImpl.class); 2. MDC.put("type", "Greeting"); 3. LOG.warn("Greeting received from {}", name); 4. MDC.remove("type"); Note: Use slf4j imports not commons logging. 4.3.4 BUILD AND DEPLOY THE PROJECT Run maven install on the parent project. 1. Install the project (Right Click logging project -> Run As -> Maven install). 2. Start Application Talend ESB by executing ~/Training/container-app/bin/trun. 3. Install and start common, provider and consumer bundle in Application Talend ESB. Common install -s mvn:org.talend.training.esb/logging-greetercommon/1.0.0-SNAPSHOT Provider install -s mvn:org.talend.training.esb/logging-greeterprovider/1.0.0-SNAPSHOT Consumer install -s mvn:org.talend.training.esb/logging-greeterconsumer/1.0.0-SNAPSHOT © 2014 Talend – All rights reserved 11/15 Note: The consumer will automatically call the provider when it is installed. So this should already trigger the logging we inserted. 4.4 EXPECTED OUTCOME 4.4.1 VALIDATE THE LOG MESSAGES ON THE LOGGING SERVER 1. Call Logging’s REST service to verify log messages were created. URL http://localhost:8040/services/eventlogging/events?_s=severity==WARN&include _logmessage=true Credentials tadmin//tadmin Note: The root logger in ~/Training/container-app/etc/org.ops4j.pax.logging is already set to log into osgi:eventloglistener by default using this line. log4j.rootLogger=INFO, out, osgi:VmLogAppender, osgi:eventloglistener This means that all log messages at INFO level or higher go to the log-listener-log by default and so they ultimately reach the logging server. © 2014 Talend – All rights reserved 12/15 5 BONUS TASKS – RETRIEVE LOG EVENTS OVER REST 5.1 OBJECTIVES Use the Logging Service REST API to retrieve log messages from the database. Use Filter to sharpen your query. 5.2 OVERVIEW Use the Talend ESB Infrastructure Services Configuration Guide and/or presentation slides to create the following queries. 5.2.1 QUERIES / INSTRUCTIONS 1. Search all CALL (Marker from other exercise) events including the log message. 2. Search all events from files GreeterServiceImpl.java and GreeterClient.java. 3. Search the last 50 warnings and errors from container ‘app-container-agent’. 5.3 CONCLUSION In this exercise you used the REST logging service to query the log database. © 2014 Talend – All rights reserved 13/15 6 REFERENCES /1/ Apache Maven http://maven.apache.org/ /2/ Apache Aries Blueprint http://aries.apache.org/modules/blueprint.html /3/ Talend ESB Infrastructure Services Configuration Guide Talend_ESB_InfrastructureServices_CG_5.4.1_EN.pdf © 2014 Talend – All rights reserved 14/15 Appendix A SOLUTIONS FOR BONUS TASKS Search all CALL(Marker from other exercise) events including the log message http://localhost:8040/services/eventlogging/events?include_logmessage=true&custominfo.slf4j .marker=CALL Search all events from files GreeterServiceImpl.java and GreeterClient.java http://localhost:8040/services/eventlogging/events?logsource.file.name=GreeterServiceImpl.ja va&logsource.file.name=GreeterClient.java Search the last 50 warnings and errors from container ‘app-container-agent’ http://localhost:8040/services/eventlogging/events?_s=%28severity==WARN,severity==ERROR%2 9;agentid=app-container-agent&limit=50 © 2014 Talend – All rights reserved 15/15