Localization

In cases where log messages should be localizable, class LocalisableString can be used. See Localized Output. However it is important to note that logged messages are typically targeted at a system administrator who may have a different locale to the current user. For example if the user uses English and the administrator uses French, then the Cúram default locale will be French and the log message should be written in French. In the following example, the default server locale is explicitly passed into getMessage, otherwise getMessage would return a string corresponding to the users locale rather than the Cúram server locale.

Figure 1. Localizable logging example in application code
import curam.util.resources.ProgramLocale;

// Create a localizable message
curam.util.exception.LocalisableString e =
  new LocalisableString(EXAMPLE.ID_EXAMPLE_MESSAGE);
e.arg(someIdentifier);


// WRONG! This logs the message in the current users locale,
// not that of the Cúram server.
curam.util.resources.Trace.kTopLevelLogger.info(e.getMessage());


// RIGHT: The message is logged using the Cúram server locale.
curam.util.resources.Trace.kTopLevelLogger.info(
  e.getMessage(ProgramLocale.getDefaultServerLocale()));