Search in sources :

Example 41 with LogManager

use of java.util.logging.LogManager in project Payara by payara.

the class PayaraNotificationFileHandler method evaluateFileName.

@Override
protected String evaluateFileName() {
    String cname = getClass().getName();
    LogManager manager = LogManager.getLogManager();
    logFileProperty = manager.getProperty(cname + ".file");
    if (logFileProperty == null || logFileProperty.trim().equals("")) {
        logFileProperty = env.getInstanceRoot().getAbsolutePath() + File.separator + LOGS_DIR + File.separator + NOTIFICATION_FILENAME;
    }
    return TranslatedConfigView.expandValue(logFileProperty);
}
Also used : LogManager(java.util.logging.LogManager)

Example 42 with LogManager

use of java.util.logging.LogManager in project Payara by payara.

the class GFFileHandler method configureUniformLogFormatter.

private void configureUniformLogFormatter(String excludeFields, boolean multiLineMode) {
    LogManager manager = LogManager.getLogManager();
    String cname = getClass().getName();
    // this loop is used for UFL formatter
    UniformLogFormatter formatterClass;
    // set the formatter
    if (agent != null) {
        formatterClass = new UniformLogFormatter(new AgentFormatterDelegate(agent), excludeFields);
        setFormatter(formatterClass);
    } else {
        formatterClass = new UniformLogFormatter(excludeFields);
        setFormatter(formatterClass);
    }
    formatterClass.setMultiLineMode(multiLineMode);
    formatterClass.setLogEventBroadcaster(this);
    formatterClass.noAnsi();
    String recordBeginMarker = manager.getProperty(cname + ".logFormatBeginMarker");
    if (recordBeginMarker == null || ("").equals(recordBeginMarker)) {
        recordBeginMarker = RECORD_BEGIN_MARKER;
    }
    String recordEndMarker = manager.getProperty(cname + ".logFormatEndMarker");
    if (recordEndMarker == null || ("").equals(recordEndMarker)) {
        recordEndMarker = RECORD_END_MARKER;
    }
    String recordFieldSeparator = manager.getProperty(cname + ".logFormatFieldSeparator");
    if (recordFieldSeparator == null || ("").equals(recordFieldSeparator) || recordFieldSeparator.length() > 1) {
        recordFieldSeparator = RECORD_FIELD_SEPARATOR;
    }
    String recordDateFormat = manager.getProperty(cname + ".logFormatDateFormat");
    if (recordDateFormat != null && !("").equals(recordDateFormat)) {
        SimpleDateFormat sdf = new SimpleDateFormat(recordDateFormat);
        try {
            sdf.format(new Date());
        } catch (Exception e) {
            recordDateFormat = RECORD_DATE_FORMAT;
        }
    } else {
        recordDateFormat = RECORD_DATE_FORMAT;
    }
    formatterClass.setRecordBeginMarker(recordBeginMarker);
    formatterClass.setRecordEndMarker(recordEndMarker);
    formatterClass.setRecordDateFormat(recordDateFormat);
    formatterClass.setRecordFieldSeparator(recordFieldSeparator);
}
Also used : LogManager(java.util.logging.LogManager) AgentFormatterDelegate(com.sun.enterprise.v3.logging.AgentFormatterDelegate) SimpleDateFormat(java.text.SimpleDateFormat) ParseException(java.text.ParseException)

Example 43 with LogManager

use of java.util.logging.LogManager in project Payara by payara.

the class GFFileHandler method evaluateFileName.

protected String evaluateFileName() {
    String cname = getClass().getName();
    LogManager manager = LogManager.getLogManager();
    logFileProperty = manager.getProperty(cname + ".file");
    if (logFileProperty == null || logFileProperty.trim().equals("")) {
        logFileProperty = env.getInstanceRoot().getAbsolutePath() + File.separator + LOGS_DIR + File.separator + LOG_FILE_NAME;
    }
    return TranslatedConfigView.expandConfigValue(logFileProperty);
}
Also used : LogManager(java.util.logging.LogManager)

Example 44 with LogManager

use of java.util.logging.LogManager in project Payara by payara.

the class LogDomains method getLogger.

/**
 * Returns initialized logger. If the resourceBundleLoader is not null,
 * tries to find and load the LogStrings.properties.
 *
 * @param clazz
 * @param namePrefix
 * @param resourceBundleLoader
 * @return
 */
public static Logger getLogger(final Class clazz, final String namePrefix, final ClassLoader resourceBundleLoader) {
    final String loggerName = getLoggerName(clazz, namePrefix);
    final LogManager logManager = LogManager.getLogManager();
    final Logger cachedLogger = logManager.getLogger(loggerName);
    if (cachedLogger != null) {
        return cachedLogger;
    }
    final String rbName = getResourceBundleNameForDomainRoot(namePrefix);
    final ResourceBundle resourceBundle;
    if (resourceBundleLoader == null) {
        resourceBundle = null;
    } else {
        resourceBundle = getResourceBundle(rbName, clazz, resourceBundleLoader);
    }
    // we should only add a logger of the same name at time.
    final Logger cLogger = new LogDomainsLogger(loggerName, resourceBundle);
    // We must not return an orphan logger (the one we just created) if
    // a race condition has already created one
    boolean added = logManager.addLogger(cLogger);
    if (added) {
        return cLogger;
    }
    // Another thread was faster
    return logManager.getLogger(cLogger.getName());
}
Also used : ResourceBundle(java.util.ResourceBundle) Logger(java.util.logging.Logger) LogManager(java.util.logging.LogManager)

Example 45 with LogManager

use of java.util.logging.LogManager in project beam by apache.

the class DataflowWorkerHarnessHelper method initializeLogging.

@SuppressWarnings("Slf4jIllegalPassedClass")
public static void initializeLogging(Class<?> workerHarnessClass) {
    /* Set up exception handling tied to the workerHarnessClass. */
    Thread.setDefaultUncaughtExceptionHandler(new WorkerUncaughtExceptionHandler(LoggerFactory.getLogger(workerHarnessClass)));
    // Reset the global log manager, get the root logger and remove the default log handlers.
    LogManager logManager = LogManager.getLogManager();
    logManager.reset();
    java.util.logging.Logger rootLogger = logManager.getLogger(ROOT_LOGGER_NAME);
    for (Handler handler : rootLogger.getHandlers()) {
        rootLogger.removeHandler(handler);
    }
    DataflowWorkerLoggingInitializer.initialize();
}
Also used : Handler(java.util.logging.Handler) LogManager(java.util.logging.LogManager)

Aggregations

LogManager (java.util.logging.LogManager)45 Logger (java.util.logging.Logger)19 Handler (java.util.logging.Handler)9 IOException (java.io.IOException)7 ClassLoaderLogManager (org.apache.juli.ClassLoaderLogManager)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 LifecycleException (org.apache.catalina.LifecycleException)6 ConsoleHandler (java.util.logging.ConsoleHandler)4 Level (java.util.logging.Level)4 FileNotFoundException (java.io.FileNotFoundException)3 LifecycleState (org.apache.catalina.LifecycleState)3 Server (org.apache.catalina.Server)3 AgentFormatterDelegate (com.sun.enterprise.v3.logging.AgentFormatterDelegate)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Properties (java.util.Properties)2 Formatter (java.util.logging.Formatter)2 AfterClass (org.junit.AfterClass)2