List of usage examples for java.util.logging LogRecord getLoggerName
public String getLoggerName()
From source file:ductive.log.JDKToCommonsHandler.java
@Override public void publish(LogRecord record) { String name = record.getLoggerName(); Log log = logs.get(name);// w w w . j av a2 s .co m if (log == null) logs.put(name, log = LogFactory.getLog(name)); String message = record.getMessage(); Throwable ex = record.getThrown(); Level level = record.getLevel(); if (Level.SEVERE == level) log.error(message, ex); else if (Level.WARNING == level) log.warn(message, ex); else if (Level.INFO == level) log.info(message, ex); else if (Level.CONFIG == level) log.debug(message, ex); else log.trace(message, ex); }
From source file:fr.ippon.wip.util.WIPLogging.java
private WIPLogging() { try {//from ww w . ja v a2s .c o m // FileHandler launch an exception if parent path doesn't exist, so // we make sure it exists File logDirectory = new File(HOME + "/wip"); if (!logDirectory.exists() || !logDirectory.isDirectory()) logDirectory.mkdirs(); accessFileHandler = new FileHandler("%h/wip/access.log", true); accessFileHandler.setLevel(Level.INFO); accessFileHandler.setFormatter(new SimpleFormatter()); Logger.getLogger("fr.ippon.wip.http.hc.HttpClientExecutor.AccessLog").addHandler(accessFileHandler); ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setFilter(new Filter() { public boolean isLoggable(LogRecord record) { return !record.getLoggerName().equals("fr.ippon.wip.http.hc.HttpClientExecutor.AccessLog"); } }); Logger.getLogger("fr.ippon.wip").addHandler(consoleHandler); // For HttpClient debugging // FileHandler fileHandler = new // FileHandler("%h/wip/httpclient.log", true); // fileHandler.setLevel(Level.ALL); // Logger.getLogger("org.apache.http.headers").addHandler(fileHandler); // Logger.getLogger("org.apache.http.headers").setLevel(Level.ALL); } catch (SecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:joachimeichborn.geotag.logging.LongLogFormat.java
@Override public String format(final LogRecord aRecord) { final StringBuilder sb = new StringBuilder(); sb.append(new DateTime(aRecord.getMillis()).toString()); sb.append(" [").append(aRecord.getLevel().getName().charAt(0)).append("] "); sb.append(aRecord.getMessage());//from w w w . j a v a2 s. co m sb.append(" <").append(aRecord.getLoggerName()).append(">"); sb.append(System.lineSeparator()); if (aRecord.getThrown() != null) { sb.append(ExceptionUtils.getStackTrace(aRecord.getThrown())); } return sb.toString(); }
From source file:pl.softech.learning.gwtp.simple.server.spring.RemoteLoggingHandler.java
@Override public String logOnServer(LogRecord lr) { final String strongName = getPermutationStrongName(); if (deobfuscator != null) { lr = deobfuscator.deobfuscateLogRecord(lr, strongName); }/* ww w .ja va2 s . c o m*/ try { final Logger logger = LoggerFactory.getLogger(lr.getLoggerName()); LogLevel.level(lr.getLevel()).log(logger, lr); } catch (final Exception e) { LOGGER.error("Remote logging failed", e); return "Remote logging failed, check stack trace for details."; } return null; }
From source file:at.bitfire.davdroid.log.LogcatHandler.java
@Override public void publish(LogRecord r) { String text = getFormatter().format(r); int level = r.getLevel().intValue(); int end = text.length(); for (int pos = 0; pos < end; pos += MAX_LINE_LENGTH) { String line = text.substring(pos, NumberUtils.min(pos + MAX_LINE_LENGTH, end)); if (level >= Level.SEVERE.intValue()) Log.e(r.getLoggerName(), line); else if (level >= Level.WARNING.intValue()) Log.w(r.getLoggerName(), line); else if (level >= Level.CONFIG.intValue()) Log.i(r.getLoggerName(), line); else if (level >= Level.FINER.intValue()) Log.d(r.getLoggerName(), line); else//from w w w . j av a2 s. com Log.v(r.getLoggerName(), line); } }
From source file:com.cloudbees.jenkins.support.SupportLogFormatter.java
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "DE_MIGHT_IGNORE" }, justification = "The exception wasn't thrown on our stack frame") public String format(LogRecord record) { StringBuilder builder = new StringBuilder(); builder.append(fdf.format(new Date(record.getMillis()))); builder.append(" [id=").append(record.getThreadID()).append("]"); builder.append("\t").append(record.getLevel().getName()).append("\t"); if (record.getSourceMethodName() != null) { String sourceClass;/*from w w w . j av a 2 s. co m*/ if (record.getSourceClassName() == null) { sourceClass = record.getLoggerName(); } else { sourceClass = record.getSourceClassName(); } builder.append(abbreviateClassName(sourceClass, 32)).append("#").append(record.getSourceMethodName()); } else { String sourceClass; if (record.getSourceClassName() == null) { sourceClass = record.getLoggerName(); } else { sourceClass = record.getSourceClassName(); } builder.append(abbreviateClassName(sourceClass, 40)); } builder.append(": ").append(formatMessage(record)); if (record.getThrown() != null) { try { StringWriter writer = new StringWriter(); PrintWriter out = new PrintWriter(writer); record.getThrown().printStackTrace(out); out.close(); builder.append(writer.toString()); } catch (Exception e) { // ignore } } builder.append("\n"); return builder.toString(); }
From source file:majordodo.task.BrokerTestUtils.java
@Before public void brokerTestUtilsBefore() throws Exception { // Setup exception handler Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override// w w w . j a v a2 s . c o m public void uncaughtException(Thread t, Throwable e) { System.err.println("uncaughtException from thread " + t.getName() + ": " + e); e.printStackTrace(); unhandledExceptions.add(e); } }); // Setup Logger System.out.println("Setup logger to level " + logLevel.getName()); java.util.logging.LogManager.getLogManager().reset(); ConsoleHandler ch = new ConsoleHandler(); ch.setLevel(logLevel); ch.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return "" + new java.sql.Timestamp(record.getMillis()) + " " + record.getLevel() + " [" + getThreadName(record.getThreadID()) + "<" + record.getThreadID() + ">] " + record.getLoggerName() + ": " + formatMessage(record) + "\n"; } }); java.util.logging.Logger.getLogger("").setLevel(logLevel); java.util.logging.Logger.getLogger("").addHandler(ch); // Initialize groupsMap groupsMap.clear(); groupsMap.put(userId, group); // Setup workdir Path mavenTargetDir = Paths.get("target").toAbsolutePath(); workDir = Files.createTempDirectory(mavenTargetDir, "test" + System.nanoTime()); if (startBroker) { broker = new Broker(brokerConfig, new FileCommitLog(workDir, workDir, 1024 * 1024), new TasksHeap(1000, createTaskPropertiesMapperFunction())); broker.startAsWritable(); server = new NettyChannelAcceptor(broker.getAcceptor()); server.start(); } if (startReplicatedBrokers) { zkServer = new ZKTestEnv(folderZk.getRoot().toPath()); zkServer.startBookie(); // Broker 1 broker1 = new Broker(broker1Config, new ReplicatedCommitLog(zkServer.getAddress(), zkServer.getTimeout(), zkServer.getPath(), folderSnapshots.newFolder().toPath(), BrokerHostData.formatHostdata( new BrokerHostData(broker1Host, broker1Port, "", false, null)), false), new TasksHeap(1000, createTaskPropertiesMapperFunction())); broker1.startAsWritable(); server1 = new NettyChannelAcceptor(broker1.getAcceptor(), broker1Host, broker1Port); server1.start(); // Broker 2 broker2 = new Broker(broker2Config, new ReplicatedCommitLog(zkServer.getAddress(), zkServer.getTimeout(), zkServer.getPath(), folderSnapshots.newFolder().toPath(), BrokerHostData.formatHostdata( new BrokerHostData(broker2Host, broker2Port, "", false, null)), false), new TasksHeap(1000, createTaskPropertiesMapperFunction())); broker2.start(); server2 = new NettyChannelAcceptor(broker2.getAcceptor(), broker2Host, broker2Port); server2.start(); // Broker locator brokerLocator = new ZKBrokerLocator(zkServer.getAddress(), zkServer.getTimeout(), zkServer.getPath()); } }
From source file:com.ellychou.todo.rest.service.SpringContextJerseyTest.java
/** * Retrieves {@link Handler log handler} capable of storing {@link LogRecord logged records}. * * @return log handler./*from w ww. ja va2 s . c om*/ */ private Handler getLogHandler() { if (logHandler == null) { final Integer logLevel = Integer.valueOf(getProperty(TestProperties.RECORD_LOG_LEVEL)); logHandler = new Handler() { @Override public void publish(LogRecord record) { final String loggerName = record.getLoggerName(); if (record.getLevel().intValue() >= logLevel && loggerName.startsWith("org.glassfish.jersey") && !loggerName.startsWith("org.glassfish.jersey.test")) { loggedRuntimeRecords.add(record); } } @Override public void flush() { } @Override public void close() throws SecurityException { } }; } return logHandler; }
From source file:org.diorite.impl.log.ForwardLogHandler.java
@Override public void publish(final LogRecord record) { final Logger logger = this.getLogger(record.getLoggerName()); final Throwable exception = record.getThrown(); final Level level = record.getLevel(); final String message = this.getFormatter().formatMessage(record); if (Objects.equals(level, Level.SEVERE)) { logger.error(message, exception); } else if (Objects.equals(level, Level.WARNING)) { logger.warn(message, exception); } else if (Objects.equals(level, Level.INFO)) { logger.info(message, exception); } else if (Objects.equals(level, Level.CONFIG)) { logger.debug(message, exception); } else {//from w ww . ja v a 2 s . co m logger.trace(message, exception); } }
From source file:org.dstadler.commons.logging.jdk.PatternFormatter.java
@Override public String format(LogRecord record) { Date time = new Date(record.getMillis()); String formattedTime = dateFormat.format(time); final String logMessage; if (record.getThrown() == null) { Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(), record.getSourceClassName(), record.getSourceMethodName() }; logMessage = logMessageFormat.format(log); } else {/*www .ja v a 2 s. c o m*/ String stack = getStackLayout(record.getThrown(), ""); Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(), record.getSourceClassName(), record.getSourceMethodName(), record.getThrown().getMessage(), stack }; logMessage = exceptionMessageFormat.format(log); } return logMessage; }