Skip to content

Instantly share code, notes, and snippets.

@jarrodhroberson
Last active December 19, 2015 20:09
Show Gist options
  • Save jarrodhroberson/6011652 to your computer and use it in GitHub Desktop.
Save jarrodhroberson/6011652 to your computer and use it in GitHub Desktop.
Diagnostic Properties implementation
package com.gm.gbrd.prefs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
/**
* This class is very very resource intensive and should only be used for diagnostic purposes, it should never
* be used in production code, Thread.currentThread.getStackTrace() is a very expensive operation, this was created
* only to help identify what, where and when all the various properties files in an application are being loaded.
*/
public class DiagnosticProperties extends Properties
{
private static final Logger LOG;
static
{
LOG = LoggerFactory.getLogger(DiagnosticProperties.class.getName());
}
@Override
public String getProperty(final String key)
{
return this.getProperty(key, null);
}
@Override
public String getProperty(final String key, final String defaultValue)
{
final String value = super.getProperty(key);
final StackTraceElement[] st = Thread.currentThread().getStackTrace();
final String msg = String.format("%s.%s.get(%s) = %s",st[3].getClassName(), st[3].getMethodName(), key, value);
LOG.info(msg);
return value == null ? defaultValue : value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment