Logging Best Practices Dubna 2012 Benedicto Fernandez Software Engineer CERN / GS-AIS.

Slides:



Advertisements
Similar presentations
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
Advertisements

Castelle FaxPress Plus™ FaxPress Premier and FaxPress Enterprise
JLab Lattice Portal – Data Grid Web Service Ying Chen, Chip Watson Thomas Jefferson National Accelerator Facility.
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Java Server Pages (JSP)
GUMS status Gabriele Carcassi PPDG Common Project 12/9/2004.
Logging in Java applications Sean C. Sullivan July 23, 2002 Portland Java Users Group.
Multi-Model Digital Video Library Professor: Michael Lyu Member: Jacky Ma Joan Chung Multi-Model Digital Video Library LYU9904 Multi-Model Digital Video.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
70-291: MCSE Guide to Managing a Microsoft Windows Server 2003 Network Chapter 14: Troubleshooting Windows Server 2003 Networks.
Slide 1 of 9 Presenting 24x7 Scheduler The art of computer automation Press PageDown key or click to advance.
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
Ch 11 Managing System Reliability and Availability 1.
Thomas Finnern Evaluation of a new Grid Engine Monitoring and Reporting Setup.
RUG Australia meeting 2012 Feb 6, V Tiers & sequencing suppliers Tiers and sequencing and load balancing  Tiers = groups of suppliers.
Logging with Log4j. Introduction Logging - chronological and systematic record of data processing events in a program. Possible goals: Create an audit.
© 2007 IBM Corporation IBM Global Engineering Solutions IBM Blue Gene/P Blue Gene/P Navigator.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Session 10 Windows Platform Eng. Dina Alkhoudari.
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
1 EIE424 Distributed Systems and Networking Programming –Part II 2. XML-RPC.
SelfDiagnose “who is to blame” ernest micklei, April 2007.
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
Dynamic Data Exchanges with the Java Flow Processor Presenter: Scott Bowers Date: April 25, 2007.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
LogBox Enterprise Logging Brad Wood
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Log analysis in the accelerator sector Steen Jensen, BE-CO-DO.
JSP Filters 23-Oct-15. JSP - FILTERS A filter is an object that can transform a request or modify a response. Filters are not servlets; they don't actually.
A powerful network monitoring system
1 Quick Overview Overview Network –IPTables –Snort Intrusion Detection –Tripwire –AIDE –Samhain Monitoring & Configuration –Beltaine –Lemon –Prelude Conclusions.
A Brief Documentation.  Provides basic information about connection, server, and client.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Conveying Information to Users. Outline Types of information in GridChem Inconsistency = confusion Appropriate UI for different information types Examples.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
Module 10: Preparing to Monitor Server Performance.
Chapter 5 Common Internet Tools. How Gophers Work? Internet Gopher: Client software, to find Internet files and other resources easily Organize information.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
©SoftMoore ConsultingSlide 1 Filters. Filters can be used in a web application to intercept, examine, and possibly transform requests or responses associated.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
ICM – API Server Gary Ratcliffe. 2 Agenda Webinar Programme API Server Overview JSON-RPC iCM API Service API Server and Forms New services under.
Java Servlets and Java Server Pages
EGEE-II INFSO-RI Enabling Grids for E-sciencE EGEE and gLite are registered trademarks Practicals on RGMA Valeria Ardizzone INFN.
Lecture XI: Logging and Monitoring CS 4593 Cloud-Oriented Big Data and Software Engineering.
STAR Scheduling status Gabriele Carcassi 9 September 2002.
The overview How the open market works. Players and Bodies  The main players are –The component supplier  Document  Binary –The authorized supplier.
Google Code Libraries Dima Ionut Daniel. Contents What is Google Code? LDAPBeans Object-ldap-mapping Ldap-ODM Bug4j jOOR Rapa jongo Conclusion Bibliography.
Apache Solr Dima Ionut Daniel. Contents What is Apache Solr? Architecture Features Core Solr Concepts Configuration Conclusions Bibliography.
Troubleshooting Workflow 8 Raymond Cruz, Software Support Engineer.
CHAPTER 9 File Storage Shared Preferences SQLite.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
CS520 Web Programming Bits and Pieces of Web Programming (I) Chengyu Sun California State University, Los Angeles.
1 RIC 2009 Symbolic Nuclear Analysis Package - SNAP version 1.0: Features and Applications Chester Gingrich RES/DSA/CDB 3/12/09.
Logging Microservice Deep Dive
Introduction to Servlets
UC Pro Troubleshooting Guide
The Distributed Application Debugger (DAD)
Top 5 Open Source Firewall Software for Linux User
Featured Enhancements to the IDE & Debugger
Step 1 Create Database Info activity in Adeptia Server specifying the driver, URL and user credentials information for the database in which stored.
Contents Default Dancer logging Using Logger::LogReport
Pre assessment Questions
Creating Novell Portal Services Gadgets: An Architectural Overview
PHP / MySQL Introduction
Common Conventions Ramco Aviation Solution – R5.8
WEB API.
Chapter 26 Servlets.
Chengyu Sun California State University, Los Angeles
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

Logging Best Practices Dubna 2012 Benedicto Fernandez Software Engineer CERN / GS-AIS

Only useful for debugging/development?

Contents Logging libraries Logging levels Where to log? Performance How to access? What to log?

What are we talking about? Tracing Logging Auditing

First Logging: System.out.println Easy Quick No dependencies Redirect to file or null in Production –Log everything or nothing System.out.println(“Start method1”);

Example Start method1 Before retrieve information from DB After retrieve information from DB Updating information Before save information in the DB After save information in the DB Finish method1 Start method2 Before retrieve information from DB Error retrieving information from DB: NullPointerException

Next evolution: Logging Libraries Log4j, Java Logging… log.info(“Start method1”); Provide –Time of the message –The class, the method, the line –… Print easily the stacktrace Log to files, databases, system log mechanisms

Example 06:05: INFO (Class1.java:211) Start method2 06:05: INFO (Class1.java:220) Before retrieve information from DB 06:05: INFO (Class1.java:243) Error retrieving information from DB: NullPointerException java.lang.NullPointerException at pkg.Class1.method2(Class1.java:225) at pkg.Class1.methodN(Class1.java:458) at pkg2.ClassZ.methodUpdate(ClassZ.java:458) at … at java.lang.Thread.run(Thread.java:595)

Example 06:05: INFO (Class1.java:211) Start method2 06:05: INFO (Class1.java:220) Before retrieve information from DB 06:05: INFO (Class1.java:243) Error retrieving information from DB: NullPointerException java.lang.NullPointerException at pkg.Class1.method2(Class1.java:225) at pkg.Class1.methodN(Class1.java:458) at pkg2.ClassZ.methodUpdate(ClassZ.java:458) at … at java.lang.Thread.run(Thread.java:595)

Example 06:05: INFO ( Class1.java:211 ) Start method2 06:05: INFO (Class1.java:220) Before retrieve information from DB 06:05: INFO (Class1.java:243) Error retrieving information from DB: NullPointerException java.lang.NullPointerException at pkg.Class1.method2(Class1.java:225) at pkg.Class1.methodN(Class1.java:458) at pkg2.ClassZ.methodUpdate(ClassZ.java:458) at … at java.lang.Thread.run(Thread.java:595)

Example 06:05: INFO (Class1.java:211) Start method2 06:05: INFO (Class1.java:220) Before retrieve information from DB 06:05: INFO (Class1.java:243) Error retrieving information from DB: NullPointerException java.lang.NullPointerException at pkg.Class1.method2(Class1.java:225) at pkg.Class1.methodN(Class1.java:458) at pkg2.ClassZ.methodUpdate(ClassZ.java:458) at … at java.lang.Thread.run(Thread.java:595)

Logging levels (I) Log4j –Trace –Debug –Info –Warning –Error –Fatal Java Logging –Finest –Finer –Fine –Config –Info –Warning –Severe

Example 06:05: INFO (Class1.java:211) Start method2 06:05: INFO (Class1.java:211) Parameter ‘age’ is not an Integer 06:05: INFO (Class1.java:211) Finish method2 06:05: INFO (Class1.java:211) Start method2 06:05: DEBUG (Class1.java:220) Before retrieve information from DB 06:05: ERROR (Class1.java:243) Error retrieving information from DB: NullPointerException java.lang.NullPointerException at pkg.Class1.method2(Class1.java:225) at pkg.Class1.methodN(Class1.java:458) at pkg2.ClassZ.methodUpdate(ClassZ.java:458) at … at java.lang.Thread.run(Thread.java:595)

Example 06:05: INFO (Class1.java:211) Start method2 06:05: INFO (Class1.java:211) Parameter ‘age’ is not an Integer 06:05: INFO (Class1.java:211) Finish method2 06:05: INFO (Class1.java:211) Start method2 06:05: DEBUG (Class1.java:220) Before retrieve information from DB 06:05: ERROR (Class1.java:243) Error retrieving information from DB: NullPointerException java.lang.NullPointerException at pkg.Class1.method2(Class1.java:225) at pkg.Class1.methodN(Class1.java:458) at pkg2.ClassZ.methodUpdate(ClassZ.java:458) at … at java.lang.Thread.run(Thread.java:595)

