# Logging and Monitoring

## Development Phase Log Output

Many developers just use System.out.println() to print diagnostic strings to the terminal. The problem with that is that before the release, you'd have to go through all your code and make certain you removed all these println() calls. You do not want your users to see them and worry about ominous strings babbling about old development diagnostics.

Instead of println(), you use the standard Java logger from `java.util.logging`. It has many advantages for professional game development:

- You "tag" each message with a log level: Severe error, informative warning, etc.
- You can switch off printing of all messages up to certain log level with just one line of code.
  - During development, you would set the log level to fine, because you want all warnings printed.
  - For the release, you set the log level to only report severe errors, and no informative diagnostics.
- The logger string is localizable, since it contains variables. You may want to localize all errors.

So to print comments like a pro, you use the following logger syntax. The variables a, b, c, can be any printable Java object, e.g. `Vector3f a = cam.getLocation()`. They are numbered {0},{1},{2},etc for use in the string, in the order you put them in the Object array.

    private static final Logger logger = Logger.getLogger(HelloWorld.class.getName());

Replace HelloWorld by the name of the class where you are using this line.

    logger.log(Level.WARNING, "ok seriously wtf somebody check why {0} is {1} again?!",
                          new Object[]{a , b});

or

    logger.log(Level.SEVERE, "Game error: {0} must not be {1} after {2}! Please check your flux generator.",
                          new Object[]{a , b , c});

As you see in the example, you should phrase potentially "customer facing" errors in a neutral way and offer a reason and a solution. If you use WARNINGs as replacement for casual printlns, make sure you deactivate them for the release.

More details about Java log levels here.

### Switching the Logger on and off

In the release version you will deactivate the logging output to the terminal.

To deactivate the default logger, you set the log level to only report severe messages:

    Logger.getLogger(””).setLevel(Level.SEVERE);

To reactivate it:

    Logger.getLogger(””).setLevel(Level.FINE);

## jMonkeyPlatform Log Files

You find the jMonkeyPlatform log file in /dev/var/log/messages.log in the jMonkeyPlatform preferences folder. You can learn the location of the preferences folder in the “About” screen of the jMonkeyPlatform under the label Userdir.

- Windows: C:\Documents and Settings\YOUR_NAME\.jmonkeyplatform\"
- Linux: /home/YOUR_NAME/.jmonkeyplatform/"
- Mac OS: `/Users/YOUR_NAME/Library/Application Support/jmonkeyplatform/`

## Read Graphic Card Capabilites

You can read the graphic card's capabilities using the `com.jme3.renderer.Caps` class:

    Collection<Caps> caps = renderer.getCaps();
    Logger.getLogger(HelloWorld.class.getName()).log(Level.INFO, “Caps: {0}” + caps.toString());

Replace HelloWorld by the name of the class where you are using this line.

The result looks like the following example:

    Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, OpenGL20, ARBprogram, GLSL100, GLSL110, GLSL120, VertexTextureFetch, FloatTexture, TextureCompressionLATC]

This would tell you that this user's graphic card only supports OpenGL 2.0 and cannot handle newer OpenGL features.

view online version