azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

Coding guideline on logging

Open guangyang opened this issue 13 years ago • 10 comments

Moved from https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/269. Currently, in service bus, we always log when an exception is thrown. We might want to decide a team practice on whether that is the best thing we should do.

guangyang avatar Mar 01 '13 20:03 guangyang

some related stackoverflow post http://stackoverflow.com/questions/10838907/azure-java-tomcat-logging

gcheng avatar Mar 18 '13 17:03 gcheng

+1

And I think it's a good idea to switch to sl4j.

BTW: I've started to develop a Log4j Appender for Windows Azure Table storage

JMayrbaeurl avatar Apr 12 '13 10:04 JMayrbaeurl

+1 for slf4j.

If you're really goint to do a log4j Appender, make sure to look at blitz4j before reinventing the wheel.

You may want to base your appender off logback instead, as it addresses many of the issues with log4j which blitz does. Managed by the slf4j and log4j author.

BillAtPros avatar Apr 16 '13 16:04 BillAtPros

What are the reasons that you guys are up to slf4j / blitz4j /logback? The more specific reasons for Azure, the better.

gcheng avatar Apr 16 '13 22:04 gcheng

The intention is create a logger that logs to storage. This is appealing because multilple instances of a Role can log all message to a central location. In the case of WebRole or WorkerRole, the logs won't be lost if the underlying VM gets recycled.

Log4j is a very popular open-source logging framework and standard for a large percentage of Java projects.

Slf4j is a newer open-source logging standard by the same creator. It is a spec, not an implementation. It allows a project to code to a logging API, and choose the actual logging framework used at runtime via configuration. Implementations can be changed out without touching a line of source code. There are many adapters to popular logging frameworks including Apache commons-logging, the Java logging framework (which wasn't standard until Java 1.4 is memory serves), log4j and logback.

blitz4j is Netflix's open-source rewrite of log4j. It deals with some of the low level locking/sychronization issues in log4j. For most use, these are not an issue, but very high throughput scenarios become a bottleneck. Cloud apps tend to be high throughput. Log4j was written before the java.util.concurrent package was available and relied on older, larger grained locking mechanisms.

Logback is a new open-source logging framework, written by the author of log4j and slf4j. It is an Slf4j implementation. It takes advantage of the java.util.concurrent and other, newer features in the Java platform. It deals with some of the same issues in log4j that blitz4j addressed. It is often chosen as the runtime logging implementation for application which use Slf4j.

SO: slf4j because its a (relatively) implementation agnostic standard which applications can code to for logging purposes. logback for a more modern, concurrency and scalability friendly slf4j implementation.

My off-the-cuff recommendation for a storage based logging solution would be to create a logback Appender implementation which writes to storage. Appropiate buffering of log messages and correlating them by Role instance on the storage side will be interesting challenges.

TTFN

BillAtPros avatar Apr 16 '13 23:04 BillAtPros

Please note that we're discussing two topics here. First of all is the change from using Apache Commons Logging in the sources to using the sl4j api. The second one is developing a logging appender for log4j or logback that's able to log to Azure table storage with high performance scenarios (best would be to do logging asynchronously without affecting the performance of the application). I'll investigate into the logback version after I've finished the log4j based appender.

JMayrbaeurl avatar Apr 18 '13 16:04 JMayrbaeurl

Agreed:

  1. transition to slf4j == no brainer. Still supports Apache Commons Logging as an implementation.

  2. "Async" logging Appender. If I were doing the dev, I'd start with the logback version (and probably never look back)

log4j has well documented performance issues based on fundamental design anachronisms, specifically using sychronization to ensure safety in concurrent situtations. Its use is antithetical to the adjective phrase "high performance".

See the blitz4j project for a succint discussion of the issues. blitz4j was developed in response to the scenario you are solving: high performance logging in a cloud environment. It was a fork of log4j and was created before logback, which also addresses those issues.

FWIW

BillAtPros avatar Apr 18 '13 16:04 BillAtPros

Have u guys used Windows Azure Diagnostics? http://msdn.microsoft.com/en-us/library/windowsazure/gg433048.aspx

gcheng avatar Apr 18 '13 17:04 gcheng

Yes. I've used Diagnostics. Unfortunately it doesn't support Azure table storage. And I think Windows Azure Diagnostics is not supported by the Windows Azure Toolkit for Eclipse.

JMayrbaeurl avatar Apr 18 '13 17:04 JMayrbaeurl

Closing out backlog items.

matt-gibbs avatar Jul 29 '14 21:07 matt-gibbs