/** * Helper method the change the log-level for a given logger. * <p> * By default the system configuration is used to set the leg level (logging.[name]=LEVEL). Also the "logger" * command in the console can be used to change the log level at runtime. * * @param logger the name of the logger to change * @param level the desired log level */ public static void setLevel(String logger, Level level) { // Setup log4j Logger.getLogger(logger).setLevel(level); // Setup java.util.logging java.util.logging.Logger.getLogger(logger).setLevel(convertLog4jLevel(level)); // Clear cached "isFINE" flag to be consistently re-computed on the next access. for (Log log : all) { if (log.getName().equals(logger)) { log.fineLogging = null; } } }
private void notifyHandlers(HandledException result) { // Injector might not have run yet if (handlers == null || Boolean.TRUE.equals(frozen.get())) { return; } try { frozen.set(Boolean.TRUE); String location = computeLocation(result); for (ExceptionHandler handler : handlers) { try { handler.handle(new Incident(log.getName(), location, CallContext.getCurrent().getMDC(), result)); } catch (Exception e) { // Just log the exception - anything else might call a rather long infinite loop LOG.SEVERE(new Exception(Strings.apply( "An error occurred while calling the ExceptionHandler: %s - %s (%s)", handler, e.getMessage(), e.getClass().getName()), e)); } } } finally { frozen.set(Boolean.FALSE); } }
@Override public void execute(Output output, String... params) { if (params.length == 2) { output.apply("Setting %s to: %s", params[0], params[1]); Log.setLevel(params[0], Level.toLevel(params[1])); output.blankLine(); } else { output.line("Usage: logger <name> <LEVEL>"); output.blankLine(); output.line("Known loggers:"); output.separator(); for (Log l : Log.getAllLoggers()) { output.line(l.getName()); } output.separator(); } }