Skip to content

Instantly share code, notes, and snippets.

@masterzen
Created January 12, 2013 16:33
Show Gist options
  • Save masterzen/4519098 to your computer and use it in GitHub Desktop.
Save masterzen/4519098 to your computer and use it in GitHub Desktop.
10 commandments of logging - code extracts
class UserRequest {
...
public void execute(int userid) {
MDC.put("user", userid);
... all logged message now will display the user=<userid> for this thread context ...
// user request processing is now finished, no need to log our current user
MDC.remote("user");
}
}
public void storeUserRank(int userId, int rank, String game) {
try {
//... deal database ...
} catch(DatabaseException de) {
throw new RankingException("Can't store ranking for user "+userId+" in game "+ game + " because " + de.getMessage() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment