Tabnine Logo
Handler
Code IndexAdd Tabnine to your IDE (free)

How to use
Handler
in
java.util.logging

Best Java code snippets using java.util.logging.Handler (Showing top 20 results out of 2,835)

origin: jenkinsci/jenkins

@Override
public void setLevel(Level newLevel) throws SecurityException {
  super.setLevel(newLevel);
  Handler t = resolve();
  if(t!=null)
    t.setLevel(newLevel);
}
origin: stanfordnlp/CoreNLP

public static void setConsoleLevel(Level level) {
 // get the top Logger:
 Logger topLogger = java.util.logging.Logger.getLogger("");
 // Handler for console (reuse it if it already exists)
 Handler consoleHandler = null;
 // see if there is already a console handler
 for (Handler handler : topLogger.getHandlers()) {
  if (handler instanceof ConsoleHandler) {
   // found the console handler
   consoleHandler = handler;
   break;
  }
 }
 if (consoleHandler == null) {
  // there was no console handler found, create a new one
  consoleHandler = new ConsoleHandler();
  topLogger.addHandler(consoleHandler);
 }
 // set the console handler level:
 consoleHandler.setLevel(level);
 consoleHandler.setFormatter(new SimpleFormatter());
}
origin: jenkinsci/jenkins

public void close() throws SecurityException {
  Handler t = resolve();
  if(t!=null)
    t.close();
}
origin: GlowstoneMC/Glowstone

/**
 * Stops all console-log handlers.
 */
public void stop() {
  running = false;
  for (Handler handler : logger.getHandlers()) {
    handler.flush();
    handler.close();
  }
}
origin: geoserver/geoserver

/**
 * Construct a handler.
 *
 * @param handler The handler to copy properties from.
 * @param formatter The formatter to use.
 * @throws UnsupportedEncodingException if the encoding is not valid.
 */
public Stdout(final Handler handler, final Formatter formatter)
    throws UnsupportedEncodingException {
  super(System.out, formatter);
  setErrorManager(handler.getErrorManager());
  setFilter(handler.getFilter());
  setLevel(handler.getLevel());
  setEncoding(handler.getEncoding());
}
origin: googleapis/google-cloud-java

@Test
public void testReportFormatError() {
 expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
 expect(options.getService()).andReturn(logging);
 logging.setFlushSeverity(Severity.ERROR);
 expectLastCall().once();
 logging.setWriteSynchronicity(Synchronicity.ASYNC);
 expectLastCall().once();
 replay(options, logging);
 Formatter formatter = EasyMock.createStrictMock(Formatter.class);
 RuntimeException ex = new RuntimeException();
 ErrorManager errorManager = EasyMock.createStrictMock(ErrorManager.class);
 errorManager.error(null, ex, ErrorManager.FORMAT_FAILURE);
 expectLastCall().once();
 LogRecord record = newLogRecord(Level.FINEST, MESSAGE);
 expect(formatter.format(record)).andThrow(ex);
 replay(errorManager, formatter);
 Handler handler = new LoggingHandler(LOG_NAME, options, DEFAULT_RESOURCE);
 handler.setLevel(Level.ALL);
 handler.setErrorManager(errorManager);
 handler.setFormatter(formatter);
 handler.publish(record);
 verify(errorManager, formatter);
}
origin: googleapis/google-cloud-java

@Test
public void testPublishCustomResource() {
 expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
 expect(options.getService()).andReturn(logging);
 logging.setFlushSeverity(Severity.ERROR);
 expectLastCall().once();
 logging.setWriteSynchronicity(Synchronicity.ASYNC);
 expectLastCall().once();
 MonitoredResource resource = MonitoredResource.of("custom", ImmutableMap.<String, String>of());
 logging.write(
   ImmutableList.of(FINEST_ENTRY),
   WriteOption.logName(LOG_NAME),
   WriteOption.resource(resource),
   WriteOption.labels(BASE_SEVERITY_MAP));
 expectLastCall().once();
 replay(options, logging);
 Handler handler = new LoggingHandler(LOG_NAME, options, resource);
 handler.setLevel(Level.ALL);
 handler.setFormatter(new TestFormatter());
 handler.publish(newLogRecord(Level.FINEST, MESSAGE));
}
origin: traccar/traccar

private static void setupLogger(
    boolean console, String file, String levelString, boolean fullStackTraces, boolean rotate) {
  Logger rootLogger = Logger.getLogger("");
  for (Handler handler : rootLogger.getHandlers()) {
    rootLogger.removeHandler(handler);
  }
  Handler handler;
  if (console) {
    handler = new ConsoleHandler();
  } else {
    handler = new RollingFileHandler(file, rotate);
  }
  handler.setFormatter(new LogFormatter(fullStackTraces));
  Level level = Level.parse(levelString.toUpperCase());
  rootLogger.setLevel(level);
  handler.setLevel(level);
  handler.setFilter(record -> record != null && !record.getLoggerName().startsWith("sun"));
  rootLogger.addHandler(handler);
}
origin: googleapis/google-cloud-java

 @Test
 public void testClose() throws Exception {
  expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
  expect(options.getService()).andReturn(logging);
  logging.setFlushSeverity(Severity.ERROR);
  expectLastCall().once();
  logging.setWriteSynchronicity(Synchronicity.ASYNC);
  expectLastCall().once();
  logging.write(ImmutableList.of(FINEST_ENTRY), DEFAULT_OPTIONS);
  expectLastCall().once();
  logging.close();
  expectLastCall().once();
  replay(options, logging);
  Handler handler = new LoggingHandler(LOG_NAME, options, DEFAULT_RESOURCE);
  handler.setLevel(Level.ALL);
  handler.setFormatter(new TestFormatter());
  handler.publish(newLogRecord(Level.FINEST, MESSAGE));
  handler.close();
  handler.close();
 }
}
origin: org.postgresql/postgresql

 handlers.close();
 PARENT_LOGGER.removeHandler(handlers);
 loggerHandlerFile = null;
 handler.setFormatter(formatter);
handler.setLevel(PARENT_LOGGER.getLevel());
PARENT_LOGGER.setUseParentHandlers(false);
PARENT_LOGGER.addHandler(handler);
origin: jenkinsci/jenkins

@Override
public void setFormatter(Formatter newFormatter) throws SecurityException {
  super.setFormatter(newFormatter);
  Handler t = resolve();
  if(t!=null)
    t.setFormatter(newFormatter);
}
origin: com.twitter.common/logging

private static void setVlog(Logger logger, LogLevel logLevel) {
 final Level newLevel = logLevel.getLevel();
 logger.setLevel(newLevel);
 do {
  for (Handler handler : logger.getHandlers()) {
   Level handlerLevel = handler.getLevel();
   if (newLevel.intValue() < handlerLevel.intValue()) {
    handler.setLevel(newLevel);
   }
  }
 } while (logger.getUseParentHandlers() && (logger = logger.getParent()) != null);
}
origin: robovm/robovm

/**
 * Call target handler to flush any buffered output. Note that this doesn't
 * cause this {@code MemoryHandler} to push.
 */
@Override
public void flush() {
  target.flush();
}
origin: alibaba/Sentinel

  protected static Handler makeLogger(String logName, Logger heliumRecordLog) {
    CspFormatter formatter = new CspFormatter();
    String fileName = LogBase.getLogBaseDir() + logName;
    if (isLogNameUsePid()) {
      fileName += ".pid" + PidUtil.getPid();
    }
    Handler handler = null;
    try {
      handler = new DateFileLogHandler(fileName + ".%d", 1024 * 1024 * 200, 4, true);
      handler.setFormatter(formatter);
      handler.setEncoding(LOG_CHARSET);
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (handler != null) {
      LoggerUtils.disableOtherHandlers(heliumRecordLog, handler);
    }
    heliumRecordLog.setLevel(Level.ALL);
    return handler;
  }
}
origin: robovm/robovm

/**
 * Triggers a push action to output all buffered records to the target handler,
 * and the target handler will publish them. Then the buffer is cleared.
 */
public void push() {
  for (int i = cursor; i < size; i++) {
    if (buffer[i] != null) {
      target.publish(buffer[i]);
    }
    buffer[i] = null;
  }
  for (int i = 0; i < cursor; i++) {
    if (buffer[i] != null) {
      target.publish(buffer[i]);
    }
    buffer[i] = null;
  }
  cursor = 0;
}
origin: oracle/opengrok

private static Level getBaseLogLevel(Class<? extends Handler> handlerClass) {
  for (Handler handler : getBaseLogger().getHandlers()) {
    if (handlerClass.isInstance(handler)) {
      return handler.getLevel();
    }
  }
  return Level.OFF;
}
origin: jenkinsci/jenkins

