Kirk Rader  1.0-SNAPSHOT
Static Public Member Functions | Static Package Functions | Private Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
us.rader.logging.statuscodes.Log Class Reference

Logging utilities. More...

Static Public Member Functions

static void debug (final Properties logMessages, final Logger logger, final String key)
 Write the specified message to the given Logger. More...
 
static void debug (final Properties logMessages, final Logger logger, final String key, final Throwable throwable)
 Write the specified message to the given Logger. More...
 
static void error (final Properties logMessages, final Logger logger, final String key)
 Write the specified message to the given Logger. More...
 
static void error (final Properties logMessages, final Logger logger, final String key, final Throwable throwable)
 Write the specified message to the given Logger. More...
 
static void info (final Properties logMessages, final Logger logger, final String key)
 Write the specified message to the given Logger. More...
 
static void info (final Properties logMessages, final Logger logger, final String key, final Throwable throwable)
 Write the specified message to the given Logger. More...
 
static Properties loadLogMessages (final ClassLoader classLoader, final String name) throws IOException
 
static void trace (final Properties logMessages, final Logger logger, final String key)
 Write the specified message to the given Logger. More...
 
static void trace (final Properties logMessages, final Logger logger, final String key, final Throwable throwable)
 Write the specified message to the given Logger. More...
 
static void warn (final Properties logMessages, final Logger logger, final String key)
 Write the specified message to the given Logger. More...
 
static void warn (final Properties logMessages, final Logger logger, final String key, final Throwable throwable)
 Write the specified message to the given Logger. More...
 

Static Package Functions

 [static initializer]
 

Private Member Functions

 Log ()
 Hide constructor for utility class. More...
 

Static Private Member Functions

static StackTraceElement getCallerFrame ()
 Return the first stack frame that is neither Thread nor this class. More...
 
static String getMessage (final Properties logMessages, final String key)
 

Static Private Attributes

static Logger logger
 Debug logging / tracing. More...
 

Detailed Description

Logging utilities.

Definition at line 29 of file Log.java.

Constructor & Destructor Documentation

◆ Log()

us.rader.logging.statuscodes.Log.Log ( )
private

Hide constructor for utility class.

Definition at line 45 of file Log.java.

45  {
46 
47  // hidden constructor for utility class
48 
49  }

Member Function Documentation

◆ [static initializer]()

us.rader.logging.statuscodes.Log.[static initializer] ( )
staticpackage

◆ debug() [1/2]

