Name: Logging
Summary: Anything related to logging - framework, guidelines, hints
Scope: Engine
Current Goal: Maintenance
Phase: Maintenance
Curator: Immortius
Related:
I've just done review of the logging in Terasology, and made the following changes:
For IntelliJ users I suggest setting up a live template that looks like this
Then you can insert the line with ctrl+j, and it will automatically use the right class name.
Parameterized logging looks like this:
All error logging in response to an exception should include the exception as well
Some general guidelines on the logging levels:
Summary: Anything related to logging - framework, guidelines, hints
Scope: Engine
Current Goal: Maintenance
Phase: Maintenance
Curator: Immortius
Related:
I've just done review of the logging in Terasology, and made the following changes:
- Switched from using Java logging directly, to using slf4j (Simply Logging Framework for Java). This has a nicer API, and allows us to switch to a different logging implementation easily if desired.
- Checked and changed the log level of the log statements. Many things have be switched from info to debug level, to reduce log spam.
- Fixed a number of error log statements that weren't including the exception causing them
Code:
private static final Logger logger = LoggerFactory.getLogger(TerasologyEngine.class);
Code:
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger($CLASS$.class);
Parameterized logging looks like this:
Code:
logger.info("Found a {} under a {} wearing a {}", cat, mat, hat);
Code:
logger.error("Error opening file '{}'", filename, exception);
- Error should be used for anything fatal, or anything that needs to be looked at promptly. Broken assets, broken prefabs, unexpected exceptions.
- Warnings are for things that won't hurt, but still need to be looked at. Missing assets, entities using missing components, exceptions that are semi-expected.
- Info is for major lifecycle events and generally useful information to log, opengl capabilities.
- Debug is for logging for development and debugging purposes. It should be focused on lifecycle events once more -not something that happens in inner loops or otherwise extremely frequently.
- Trace is for development and debugging purposes, but at a level that is getting too detailed for general debugging. Trace statements should generally be temporary, and removed once there is no immediate need for them - but using trace level means they will be turned off at least if you forget to remove them.