APPLICATION LOGGING
About MESander De VosSoftware EngineerRealDolmen 2008Past projectsMaTMa (M*)E-Metro (FOD-ECO)SP10B (FOD-FIN)MIK (FOD-MOB)
QuotesFrom The Field“Whoneeds logs? Isuredon’t!”“Debugger is better! Sysoutworkstoo!”“Isn’tthatwhatinfrastructure does?”“It slows down disk and memory!”“It isn’t in the spec!”“We don’tknowwhatto log – we’lljust log something!”“We don’tknowhow – we’lljust do itsomehow!”
AgendaWhat is loggingDefinition andChallengesWhyloggingWhouses logsWhat logs are usedforFunctional or non-functionalWhatto logWhatwill (not) help youLog messagedecomposedGuidelinesHow to log in JavaLogging in productionLog processing and analysis
What is logging
Definition“Logs are the recordings of one or more events occurring on information systems.”“Logs can be organized based on the program, day, severity, host, or a number of other categories.““Logs may be referred to as log files, audit logs, or audit trails.Logs also cover alerts, alarms and event records.“
Log challengesDecentralizationCloudSOAVolatilityMultiple tiersandlayersArchivalAccessabilityAbsence of critical informationRandom log formats
WHY logging
Whouses logsManaged ServicesSecurity TeamsMonitorDetectInvestigateTrackAnalyzeAuditorsDevelopersDebuggingCustomer
What logs are usedforDebugging andForensicsFault monitoringPerformance monitoringTroubleshootingFeature usageSecurity / Incident detectionRegulatoryand standards compliance
Functional – non-functionalloggingFunctionalAuditGovernanceSecurityNon-functionalFaults, Errors, ExceptionsExecution contextPerformanceComponent usage
Putting italltogetherFunctional LogsCustomerAuditAlways onRequirementsScope knownYears‘Clutter, yuck, slow’Non-Functional LogsSystem operatorDeveloperSometimes onErrors, Exceptions, DebugScope notknownHours, Days‘Mightcome in handy’
WHAT to log
Keep in mind”Whatwouldhelp YOU at 3 AM in the morning? “Image: Ambro / FreeDigitalPhotos.net
Whatwillhelp youExact notice of whathappenedWhenWhereHowWhoClearconcise context informationAnalysis possible without applicationManualSemi-automatedAutomatedRemotelycollectible filesLow footprintProven reliableandauthentic
Whatwill help youexamples2011-05-31 08:46:11,308 +0200INFO  [eventlog.security] ACCESS OF ProfileServiceImpl.findProfilesBY[login: some_username];Password: [PROTECTED];Authenticated: true;Details: RemoteIpAddress: 192.168.156.17;SessionId: 8XyrNkLWv7FdXS…Granted Authorities:ROLE_USER,ROLE…
Whatwon’thelp youNo details about the recordNo context informationInconsistent format or bad useNon-correlatableSubjective/interpretativemessageToo muchuseless log recordsLoggingtoone single big file
Whatwon’t help you – example#1log4j: setFile called: ./logs/be/mobistar/network-status/log_functional.log, falselog4j: setFileendedtis nendefaulttis nendefaultActivations : 15Deactivations : 0In straigt to resource filter
Whatwon’t help you – example#2INFO  [dao.ProductDao] [] - FOUND 40INFO  [web.listeners.PhaseLogger] [] - +RENDER_RESPONSEINFO [service.ProductFamilyService] [] - product in family is trueINFO  [.dao.ProfileDao] [] - [OBJECTS] find profiles
log messagedecomposed
“A log record shouldbeunderstandableby a human, andeasily machine processable.”
LoggingGuidelines: PrioritiesFatalApplication crash&burnErrorExceptionsMonitoring team alertWarnMonitor health, performanceInfoInformative ContextAudit trailDebugExtensive ContextDevelopment, TestingTroubleshooting
LoggingGuidelines: ExceptionsHandlingRecoverLog the details ifcriticalNot Handling, TranslatingTranslateHandling logic ifnotpropagatingNot HandlingPropagateSomeoneelsewill handle (and log!)Chooseexceptionsto logDefendfromstacktrace chaosChoosewhatto log foreachexceptionCatching block has all context details!
LoggingGuidelines: Correlation1 transaction = * log recordsCorrelationnecessaryExecutiontrailShared context variableShared per transactionReuse of context variablesNested Diagnostic ContextMap Diagnostic ContextOnlyonecorrelationUse a context uniquevariableCorrelate transactions
How to log iN
How loggingframeworkswork
Java Logging FrameworksImplementationSystem.out – System.errRedirect outputJava UtilLoggingLog4jLogbackAbstractionCommonsLoggingSLF4J
Java UtilLoggingJava 1.4+Based on Log4JLess features out of the boxConsoleFileStream
Log4jFirst frameworkIntroductionof Logger, Appender, LevelHiearchical LoggersConfigurableappenders, e.g.MailAppenderFileAppenderSMTPAppenderSocketAppenderSyslogAppenderLeader quitandstartedlogback
CommonsLoggingApache ProjectAPI BridgeAPI-calls forward toLog4j if on CPFalls back to JULPlaguedDouble ConfigurationRuntime dependency checkClasspathScanningDiscontinuedv1.1.1 dates from end 2007
Slf4j - LogbackTwolibrariestorulethemallSlf4jComparablewithcommons-loggingParameter parsingFramework  bridgesMuch more powerfulLogbackEvolved log4jImplements Slf4j“Picking up where log4j leaves off”TestingFilters on-need-base
SLF4J Binding
SLF4J Bridging
Keepingit performantString concatenationLOGGER.debug("Hello " + name);Protected blockif (logger.isDebugEnabled()) {LOGGER.debug("Hello " + name);}Slf4jLOGGER.debug("Hello {}", name);
Context Variables In PracticeNDC.push(correlationId);app.logMe("Hello world!");NDC.pop();Use %x in PatternConversionPattern= %x %d %m %ncorrelationId 2011-06-21 09:20:41 [INFO] Hello world!
Specialized LoggersLogger for classFine-tune logExecutiontraceHow distinguishSecurityPerformance BusinessSpecialized LoggersPrioritiesOutput handlersGroupedlogging
Logging In ProductionOnlynecessaryloggingSituation -> turn on debugloggingNo restart: DynamicReloading‘Watch’ file for changesLog file managementRolling fileSeperation of concernsClusteringDifferent systems generatemessagesSynchronization of timestampsCorrelation on host-specific files
My OpinionImportance of loggingwillgrowMobile / offline applicationsCloud integrationSystem interactionLogging standards enterprisewideStandardization of logging effortInexpensiveexerciseDraft a standardBuild adapters / patternsEnforce standards
Log Processing and analysis
Log AnalysisBang foryourbuckXpoLoghttp://www.xpolog.comLicensedFasterSplunkhttp://www.splunk.comFree Edition‘Slow’ AJAX feelNice graphicsModular (http://www.splunkbase.com)Tuningyourpattern is important?
Demo
For more information:visit our website WWW.REALDOLMEN.COMFollow us on:Selected presentations are available on:Thank YouOr scan this QR code with your Smartphone to immediately go to the website

Functional and non functional application logging