Example 06:05: INFO (Class1.java:211) Start method2 06:05: INFO (Class1.java:211) Parameter ‘age’ is not an Integer 06:05: INFO (Class1.java:211) Finish method2 06:05: INFO (Class1.java:211) Start method2 06:05: DEBUG (Class1.java:220) Before retrieve information from DB 06:05: ERROR (Class1.java:243) Error retrieving information from DB: NullPointerException java.lang.NullPointerException at pkg.Class1.method2(Class1.java:225) at pkg.Class1.methodN(Class1.java:458) at pkg2.ClassZ.methodUpdate(ClassZ.java:458) at … at java.lang.Thread.run(Thread.java:595)

Logging levels (II) log4j.logger.ch.cern.ais=DEBUG log4j.logger.ch.cern.ais.package.Class1=TRACE log4j.logger.org.springframework=ERROR log4j.logger.org.springframework.ws=INFO

Where to log? Text files (Plain text, XML,…) Binary files Database Syslog (Windows & Unix/Linux) Network (TCP & UDP)

Where to log? Text files (Plain text, XML,…) Binary files Database Syslog (Windows & Unix/Linux) Network (TCP & UDP) Always to a Text file (+ something else)?

Performance "hidden" cost of parameter construction logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));

Performance "hidden" cost of parameter construction logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i])); Solution if (logger.isDebugEnabled()) { logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i])); }

