Mais conteúdo relacionado Semelhante a Application Logging for large systems (20) Mais de Jane Prusakova (20) Application Logging for large systems1. ©2010 Improving Enterprises, Inc.
Logging For Fun and Profit
Jane Prusakova
Jane.Prusakova@ImprovingEnterprises.com
http://softwareandotherthings.blogspot.com
Improving Enterprises
Houston JUG
2014
4. ©2010 Improving Enterprises, Inc.
Peek into the soul
Real setup
Real data
Real users
Real work
Dev environment
Happy path
Minimum load
Limited data
6. ©2010 Improving Enterprises, Inc.
Logging [vs Debugging]
Set up once, always ready to use
Minimum disruption to the flow
Works locally and in the cloud
Faster data collection
Collected data is persisted
14. ©2010 Improving Enterprises, Inc.
Yes, I want to setup logging!
Pick a framework
Configure logging
Storage and access
Getting value from logs
15. ©2010 Improving Enterprises, Inc.
Log4J SLF4J
Apache MIT license
Logging framework Logging facade
Configuration, log levels and categories,
rotate log files, thread-safe logging.
Support: online documentation, tutorials,
online forums.
16. ©2010 Improving Enterprises, Inc.
Database Files
Easy to parse,
hard to evolve
Very hard to parse,
easy to change
Uses DB
connections
Requires FS
access
Can cause app
crash, loss of logs,
slow down app
Can fill up space
19. ©2010 Improving Enterprises, Inc.
Log Message
What to log with the message
Importance level
Timestamp
Where in the code
Data being processed
System state info
20. ©2010 Improving Enterprises, Inc.
Example layout
log4j.appender.stdout.layout.ConversionPattern=
%d %5p [%t] (%F:%L) - %m%n
- Date
- Log Level
- Thread name
- File and line (slow to retrieve)
25. ©2010 Improving Enterprises, Inc.
What to log
Input and output
Errors and exceptions
Computation results
Integration points
Thread rendezvous
26. ©2010 Improving Enterprises, Inc.
Input and output
public int calculateCost(String user, Flight flight)
{
log.debug(“calculateCost: “ + user + “: “ +
flight);
int cost = … ;
… // cost calculation
log.debug((“calculateCost: cost for “ + user
+ “: “ + flight + “ = “ + cost);
return cost;
}
27. ©2010 Improving Enterprises, Inc.
Errors and exceptions
// do dangerous work
result = DoDangerousWork(user, flight);
}
catch (Exception e)
{
log.error(“methodName: exception in
DoDangerousWork for “ + user + “: “ + flight, e);
// recover or re-throw
}
28. ©2010 Improving Enterprises, Inc.
More
Log destination, parameters, outcomes
DB calls
SOAP calls
Wait time
Thread joins
Available memory
Memory-intensive operations
Intermediate calculation results
For complicated calculations
29. ©2010 Improving Enterprises, Inc.
Avoid
Little information
… // step 1
logger.info(“did something - XXXX”);
… // step 2
logger.info(“did more work - YYYY”);
foreach (…) {
… // useful work
logger.info(“working hard”);
}
30. ©2010 Improving Enterprises, Inc.
Avoid
Code cluttering
if (logger.isDebugEnabled()) {
logger.debug(“Show Views");
logger.debug("Address:n" +
view.getAddress());
logger.debug("Email:n" +
view.getEmail());
}
31. ©2010 Improving Enterprises, Inc.
Watch for logging-caused bugs
Side effects
Logger.info(count++ + “: did something”);
Errors and exceptions
Logger.info(m.GetValue());
41. ©2010 Improving Enterprises, Inc.
Learning from the logs
> grep userName myApplication-MMDDYYYY.log
> grep methodName myApplication-MMDDYYYY.log
> grep FATAL myApplication-MMDDYYYY.log
> tail -2000 myApplication-MMDDYYYY.log | grep Exception
42. ©2010 Improving Enterprises, Inc.
Querying logs using Awk
GNU Awk www.gnu.org/software/gawk
Create histograms
Wait times
Number of calls
Exceptions per time period or per user
Compare and relate events
Exception stacks traces
Outcomes by caller or thread
44. ©2010 Improving Enterprises, Inc.
Jane.Prusakova at ImprovingEnterprises.com
SoftwareAndOtherThings.blogspot.com
@jprusakova
Jane Prusakova
http://www.slideshare.net/jprusakova
45. ©2010 Improving Enterprises, Inc.
Logging For Fun and Profit
Jane Prusakova
Jane.Prusakova@ImprovingEnterprises.com
http://softwareandotherthings.blogspot.com
Improving Enterprises
Houston JUG
2014