@Override
public void setFilter(Filter newFilter) throws SecurityException {
  super.setFilter(newFilter);
  Handler t = resolve();
  if(t!=null)
    t.setFilter(newFilter);
}
origin: com.caucho/resin

/**
 * Flush the handler.
 */
public void flush()
{
 int level = getLevel().intValue();
 
 for (int i = 0; i < _handlers.length; i++) {
  Handler handler = _handlers[i];
  if (level <= handler.getLevel().intValue())
   handler.flush();
 }
}
origin: googleapis/google-cloud-java

@Test
public void testReportWriteError() {
 expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
 expect(options.getService()).andReturn(logging);
 RuntimeException ex = new RuntimeException();
 logging.setFlushSeverity(Severity.ERROR);
 expectLastCall().once();
 logging.setWriteSynchronicity(Synchronicity.ASYNC);
 expectLastCall().once();
 logging.write(ImmutableList.of(FINEST_ENTRY), DEFAULT_OPTIONS);
 expectLastCall().andStubThrow(ex);
 replay(options, logging);
 ErrorManager errorManager = EasyMock.createStrictMock(ErrorManager.class);
 errorManager.error(null, ex, ErrorManager.WRITE_FAILURE);
 expectLastCall().once();
 replay(errorManager);
 Handler handler = new LoggingHandler(LOG_NAME, options, DEFAULT_RESOURCE);
 handler.setLevel(Level.ALL);
 handler.setErrorManager(errorManager);
 handler.setFormatter(new TestFormatter());
 handler.publish(newLogRecord(Level.FINEST, MESSAGE));
 verify(errorManager);
}
origin: googleapis/google-cloud-java

@Test
public void testTraceEnhancedLogEntry() {
 expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
 expect(options.getService()).andReturn(logging);
 MonitoredResource resource = MonitoredResource.of("custom", ImmutableMap.<String, String>of());
 logging.setFlushSeverity(Severity.ERROR);
 expectLastCall().once();
 logging.setWriteSynchronicity(Synchronicity.ASYNC);
 expectLastCall().once();
 logging.write(
   ImmutableList.of(TRACE_ENTRY),
   WriteOption.logName(LOG_NAME),
   WriteOption.resource(resource),
   WriteOption.labels(BASE_SEVERITY_MAP));
 expectLastCall().once();
 replay(options, logging);
 LoggingEnhancer enhancer = new TraceLoggingEnhancer();
 TraceLoggingEnhancer.setCurrentTraceId("projects/projectId/traces/traceId");
 Handler handler =
   new LoggingHandler(LOG_NAME, options, resource, Collections.singletonList(enhancer));
 handler.setLevel(Level.ALL);
 handler.setFormatter(new TestFormatter());
 handler.publish(newLogRecord(Level.FINEST, MESSAGE));
}
java.util.loggingHandler

Javadoc

A Handler object accepts a logging request and exports the desired messages to a target, for example, a file, the console, etc. It can be disabled by setting its logging level to Level.OFF.

Most used methods

  • setLevel
    Sets the logging level of the messages logged by this handler, levels lower than this value will be
  • setFormatter
    Sets the formatter to be used by this handler.
  • close
    Closes this handler. A flush operation will be performed and all the associated resources will be fr
  • flush
    Flushes any buffered output.
  • publish
    Accepts a logging request and sends it to the the target.
  • getLevel
    Gets the logging level of this handler, records with levels lower than this value will be dropped.
  • setFilter
    Sets the filter to be used by this handler.
  • isLoggable
    Determines whether the supplied log record needs to be logged. The logging levels will be checked as
  • getFormatter
    Gets the formatter used by this handler to format the logging messages.
  • setEncoding
    Sets the character encoding used by this handler, null indicates a default encoding.
  • setErrorManager
    Sets the error manager for this handler.
  • getEncoding
    Gets the character encoding used by this handler, null for default encoding.
  • setErrorManager,
  • getEncoding,
  • getErrorManager,
  • getFilter,
  • getCustomizeInstance,
  • getDefaultInstance,
  • internalSetEncoding,
  • internalSetFormatter,
  • printInvalidPropMessage,
  • reportError

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getSystemService (Context)
  • addToBackStack (FragmentTransaction)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • Socket (java.net)
    Provides a client-side TCP socket.
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • JTable (javax.swing)
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Top 17 PhpStorm Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now