Created
January 12, 2013 16:33
-
-
Save masterzen/4519098 to your computer and use it in GitHub Desktop.
10 commandments of logging - code extracts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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