Java Code Examples for java.util.logging.ConsoleHandler.setEncoding()

The following are Jave code examples for showing how to use setEncoding() of the java.util.logging.ConsoleHandler class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OpenCyclos   File: LoggingHandlerImpl.java   Source Code and License Vote up 7 votes
/**
 * Creates a new logger
 */
private Logger init(final Level level, final String file) {
    final LogSettings logSettings = settingsService.getLogSettings();
    final Logger logger = Logger.getAnonymousLogger();
    logger.setLevel(level);
    logger.setUseParentHandlers(false);
    try {
        final FileUnits units = logSettings.getMaxLengthPerFileUnits();
        final FileHandler fileHandler = new FileHandler(file, units.calculate(logSettings.getMaxLengthPerFile()), logSettings.getMaxFilesPerLog(), true);
        fileHandler.setFormatter(logFormatter);
        fileHandler.setEncoding(settingsService.getLocalSettings().getCharset());
        logger.addHandler(fileHandler);
    } catch (final Exception e) {
        final ConsoleHandler consoleHandler = new ConsoleHandler();
        consoleHandler.setFormatter(logFormatter);
        try {
            consoleHandler.setEncoding(settingsService.getLocalSettings().getCharset());
        } catch (final Exception e1) {
            // Just ignore
        }
        logger.addHandler(consoleHandler);
        logger.log(Level.WARNING, "Unable to create logger for file " + file);
    }
    return logger;
}
 
Example 2
Project: JFaceUtils   File: ScrollableConsole.java   Source Code and License Vote up 7 votes
protected void redirectLogging() {
	final Logger rootLogger = LoggingSupport.getRootLogger();
	for (int i = 0; i < rootLogger.getHandlers().length; i++) {
		final Handler oldHandler = rootLogger.getHandlers()[i];
		if (oldHandler instanceof ConsoleHandler) {
			final ConsoleHandler newConsoleHandler = new ConsoleHandler();
			newConsoleHandler.setLevel(oldHandler.getLevel());
			newConsoleHandler.setFilter(oldHandler.getFilter());
			if (oldHandler.getFormatter() != null) {
				newConsoleHandler.setFormatter(oldHandler.getFormatter());
			}
			if (oldHandler.getErrorManager() != null) {
				newConsoleHandler.setErrorManager(oldHandler.getErrorManager());
			}
			try {
				newConsoleHandler.setEncoding(oldHandler.getEncoding());
			}
			catch (final UnsupportedEncodingException uee) {
				throw new IllegalStateException(uee);
			}
			rootLogger.removeHandler(oldHandler);
			rootLogger.addHandler(newConsoleHandler);
		}
	}
}