Next evolution: Logging Libraries v2.0 Simple Logging Facade (SLF4J) –Logback Parameterized messages logger.debug("Entry number: {} is {}“, i, String.valueOf(entry[i]));

Multiple users (I) Different users working simultaneously Log messages mixed for different users Difficult to trace user’s actions

Multiple users (I) Different users working simultaneously Log messages mixed for different users Difficult to trace user’s actions Log User ID

Multiple users - Example 06:05: INFO (Class1.java:41) User=bfernan; message=‘Start method1’; 06:05: DEBUG (Class1.java:44) message=‘Before retrieve information from DB’; 06:05: DEBUG (Class1.java:46) message=‘After retrieve information from DB’; 06:05: INFO (Class1.java:50) message=‘Updating information’; 06:05: DEBUG (Class1.java:94) message=‘Before save information in the DB’; 06:05: DEBUG (Class1.java:96) message=‘After save information in the DB’; 06:05: INFO (Class1.java:100) User=bfernan; message=‘Finish method1’; 06:05: INFO (Class1.java:211) User=xxxxxxx; message=‘Start method2’; 06:05: DEBUG (Class1.java:220) message=‘Before retrieve information from DB’; 06:05: ERROR (Class1.java:243) message=‘Error retrieving information from DB: NullPointerException’;

Multiple users (II) Mapped Diagnostic Contexts (MDC) public void serviceMethod1(String userName,…) { String userName = getLoggedUserName(); MDC.put( “userName”, userName); } Configuration …PatternLayout=%T User=%X{userName};message=‘%m’;%n

Multiple users (III) public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; Principal principal = req.getUserPrincipal(); // Please note that we could have also used a cookie to // retrieve the user name if (principal != null) { String username = principal.getName(); MDC.put(USER_KEY, username); } try { chain.doFilter(request, response); } finally { MDC.remove(USER_KEY); } }

Multiple users (III) public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; Principal principal = req.getUserPrincipal(); // Please note that we could have also used a cookie to // retrieve the user name if (principal != null) { String username = principal.getName(); MDC.put(USER_KEY, username); } try { chain.doFilter(request, response); } finally { MDC.remove(USER_KEY); } }

Multiple users - Example 06:05: INFO (Class1.java:41) User=bfernan; message=‘Start method1’; 06:05: DEBUG (Class1.java:44) User=bfernan; message=‘Before retrieve information from DB’; 06:05: DEBUG (Class1.java:46) User=bfernan; message=‘After retrieve information from DB’; 06:05: INFO (Class1.java:50) User=bfernan; message=‘Updating information’; 06:05: DEBUG (Class1.java:94) User=bfernan; message=‘Before save information in the DB’; 06:05: DEBUG (Class1.java:96) User=bfernan; message=‘After retrieve information in the DB’; 06:05: INFO (Class1.java:100) User=bfernan; message=‘Finish method1’; 06:05: INFO (Class1.java:211) User=xxxxxxx; message=‘Start method2’; 06:05: DEBUG (Class1.java:220) User=xxxxxxx; message=‘Before retrieve information from DB’; 06:05: ERROR (Class1.java:243) User=xxxxxxx; message=‘Error retrieving information from DB: NullPointerException’ ;

Multiple Connections Same User (I) “Account” shared by 2+ end users Different –Session ID –Remote Address user1

Multiple Connections Same User (I) “Account” shared by 2+ end users Different –Session ID –Remote Address Log Session ID Log Remote IP user1

Multiple Connections Same User (I) - Example 06:05: INFO (Class1.java:41) IP= ;Session= ; User=bfernan;message=‘Start method1’; 06:05: DEBUG (Class1.java:44) IP= ;Session= ; User=bfernan;message=‘Before retrieve information from DB’; 06:05: INFO (Class1.java:211) IP= ;Session= ; User=bfernan;message=‘Start method2’; 06:05: DEBUG (Class1.java:220) IP= ;Session= ; User=bfernan;message=‘Before retrieve information from DB’; 06:05: DEBUG (Class1.java:46) IP= ;Session= ; User=bfernan;message=‘After retrieve information from DB’; 06:05: INFO (Class1.java:50) IP= ;Session= ; User=bfernan;message=‘Updating information’; 06:05: DEBUG (Class1.java:94) IP= ;Session= ; User=bfernan;message=‘Before save information in the DB’; 06:05: DEBUG (Class1.java:96) IP= ;Session= ; User=bfernan;message=‘After retrieve information in the DB’; 06:05: ERROR (Class1.java:243) IP= ;Session= ; User=bfernan;message=‘Error retrieving information from DB: NullPointerException’; 06:05: INFO (Class1.java:100) IP= ;Session= ; User=bfernan;message=‘Finish method1’;

Multiple Connections Same User (II) What about tabs? –Same Remote IP –Same Session ID

Multiple Connections Same User (II) What about tabs? –Same Remote IP –Same Session ID Log Transaction ID

Multiple Connections Same User (I) - Example 06:05: INFO (Class1.java:41) IP= ;Session= ; Transaction= ;User=bfernan;message=‘Start method1’; 06:05: DEBUG (Class1.java:44) IP= ;Session= ; Transaction= ;User=bfernan;message=‘Before retrieve information from DB’; 06:05: INFO (Class1.java:211) IP= ;Session= ; Transaction= ;User=bfernan;message=‘Start method2’; 06:05: DEBUG (Class1.java:220) IP= ;Session= ; Transaction= ;User=bfernan;message=‘Before retrieve information from DB’; 06:05: DEBUG (Class1.java:46) IP= ;Session= ; Transaction= ;User=bfernan;message=‘After retrieve information from DB’; 06:05: INFO (Class1.java:50) IP= ;Session= ; Transaction= ;User=bfernan;message=‘Updating information’; 06:05: DEBUG (Class1.java:94) IP= ;Session= ; Transaction= ;User=bfernan;message=‘Before save information in the DB’; 06:05: DEBUG (Class1.java:96) IP= ;Session= ; Transaction= ;User=bfernan;message=‘After retrieve information in the DB’; 06:05: ERROR (Class1.java:243) IP= ;Session= ; Transaction= ;User=bfernan;message=‘Error retrieving information from DB: NullPointerException’; 06:05: INFO (Class1.java:100) IP= ;Session= ; Transaction= ;User=bfernan;message=‘Finish method1’;

How to access the information? v1.0 View the file –Human readable format System utils (grep command) $ grep '.*ERROR.* User bfernan.*' log_cra-ws.log –Easy for regext (Ex: key=value;) $ grep ‘.*ERROR.*;User=bfernan;.*’ log_cra-ws.log

Cluster of Servers Application distributed several Servers 1 log file for each server Which one contains the error?

How to access the information? v2.0 Forward log messages to a Server –Log4j Server UI Tools –Apache Log4j Chainsaw –MindTree Insight

Analytic Tools Splunk –Indexer –Search Engine –“Pseudo” real-time –Alerts

Example

What to log? User requests (start & end) Service methods calls (start & end) Calls to external systems ( before & after) Errors Any relevant state

Conclusions (I) Log everything useful, not only debug information Log to text files, human readable format Use a template parseable with regexp (Ex: key=value;)

Conclusions (II) Use the appropriate level One single action per line Be careful with the performance Be ready to profit of it

Why not logging standards?

“A good job can save a day of work”

Спасибо! Benedicto Fernandez Software Engineer CERN / GS-AIS