SlideShare uma empresa Scribd logo
1 de 22
Logs
Objective
• all activities that affect user state or
balances are formally trackedAuditable
• it’s possible to determine where an
activity occurs in all tiers of the
application
Traceable
• logs cannot be overwritten or tampered
with by local or remote users
High
integrity
Message Priorities/Levels
• Severe errors that cause premature termination.fatal
• Other runtime errors or unexpected conditions.error
• are undesirable or unexpected, but not necessarily
"wrong".Warn
• Interesting runtime events (startup/shutdown).Info
• detailed information on the flow through the system.Debug
• more detailed information.Trace
What to log?
Log all the things
Work Smarter, not Harder
Default Message Priority/Level
By default the message priority
should be no lower than info.
That is, by default debug message
should not be seen in the logs.
Default production log level
WARNING
Where to define logger layout?
• private static Logger log = Logger.getLogger(
MyClass.class )
– log.error()
– log.warn()
– log.info()
– log.debug()
• "%r [%t] %-5p %c - %m%n"
– 176 [main] INFO org.foo.Bar - Located nearest gas
station.
What format to use?
• A SINGLE LINE
• Timestamps with timezone, to the
millisecond or nanosecond
• Class name + line number
• Meaningful context
Best practices for app
• Do not allow exceptions to go
unhandled/reach the browser
• Display custom error pages to users with an
email link for feedback
• Do not enable “Robust Exception Information”
in production.
• Rotate log files to keep them current
Use parameterized logging
• LOG.debug("Method called with arg " + arg);
• BAD: string varies with argument
Use parameterized logging
• if (LOG.isDebugEnabled()) {
LOG.debug("Method called with arg {}", arg);
• BAD: code clutter
Use parameterized logging
• LOG.debug("arg is {}", arg);
• BAD: wrong level of language, this would be
okay on TRACE
Use parameterized logging
• LOG.debug("Method called with arg {}", arg);
• GOOD: string literal, no dynamic objects
Exception example
• catch (SomeException ex) { LOG.warn("Failed
to do something with {}, continuing", arg, ex);
}
• GOOD: note how there is no "{}" for ex
Provide useful event context
• LOG.debug(arg.toString());
• VERY BAD:
– no context provided
– non-constant message string
– assumes useful toString()
Provide useful event context
• LOG.debug("{}", arg);
• VERY BAD
– no context provided
Provide useful event context
• try { doSomething(arg); ... }
catch (SomeException ex) { }
• COMPLETELY BAD
– silently ignoring errors!!!
Provide useful event context
• try { doSomething(arg);}
catch (SomeException ex) {
LOG.warn(ex.getMessage()); }
• EXTREMELY BAD
– message is not constant
– no context is provided
– ex.getCause() is lost
– call stack is lost
Provide useful event context
• try { doSomething(arg); ... }
catch (SomeException ex) {
LOG.warn("Failed to do something with {},
ignoring it", arg, ex); }
• GOOD
– string literal
– we explain what we tried to do
– we pass along information we have about the failure
– we explain that we recovered from the failure
Provide useful event context
• try { doSomething(arg); ... }
catch (SomeException ex) { LOG.error("Failed to do
something with {}", arg, ex);
throw new RuntimeException("Failed to do
something", ex); }
• GOOD
– string literal
– we explain what we tried to do
– we pass along information we have about the failure
– we escalate the failure to our caller
– we also 'chain' the exception so it is not lost and can be
correlated
Anything else?
• Separate files for different areas of interest
• Always Log To Local Disk
• http://juliusdavies.ca/logging.html

Mais conteúdo relacionado

Destaque

Destaque (8)

13 Signs You Might Be A Bad Boss
13 Signs You Might Be A Bad Boss13 Signs You Might Be A Bad Boss
13 Signs You Might Be A Bad Boss
 
10 Shocking Stats About Disengaged Employees
10 Shocking Stats About Disengaged Employees10 Shocking Stats About Disengaged Employees
10 Shocking Stats About Disengaged Employees
 
20 Inspirational Leadership Quotes
20 Inspirational Leadership Quotes20 Inspirational Leadership Quotes
20 Inspirational Leadership Quotes
 
Do You Struggle With Employee Recognition?
Do You Struggle With Employee Recognition?Do You Struggle With Employee Recognition?
Do You Struggle With Employee Recognition?
 
BigWeatherGear Group and Corporate Services Brochure 2013
BigWeatherGear Group and Corporate Services Brochure 2013BigWeatherGear Group and Corporate Services Brochure 2013
BigWeatherGear Group and Corporate Services Brochure 2013
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
The Productivity Secret Of The Best Leaders
The Productivity Secret Of The Best LeadersThe Productivity Secret Of The Best Leaders
The Productivity Secret Of The Best Leaders
 
10 Ways Your Boss Kills Employee Motivation
10 Ways Your Boss Kills Employee Motivation10 Ways Your Boss Kills Employee Motivation
10 Ways Your Boss Kills Employee Motivation
 

Semelhante a Logs

Semelhante a Logs (20)

Cashing in on logging and exception data
Cashing in on logging and exception dataCashing in on logging and exception data
Cashing in on logging and exception data
 
Coding for production
Coding for productionCoding for production
Coding for production
 
Monitoring and Debugging your Live Applications
Monitoring and Debugging your Live ApplicationsMonitoring and Debugging your Live Applications
Monitoring and Debugging your Live Applications
 
Logging
LoggingLogging
Logging
 
Java 8 and beyond, a scala story
Java 8 and beyond, a scala storyJava 8 and beyond, a scala story
Java 8 and beyond, a scala story
 
10 Tips to improve your application logs
10 Tips to improve your application logs10 Tips to improve your application logs
10 Tips to improve your application logs
 
Instrumentation of Software Systems
Instrumentation of Software SystemsInstrumentation of Software Systems
Instrumentation of Software Systems
 
Presentation log4 j
Presentation log4 jPresentation log4 j
Presentation log4 j
 
Presentation log4 j
Presentation log4 jPresentation log4 j
Presentation log4 j
 
Logstash and friends
Logstash and friendsLogstash and friends
Logstash and friends
 
Monitor all the things - Confoo
Monitor all the things - ConfooMonitor all the things - Confoo
Monitor all the things - Confoo
 
Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVM
 
Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek
 
Docker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic StackDocker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic Stack
 
Elk with Openstack
Elk with OpenstackElk with Openstack
Elk with Openstack
 
Java Logging
Java LoggingJava Logging
Java Logging
 
Logstash
LogstashLogstash
Logstash
 
Helpful logging with Java
Helpful logging with JavaHelpful logging with Java
Helpful logging with Java
 
ELK stack at weibo.com
ELK stack at weibo.comELK stack at weibo.com
ELK stack at weibo.com
 
Debugging webOS applications
Debugging webOS applicationsDebugging webOS applications
Debugging webOS applications
 

Mais de Hanokh Aloni

Mais de Hanokh Aloni (18)

NWD Total commander for fun and profit!!!
NWD Total commander for fun and profit!!!NWD Total commander for fun and profit!!!
NWD Total commander for fun and profit!!!
 
CI CD OPS WHATHAVEYOU
CI CD OPS WHATHAVEYOUCI CD OPS WHATHAVEYOU
CI CD OPS WHATHAVEYOU
 
How to write proper GIT commit messages.pptx
How to write proper GIT commit messages.pptxHow to write proper GIT commit messages.pptx
How to write proper GIT commit messages.pptx
 
Architectural kata 0 of n.pptx
Architectural kata 0 of n.pptxArchitectural kata 0 of n.pptx
Architectural kata 0 of n.pptx
 
Code smells (1).pptx
Code smells (1).pptxCode smells (1).pptx
Code smells (1).pptx
 
NWD the73js.pptx
NWD the73js.pptxNWD the73js.pptx
NWD the73js.pptx
 
top developer mistakes
top developer mistakes top developer mistakes
top developer mistakes
 
Things senior developers should know
Things senior developers should knowThings senior developers should know
Things senior developers should know
 
Cynefin framework in software engineering
Cynefin framework in software engineeringCynefin framework in software engineering
Cynefin framework in software engineering
 
Microservices
MicroservicesMicroservices
Microservices
 
Wcbpijwbpij new
Wcbpijwbpij newWcbpijwbpij new
Wcbpijwbpij new
 
Trunk based vs git flow
Trunk based vs git flowTrunk based vs git flow
Trunk based vs git flow
 
How to write unmaintainable code
How to write unmaintainable codeHow to write unmaintainable code
How to write unmaintainable code
 
How i learned to stop worrying and love the logs
How i learned to stop worrying and love the logsHow i learned to stop worrying and love the logs
How i learned to stop worrying and love the logs
 
Game is ggj2018 presentation
Game is ggj2018 presentationGame is ggj2018 presentation
Game is ggj2018 presentation
 
Microservices
MicroservicesMicroservices
Microservices
 
Game is ggj2017 presentation
Game is ggj2017 presentationGame is ggj2017 presentation
Game is ggj2017 presentation
 
02 terms and issues
02 terms and issues02 terms and issues
02 terms and issues
 

Último

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

Último (20)

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 

Logs

  • 2. Objective • all activities that affect user state or balances are formally trackedAuditable • it’s possible to determine where an activity occurs in all tiers of the application Traceable • logs cannot be overwritten or tampered with by local or remote users High integrity
  • 3. Message Priorities/Levels • Severe errors that cause premature termination.fatal • Other runtime errors or unexpected conditions.error • are undesirable or unexpected, but not necessarily "wrong".Warn • Interesting runtime events (startup/shutdown).Info • detailed information on the flow through the system.Debug • more detailed information.Trace
  • 4. What to log? Log all the things Work Smarter, not Harder
  • 5. Default Message Priority/Level By default the message priority should be no lower than info. That is, by default debug message should not be seen in the logs.
  • 6. Default production log level WARNING
  • 7. Where to define logger layout? • private static Logger log = Logger.getLogger( MyClass.class ) – log.error() – log.warn() – log.info() – log.debug() • "%r [%t] %-5p %c - %m%n" – 176 [main] INFO org.foo.Bar - Located nearest gas station.
  • 8. What format to use? • A SINGLE LINE • Timestamps with timezone, to the millisecond or nanosecond • Class name + line number • Meaningful context
  • 9. Best practices for app • Do not allow exceptions to go unhandled/reach the browser • Display custom error pages to users with an email link for feedback • Do not enable “Robust Exception Information” in production. • Rotate log files to keep them current
  • 10. Use parameterized logging • LOG.debug("Method called with arg " + arg); • BAD: string varies with argument
  • 11. Use parameterized logging • if (LOG.isDebugEnabled()) { LOG.debug("Method called with arg {}", arg); • BAD: code clutter
  • 12. Use parameterized logging • LOG.debug("arg is {}", arg); • BAD: wrong level of language, this would be okay on TRACE
  • 13. Use parameterized logging • LOG.debug("Method called with arg {}", arg); • GOOD: string literal, no dynamic objects
  • 14. Exception example • catch (SomeException ex) { LOG.warn("Failed to do something with {}, continuing", arg, ex); } • GOOD: note how there is no "{}" for ex
  • 15. Provide useful event context • LOG.debug(arg.toString()); • VERY BAD: – no context provided – non-constant message string – assumes useful toString()
  • 16. Provide useful event context • LOG.debug("{}", arg); • VERY BAD – no context provided
  • 17. Provide useful event context • try { doSomething(arg); ... } catch (SomeException ex) { } • COMPLETELY BAD – silently ignoring errors!!!
  • 18. Provide useful event context • try { doSomething(arg);} catch (SomeException ex) { LOG.warn(ex.getMessage()); } • EXTREMELY BAD – message is not constant – no context is provided – ex.getCause() is lost – call stack is lost
  • 19. Provide useful event context • try { doSomething(arg); ... } catch (SomeException ex) { LOG.warn("Failed to do something with {}, ignoring it", arg, ex); } • GOOD – string literal – we explain what we tried to do – we pass along information we have about the failure – we explain that we recovered from the failure
  • 20. Provide useful event context • try { doSomething(arg); ... } catch (SomeException ex) { LOG.error("Failed to do something with {}", arg, ex); throw new RuntimeException("Failed to do something", ex); } • GOOD – string literal – we explain what we tried to do – we pass along information we have about the failure – we escalate the failure to our caller – we also 'chain' the exception so it is not lost and can be correlated
  • 21. Anything else? • Separate files for different areas of interest • Always Log To Local Disk

Notas do Editor

  1. It is important to ensure that log message are appropriate in content and severity. The following guidelines are suggested: fatal  Severe errors that cause premature termination. Expect these to be immediately visible on a status console. See also Internationalization. error  Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. See also Internationalization. Warn Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console. See also Internationalization. Info Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. See also Internationalization. Debug detailed information on the flow through the system. Expect these to be written to logs only. Trace more detailed information. Expect these to be written to logs only.
  2. Why timezone? Answer: maybe half our servers are in Toronto. If our sysadmins decide every computer should use GMT (or PST), great, but let's give the sysadmins the option! Timezone also helps around daylight-savings changes. Why nanosecond? Why not to the second? Answer: we want to minimize the number of lines occuring with identical timestamps. This is very important if you want to split logs into separate files covering different areas of interest (e.g. connection-history.log and messages.log). If your timestamps are to the nanosecond, you can re-merge these files together and usually not lose the order of events ("sort -m"). Personally, for Java I prefer to use "yyyy-MM-dd/HH:mm:ss.SSS/zzz". (I would use nanoseconds if Java supported it). High Volume Logging: It is probably impossible for any logging system to guarantee logs get written chronologically (in same order as the original events). In an extremely highly loaded system you will sometimes see out-of-order events in your log, usually by a few milliseconds. If you only log to the second, you cannot reestablish the chronology. Log analysis tools also need to be aware of this and not blowup when fed data that is not strictly chronological.