# logging-tools Quick Start

## Internationalization and Localisation with JBoss Logging Tools

This quick start demonstrates the use of JBoss Logging Tools to create internationalized loggers, exceptions, and generic messages; and then provide localizations for them. This is done using a simple JAX-RS service. Translations in French(fr-FR), German(de-DE), and Swedish (sv-SE) are provided courtesy of http://translate.google.com for demonstration. My apologies if they are less than ideal translations.

The different methods of the JAX-RS service can be access using the URLs below:

- `rest/greetings/name`

  Example: rest/greetings/Harold

  Simple use of localized messages (with parameter) and logging.

  - Returns a localized "hello `name`" string where `name` is the last component of the URL.
  - Logs a localized "Hello message sent".
- `rest/greetings/locale/name`

  Example: rest/greetings/fr-FR/Harold

  Demonstrates how to obtain a message bundle for a specified locale and how to throw a localized exceptions. Note that the localized exception is a wrapper around `WebApplicationException`.

  - Returns a localized "hello `name`" string where `name` is the last component of the URL and the locale used is the one supplied in the `locale` URL.
  - Logs a localized "Hello message sent in `locale`" message using the JVM locale for the translation.
  - If the supplied locale is invalid (in this case if it contains more than 3 components, eg. `fr-FR-POSIX-FOO`) it throws a `WebApplicationException` (404) using a localizable sub-class of `WebApplicationException`.

  Note that `WebApplicationException` cannot be directly localized by JBoss Logging Tools using the `@Message` annotation due to the message parameter being ignored by `WebApplicationException` 's constructors. Cases like this can be worked around by creating a sub-class with a constructor that does deal with the message parameter.

- `rest/greetings/crashme or rest/greetings/fr-FR/crashme`

  The name "crashme' demonstrates how to throw a localized exception with another exception specified as the cause. This is a completely contrived example.

  - Attempts divide by zero, catches exception and throws localized one.
- `rest/dates/daysuntil/targetDate`

  Example: rest/dates/daysuntil/2020-12-25

  Demonstrates how to pass parameters through to the constructor of a localized exception, and how to specify an exception as a cause of a log message.

  - Attempts to turn the `targetDate` URL component into a date object using the format `dd-MM-yyyy`.
  - Returns number of days (as an integer) until that date.
  - If the `targetDate` is invalid, for example, rest/dates/daysuntil/2015-02-31:
    - Catches the `ParseException`.
    - Creates a localized `ParseException` passing values from the caught exception as parameters to it's constructor.
    - Logs a localized message with the localized exception as the cause.
    - Throws a `WebApplicationException`(400) with the text from the localized `ParseException`.