Skip to content

Instantly share code, notes, and snippets.

@sripathikrishnan
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save sripathikrishnan/dea0f9d579dd37040430 to your computer and use it in GitHub Desktop.

Select an option

Save sripathikrishnan/dea0f9d579dd37040430 to your computer and use it in GitHub Desktop.
Possible Interface for Structured Logging in Java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.hashedin.logan.utils.$;
public class HelloStructuredLogging {
private static final Logger LOGGER = LoggerFactory.getLogger(GobblerServerHandler.class);
public static void main(String args[]) {
LOGGER.info("tweet_dispatched_to_room",
$("tweetid", "42323123112",
"twitter_handle", "@srithedabbler",
"room_name", "Twitter Test Room",
"tenant_id", "3242342432423",
"account", "HashedIn"
)
);
}
}
public static final Map<String, String> _(String ...args) {
Map<String, String> map = new HashMap<String, String>();
if ((args.length %2) != 0) {
throw new IllegalArgumentException("Mismatched keys and values");
}
for(int i=0; i<args.length-1; i+=2) {
map.put(args[i], args[i+1]);
}
return map;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment