Search in sources :

Example 71 with Handler

use of java.util.logging.Handler in project heron by twitter.

the class LoggingHelper method loggerInit.

/**
   * Init java util logging
   *
   * @param level the Level of message to log
   * @param isRedirectStdOutErr whether we redirect std out&err
   * @param format the format to log
   */
public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException {
    // Set the java util logging format
    setLoggingFormat(format);
    // Configure the root logger and its handlers so that all the
    // derived loggers will inherit the properties
    Logger rootLogger = Logger.getLogger("");
    for (Handler handler : rootLogger.getHandlers()) {
        handler.setLevel(level);
    }
    rootLogger.setLevel(level);
    if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) {
        // zookeeper logging scares me. if people want this, we can patch to config-drive this
        Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING);
    }
    if (isRedirectStdOutErr) {
        // System.err to Logger, it results in an infinite loop.
        for (Handler handler : rootLogger.getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                rootLogger.removeHandler(handler);
            }
        }
        // now rebind stdout/stderr to logger
        Logger logger;
        LoggingOutputStream los;
        logger = Logger.getLogger("stdout");
        los = new LoggingOutputStream(logger, StdOutErrLevel.STDOUT);
        System.setOut(new PrintStream(los, true));
        logger = Logger.getLogger("stderr");
        los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR);
        System.setErr(new PrintStream(los, true));
    }
}
Also used : PrintStream(java.io.PrintStream) FileHandler(java.util.logging.FileHandler) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 72 with Handler

use of java.util.logging.Handler in project OpenAM by OpenRock.

the class SecureFileHandler method initializeVerifier.

/**
     * Initialize SecureLog verifier
     * @param verPass verifier password
     * @param token AM token
     */
public static void initializeVerifier(AMPassword verPass, Object token) {
    /*  Remove the relevant verifier initialization code when deploying
         *  it finally. For the timebeing it will be done in the old way
         *  of doing it in the constructor thru initializeSecurity();
         */
    try {
        setVerPassword(verPass, token);
        LogManager lmanager = LogManagerUtil.getLogManager();
        String logPath = lmanager.getProperty(LogConstants.LOG_LOCATION);
        if (!logPath.endsWith("/"))
            logPath += "/";
        LogManager manager = LogManagerUtil.getLogManager();
        Enumeration e = manager.getLoggerNames();
        while (e.hasMoreElements()) {
            String FileName = (String) e.nextElement();
            String verifierFileName = logPath + PREFIX + "ver." + FileName;
            SecureLogHelper helper = getSecureLogHelper(FileName);
            AMPassword logPassword = getLogPassword();
            // explicit auditor role in DSAME to initialize ver.
            if (helper != null) {
                helper.initializeVerifier(verifierFileName, logPassword, verPassword);
                try {
                    Debug.message(FileName + ":Trying to start the Verifier Thread");
                    Logger logger = (com.sun.identity.log.Logger) Logger.getLogger(FileName);
                    Handler[] handlers = logger.getHandlers();
                    ((com.sun.identity.log.handlers.SecureFileHandler) handlers[0]).startVerifierThread();
                    Debug.message(FileName + ":Started Log Verifier thread");
                } catch (Exception ex) {
                    Debug.error(FileName + ":Unable to start Verifier Thread", ex);
                // throw custom exception
                }
            }
            verificationInitialized = true;
        }
    } catch (Exception e) {
        Debug.error("Error initializing Verification", e);
    }
}
Also used : Enumeration(java.util.Enumeration) Handler(java.util.logging.Handler) Logger(com.sun.identity.log.Logger) NullLocationException(com.iplanet.log.NullLocationException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AMPassword(com.sun.identity.security.keystore.AMPassword) LogManager(java.util.logging.LogManager) SecureLogHelper(com.sun.identity.log.secure.SecureLogHelper)

Example 73 with Handler

use of java.util.logging.Handler in project mysql_perf_analyzer by yahoo.

the class MyPerfContext method configureLogging.

private void configureLogging() {
    Logger logger = Logger.getLogger("");
    try {
        logger.setLevel(Level.parse(getLogLevel()));
    } catch (Exception ex) {
        logger.setLevel(Level.INFO);
    }
    try {
        for (Handler h : logger.getHandlers()) {
            if (h instanceof java.util.logging.ConsoleHandler)
                h.setLevel(Level.SEVERE);
        }
        String logRoot = System.getProperty("logPath", ".");
        java.util.logging.FileHandler fileHandler = new java.util.logging.FileHandler(logRoot + File.separatorChar + getLogPath(), this.logFileSize, this.logFileCount);
        fileHandler.setLevel(logger.getLevel());
        fileHandler.setFormatter(new SimpleFormatter());
        logger.addHandler(fileHandler);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger)

Example 74 with Handler

use of java.util.logging.Handler in project ACS by ACS-Community.

the class CommandCenter method main.

public static void main(String[] args) {
    for (Handler h : Logger.getLogger("").getHandlers()) {
        if (h instanceof ConsoleHandler) {
            h.setFormatter(new Formatter() {

                DateFormat df = new SimpleDateFormat("HH:mm:ss ");

                @Override
                public String format(LogRecord record) {
                    String s = df.format(new Date(record.getMillis()));
                    s += record.getMessage() + "\n";
                    return s;
                }
            });
        }
    }
    // --- parse the command line
    StartupOptions startupOptions = new StartupOptions();
    for (int i = 0; i < args.length; i++) {
        if (i == 0 && equalsOneOf(args[i], new String[] { "-h", "-help", "--help" })) {
            printUsage(System.out);
            return;
        }
        try {
            if (equalsOneOf(args[i], new String[] { "-r", "-retrieve", "--retrieve" })) {
                startupOptions.project = new File(args[++i]);
                continue;
            }
            if (equalsOneOf(args[i], new String[] { "-g", "-geometry", "--geometry" })) {
                StringTokenizer toky = new StringTokenizer(args[++i], "x+");
                int w = Integer.parseInt(toky.nextToken());
                int h = Integer.parseInt(toky.nextToken());
                int x = Integer.parseInt(toky.nextToken());
                int y = Integer.parseInt(toky.nextToken());
                startupOptions.geometry = new Rectangle(x, y, w, h);
                continue;
            }
            if (equalsOneOf(args[i], new String[] { "-x", "-noexit", "--noexit" })) {
                startupOptions.doExitOnClose = false;
                continue;
            }
            if (equalsOneOf(args[i], new String[] { "-useNativeSSH", "--useNativeSSH" })) {
                log.warning("command line option '-useNativeSSH' no longer supported.");
                continue;
            }
            if (equalsOneOf(args[i], new String[] { "-killNativeSSH", "--killNativeSSH" })) {
                log.warning("command line option '-killNativeSSH' no longer supported.");
                continue;
            }
            // msc (Oct 24, 2005): stand-alone argument should be considered a project name
            // msc (Apr 28, 2006): alternatively it could be a manager location
            String standalone = args[i];
            if (standalone.length() > 8 && standalone.substring(0, 8).equalsIgnoreCase("corbaloc")) {
                startupOptions.manager = standalone;
                continue;
            }
            String mgrArg = MiscUtils.convertShortNotationToCorbaloc(standalone);
            if (mgrArg != null) {
                startupOptions.manager = mgrArg;
                continue;
            }
            startupOptions.project = new File(standalone);
        } catch (Exception exc) {
            // ArrayIndexOutOfBounds, NumberFormat, ...
            startupOptions = new StartupOptions();
            log.warning("command line argument(s) invalid, some arguments may be ignored: " + Arrays.asList(args));
            printUsage(System.err);
        }
    }
    // --- instantiate appropriate logic
    commandCenterLogic = new CommandCenterLogic();
    commandCenterLogic.prepare(startupOptions);
    if (startupOptions.project != null) {
        commandCenterLogic.loadProject(startupOptions.project);
    }
    commandCenterLogic.go();
}
Also used : CommandCenterLogic(alma.acs.commandcenter.app.CommandCenterLogic) Formatter(java.util.logging.Formatter) Rectangle(java.awt.Rectangle) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) ConsoleHandler(java.util.logging.ConsoleHandler) Date(java.util.Date) StringTokenizer(java.util.StringTokenizer) LogRecord(java.util.logging.LogRecord) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) StartupOptions(alma.acs.commandcenter.app.CommandCenterLogic.StartupOptions)

Example 75 with Handler

use of java.util.logging.Handler in project ACS by ACS-Community.

the class LocalOnlyAcsLogger method getInstance.

public static synchronized LocalOnlyAcsLogger getInstance(String namespace, Level level) {
    if (instance == null) {
        LogConfig testLogConfig = new LogConfig();
        testLogConfig.setDefaultMinLogLevelLocal(AcsLogLevel.getNativeLevel(level).getAcsLevel());
        instance = new LocalOnlyAcsLogger(namespace, testLogConfig);
        instance.setUseParentHandlers(false);
        Handler logHandler = new StdOutConsoleHandler(testLogConfig, namespace, null);
        logHandler.setFormatter(new AcsXMLLogFormatter() {

            public String format(LogRecord lr) {
                String xml = super.format(lr);
                return xml + '\n';
            }
        });
        logHandler.setLevel(level);
        instance.addHandler(logHandler);
    }
    return instance;
}
Also used : AcsXMLLogFormatter(alma.acs.logging.formatters.AcsXMLLogFormatter) LogRecord(java.util.logging.LogRecord) Handler(java.util.logging.Handler) LogConfig(alma.acs.logging.config.LogConfig)

Aggregations

Handler (java.util.logging.Handler)108 Logger (java.util.logging.Logger)35 ConsoleHandler (java.util.logging.ConsoleHandler)22 LogRecord (java.util.logging.LogRecord)16 Test (org.junit.Test)15 FileHandler (java.util.logging.FileHandler)13 IOException (java.io.IOException)9 File (java.io.File)8 Level (java.util.logging.Level)7 SimpleFormatter (java.util.logging.SimpleFormatter)7 Formatter (java.util.logging.Formatter)6 LogManager (java.util.logging.LogManager)6 PrintStream (java.io.PrintStream)5 ArrayList (java.util.ArrayList)4 SLF4JBridgeHandler (org.slf4j.bridge.SLF4JBridgeHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 StringTokenizer (java.util.StringTokenizer)3 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)2 ConsoleLogFormatter (alma.acs.logging.formatters.ConsoleLogFormatter)2 MonitoredResource (com.google.cloud.MonitoredResource)2