mazz.i18n
Class LoggerLocale

java.lang.Object
  extended by mazz.i18n.LoggerLocale

public class LoggerLocale
extends java.lang.Object

A utility that provides a locale that you can use for your loggers. Sometimes, you want your log messages to be logged in one locale while your user interfaces use another locale. For example, a customer may be running in a German locale, however, the team that supports the software may be located in France and only speaks and reads French. Therefore, they will want to see the logs dumped in French so they can read the logs and help decipher problems that their German customer is having.

This class provides a method (getLogLocale())to give you the locale that your log messages should be logged with. It may or may not be different than the JVM's default locale.

To define a separate log locale, this class looks for a system property called i18nlog.log-locale. It must be in the form of "language_country_variant" where country and variant are optional. For example, the system property can be "it", "en_US" or "fr_FR_EURO".

If you want the log locale to be the same as the default VM locale, set the system property i18nlog.log-locale-is-default to true. This will be ignored if the i18nlog.log-locale system property is set.

If neither system property is set, the log locale is set to Locale.ENGLISH.

You can also programatically set the locale via the methods setLogLocale(Locale) or setLogLocale(String).

This utility is a singleton. If you change the system properties during runtime and wish for this singleton to pick up the change (and thus change its log locale value), you must call reset() after the change in system properties is made. It is preferrable to call one of the setter methods to affect a change rather that using the system properties.

Version:
$Revision: 1.1 $
Author:
John Mazzitelli
See Also:
Locale

Field Summary
static java.lang.String LOG_LOCALE_IS_DEFAULT_SYSTEM_PROPERTY
          If this system property is set to true, the log locale will be set to the same as the default JVM locale.
static java.lang.String LOG_LOCALE_SYSTEM_PROPERTY
          The name of the system property that contains the log locale.
 
Constructor Summary
LoggerLocale()
           
 
Method Summary
static java.util.Locale getLogLocale()
          If the log locale has not been set yet, this will examines the system properties LOG_LOCALE_SYSTEM_PROPERTY and LOG_LOCALE_IS_DEFAULT_SYSTEM_PROPERTY to determine what the log locale should be.
static void reset()
          Resets what this class thinks should be the log locale.
static void setLogLocale(java.util.Locale locale)
          This method allows you to explicitly define what locale all loggers should use when logging messages.
static void setLogLocale(java.lang.String locale_str)
          Parses the locale string, which must be in the form of "language_country_variant" where country and variant are optional, and returns that locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_LOCALE_SYSTEM_PROPERTY

public static final java.lang.String LOG_LOCALE_SYSTEM_PROPERTY
The name of the system property that contains the log locale.

See Also:
Constant Field Values

LOG_LOCALE_IS_DEFAULT_SYSTEM_PROPERTY

public static final java.lang.String LOG_LOCALE_IS_DEFAULT_SYSTEM_PROPERTY
If this system property is set to true, the log locale will be set to the same as the default JVM locale.

See Also:
Constant Field Values
Constructor Detail

LoggerLocale

public LoggerLocale()
Method Detail

getLogLocale

public static java.util.Locale getLogLocale()
If the log locale has not been set yet, this will examines the system properties LOG_LOCALE_SYSTEM_PROPERTY and LOG_LOCALE_IS_DEFAULT_SYSTEM_PROPERTY to determine what the log locale should be.

Returns:
the log locale to be used by loggers

setLogLocale

public static void setLogLocale(java.util.Locale locale)
This method allows you to explicitly define what locale all loggers should use when logging messages.

Parameters:
locale - the new locale

setLogLocale

public static void setLogLocale(java.lang.String locale_str)
Parses the locale string, which must be in the form of "language_country_variant" where country and variant are optional, and returns that locale. If locale_str is null, then Locale.ENGLISH is returned. If you want the default VM to be used as the new log locale, call setLogLocale(Locale.getDefault()).

Parameters:
locale_str - the locale string in the form of "language_country_variant" or null

reset

public static void reset()
Resets what this class thinks should be the log locale. Call this if you change the system properties and want this class to re-read those system properties to determine the new log locale. Or call this method if you want to undo any changes made programatically via the setter methods and want to return to the locale that is specified by the system properties.



Copyright © 2006 John J. Mazzitelli All Rights Reserved. Licensed under LGPL