static void us.rader.logging.statuscodes.Log.debug ( final Properties  logMessages,
final Logger  logger,
final String  key 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
keyThe logMessages key for the message to log.

Definition at line 63 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

Referenced by us.rader.logging.statuscodes.test.LogTest.debugValidKeyTest(), and us.rader.logging.statuscodes.test.LogTest.debugValidKeyThrowableTest().

63  {
64 
65  final String message = getMessage(logMessages, key);
66  logger.debug(message);
67 
68  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

◆ debug() [2/2]

static void us.rader.logging.statuscodes.Log.debug ( final Properties  logMessages,
final Logger  logger,
final String  key,
final Throwable  throwable 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
throwableThrowable object whose stack trace should be included in the log entry
keyThe logMessages key for the message to log.

Definition at line 86 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

87  {
88 
89  logger.debug(getMessage(logMessages, key), throwable);
90 
91  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

◆ error() [1/2]

static void us.rader.logging.statuscodes.Log.error ( final Properties  logMessages,
final Logger  logger,
final String  key 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
keyThe logMessages key for the message to log.

Definition at line 105 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

Referenced by us.rader.logging.statuscodes.test.LogTest.errorInvalidKeyTest(), us.rader.logging.statuscodes.test.LogTest.errorValidKeyTest(), and us.rader.logging.statuscodes.test.LogTest.errorValidKeyThrowableTest().

105  {
106 
107  final String message = getMessage(logMessages, key);
108  logger.error(message);
109 
110  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

◆ error() [2/2]

static void us.rader.logging.statuscodes.Log.error ( final Properties  logMessages,
final Logger  logger,
final String  key,
final Throwable  throwable 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
throwableThrowable object whose stack trace should be included in the log entry
keyThe logMessages key for the message to log.

Definition at line 128 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

129  {
130 
131  logger.error(getMessage(logMessages, key), throwable);
132 
133  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

◆ getCallerFrame()

static StackTraceElement us.rader.logging.statuscodes.Log.getCallerFrame ( )
staticprivate

Return the first stack frame that is neither Thread nor this class.

Skips Thread because the top frame is always Thread.getCurrentThread().

Returns
The stack from of the caller of one of the logging utility functions.

Definition at line 310 of file Log.java.

Referenced by us.rader.logging.statuscodes.Log.getMessage().

310  {
311 
312  final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
313 
314  try {
315 
316  for (final StackTraceElement stackFrame : stackTrace) {
317 
318  final String className = stackFrame.getClassName();
319  final Class<?> cls = Log.class.getClassLoader().loadClass(className);
320 
321  if (!(Log.class.equals(cls) || Thread.class.equals(cls))) {
322 
323  return stackFrame;
324 
325  }
326 
327  }
328 
329  } catch (final ClassNotFoundException e) {
330 
331  // impossible situation unless JVM is broken so this block will
332  // never be covered
333  throw new IllegalStateException(e);
334 
335  }
336 
337  // can only get here if a method of this classes were to try to log
338  // using this class, so this line will never be covered
339  throw new IllegalStateException("no caller stack frame found");
340 
341  }
Log()
Hide constructor for utility class.
Definition: Log.java:45

◆ getMessage()

static String us.rader.logging.statuscodes.Log.getMessage ( final Properties  logMessages,
final String  key 
)
staticprivate
Parameters
logMessagesThe log messages properties
keyThe log message key
Returns
The message string

Definition at line 352 of file Log.java.

References us.rader.logging.statuscodes.Log.getCallerFrame().

Referenced by us.rader.logging.statuscodes.Log.debug(), us.rader.logging.statuscodes.Log.error(), us.rader.logging.statuscodes.Log.info(), us.rader.logging.statuscodes.Log.trace(), and us.rader.logging.statuscodes.Log.warn().

352  {
353 
354  String message = logMessages.getProperty(key);
355 
356  if (message == null) {
357 
358  message = String.format("Undefined log message key \"%s\"", key);
359  // log the invalid key as an error
360  logger.error(message);
361 
362  }
363 
364  final StackTraceElement stackFrame = getCallerFrame();
365  return stackFrame.getClassName() + " " + stackFrame.getMethodName() + " " + message;
366 
367  }
static StackTraceElement getCallerFrame()
Return the first stack frame that is neither Thread nor this class.
Definition: Log.java:310
static Logger logger
Debug logging / tracing.
Definition: Log.java:34

◆ info() [1/2]

static void us.rader.logging.statuscodes.Log.info ( final Properties  logMessages,
final Logger  logger,
final String  key 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
keyThe logMessages key for the message to log.

Definition at line 147 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

Referenced by us.rader.logging.statuscodes.test.LogTest.infoValidKeyTest(), us.rader.logging.statuscodes.test.LogTest.infoValidKeyThrowableTest(), and us.rader.logging.demo.Demo.main().

147  {
148 
149  final String message = getMessage(logMessages, key);
150  logger.info(message);
151 
152  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

◆ info() [2/2]

static void us.rader.logging.statuscodes.Log.info ( final Properties  logMessages,
final Logger  logger,
final String  key,
final Throwable  throwable 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
throwableThrowable object whose stack trace should be included in the log entry
keyThe logMessages key for the message to log.

Definition at line 170 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

171  {
172 
173  logger.info(getMessage(logMessages, key), throwable);
174 
175  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

◆ loadLogMessages()

static Properties us.rader.logging.statuscodes.Log.loadLogMessages ( final ClassLoader  classLoader,
final String  name 
) throws IOException
static
Parameters
classLoaderThe ClassLoader from which to load the log messages resource.
nameThe name of the log messages resource, relative to the given ClassLoader.
Returns
Log messages loaded from a resource.
Exceptions
IOExceptionThrown if an error occurs loading the log messages resource

Definition at line 191 of file Log.java.

Referenced by us.rader.logging.statuscodes.test.LogTest.debugValidKeyTest(), us.rader.logging.statuscodes.test.LogTest.debugValidKeyThrowableTest(), us.rader.logging.statuscodes.test.LogTest.errorInvalidKeyTest(), us.rader.logging.statuscodes.test.LogTest.errorValidKeyTest(), us.rader.logging.statuscodes.test.LogTest.errorValidKeyThrowableTest(), us.rader.logging.statuscodes.test.LogTest.infoValidKeyTest(), us.rader.logging.statuscodes.test.LogTest.infoValidKeyThrowableTest(), us.rader.logging.statuscodes.test.LogTest.loadLogMessagesTest(), us.rader.logging.demo.Demo.main(), us.rader.logging.statuscodes.test.LogTest.traceValidKeyTest(), us.rader.logging.statuscodes.test.LogTest.traceValidKeyThrowableTest(), us.rader.logging.statuscodes.test.LogTest.warnValidKeyTest(), and us.rader.logging.statuscodes.test.LogTest.warnValidKeyThrowableTest().

191  {
192 
193  final Properties properties = new Properties();
194 
195  // suppress try-with-resources warning because
196  // getResourceAsStream(String) may return `null`
197  @SuppressWarnings("resource")
198  final InputStream stream = classLoader.getResourceAsStream(name);
199 
200  if (stream != null) {
201 
202  try {
203 
204  properties.load(stream);
205 
206  } finally {
207 
208  stream.close();
209 
210  }
211  }
212 
213  return properties;
214 
215  }

◆ trace() [1/2]

static void us.rader.logging.statuscodes.Log.trace ( final Properties  logMessages,
final Logger  logger,
final String  key 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
keyThe logMessages key for the message to log.

Definition at line 229 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

Referenced by us.rader.logging.statuscodes.test.LogTest.traceValidKeyTest(), and us.rader.logging.statuscodes.test.LogTest.traceValidKeyThrowableTest().

229  {
230 
231  final String message = getMessage(logMessages, key);
232  logger.trace(message);
233 
234  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

◆ trace() [2/2]

static void us.rader.logging.statuscodes.Log.trace ( final Properties  logMessages,
final Logger  logger,
final String  key,
final Throwable  throwable 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
throwableThrowable object whose stack trace should be included in the log entry
keyThe logMessages key for the message to log.

Definition at line 252 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

253  {
254 
255  logger.trace(getMessage(logMessages, key), throwable);
256 
257  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

◆ warn() [1/2]

static void us.rader.logging.statuscodes.Log.warn ( final Properties  logMessages,
final Logger  logger,
final String  key 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
keyThe logMessages key for the message to log.

Definition at line 271 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

Referenced by us.rader.logging.statuscodes.test.LogTest.warnValidKeyTest(), and us.rader.logging.statuscodes.test.LogTest.warnValidKeyThrowableTest().

271  {
272 
273  final String message = getMessage(logMessages, key);
274  logger.warn(message);
275 
276  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

◆ warn() [2/2]

static void us.rader.logging.statuscodes.Log.warn ( final Properties  logMessages,
final Logger  logger,
final String  key,
final Throwable  throwable 
)
static

Write the specified message to the given Logger.

Parameters
logMessagesThe Properties containing the log messages
loggerThe Logger
throwableThrowable object whose stack trace should be included in the log entry
keyThe logMessages key for the message to log.

Definition at line 294 of file Log.java.

References us.rader.logging.statuscodes.Log.getMessage().

295  {
296 
297  logger.warn(getMessage(logMessages, key), throwable);
298 
299  }
static Logger logger
Debug logging / tracing.
Definition: Log.java:34
static String getMessage(final Properties logMessages, final String key)
Definition: Log.java:352

Member Data Documentation

◆ logger

Logger us.rader.logging.statuscodes.Log.logger
staticprivate

Debug logging / tracing.

Definition at line 34 of file Log.java.


The documentation for this class was generated from the following file: