Example usage for java.util.logging ConsoleHandler ConsoleHandler

List of usage examples for java.util.logging ConsoleHandler ConsoleHandler

Introduction

In this page you can find the example usage for java.util.logging ConsoleHandler ConsoleHandler.

Prototype

public ConsoleHandler() 

Source Link

Document

Create a ConsoleHandler for System.err .

Usage

From source file:org.hillview.utils.HillviewLogger.java

/**
 * Create a Hillview logger./*  w w w. ja v a2 s .co m*/
 * @param role      Who is doing the logging: web server, worker, test, etc.
 * @param filename  File where logs are to be written.  If null logs will be written to the
 *                  console.
 */
private HillviewLogger(String role, @Nullable String filename) {
    // Disable all default logging
    LogManager.getLogManager().reset();
    this.logger = Logger.getLogger("Hillview");
    this.machine = this.checkCommas(Utilities.getHostName());
    this.role = this.checkCommas(role);
    this.logger.setLevel(Level.INFO);

    Formatter form = new SimpleFormatter() {
        final String[] components = new String[5];
        final String newline = System.lineSeparator();
        private final DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");

        @Override
        public synchronized String format(LogRecord record) {
            this.components[0] = HillviewLogger.this.checkCommas(df.format(new Date(record.getMillis())));
            this.components[1] = HillviewLogger.this.role;
            this.components[2] = HillviewLogger.this.checkCommas(record.getLevel().toString());
            this.components[3] = HillviewLogger.this.machine;
            this.components[4] = record.getMessage();
            String result = String.join(",", components);
            return result + this.newline;
        }
    };

    Handler handler;
    if (filename != null) {
        try {
            handler = new FileHandler(filename);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        handler = new ConsoleHandler();
    }
    handler.setFormatter(form);
    logger.addHandler(handler);
    File currentDirectory = new File(new File(".").getAbsolutePath());
    this.info("Starting logger", "Working directory: {0}", currentDirectory);
}

From source file:org.silverpeas.core.test.rule.CommonAPI4Test.java

public void setLoggerLevel(Level level) {
    final ConsoleHandler handler = new ConsoleHandler();
    setLoggerHandler(handler);//w  ww . jav  a2  s  . c  o  m
    handler.setFormatter(new SimpleFormatter());
    switch (level) {
    case INFO:
        Logger.getLogger(ROOT_NAMESPACE).setLevel(java.util.logging.Level.INFO);
        handler.setLevel(java.util.logging.Level.INFO);
        break;
    case DEBUG:
        Logger.getLogger(ROOT_NAMESPACE).setLevel(java.util.logging.Level.FINE);
        handler.setLevel(java.util.logging.Level.FINE);
        break;
    case WARNING:
        Logger.getLogger(ROOT_NAMESPACE).setLevel(java.util.logging.Level.WARNING);
        handler.setLevel(java.util.logging.Level.WARNING);
        break;
    case ERROR:
        Logger.getLogger(ROOT_NAMESPACE).setLevel(java.util.logging.Level.SEVERE);
        handler.setLevel(java.util.logging.Level.SEVERE);
        break;
    }
}

From source file:com.googlecode.jgenhtml.JGenHtmlUtils.java

public static void setLogFormatter(final Logger logger) {
    logger.setUseParentHandlers(false);//from   w  w  w .  ja v a 2s  .  c o  m
    JGenHtmlLogFormatter formatter = new JGenHtmlLogFormatter();
    ConsoleHandler handler = new ConsoleHandler();
    handler.setFormatter(formatter);
    logger.addHandler(handler);
}

From source file:com.intuit.tank.proxy.Main.java

public void start() {
    try {/*  w  w  w .j  a  v  a2  s  . c  om*/
        application.startSession(this);
        logger.setUseParentHandlers(false);
        Handler ch = new ConsoleHandler();
        ch.setFormatter(new TextFormatter());
        logger.addHandler(ch);

        InetSocketAddress listen;
        try {
            listen = new InetSocketAddress("localhost", port);
        } catch (NumberFormatException nfe) {
            usage();
            return;
        }
        String proxy = "DIRECT";
        final ProxySelector ps = getProxySelector(proxy);

        DefaultHttpRequestHandler drh = new DefaultHttpRequestHandler() {
            @Override
            protected HttpClient createClient() {
                HttpClient client = super.createClient();
                client.setProxySelector(ps);
                client.setSoTimeout(20000);
                return client;
            }
        };
        ServerGroup sg = new ServerGroup();
        sg.addServer(listen);
        drh.setServerGroup(sg);
        HttpRequestHandler rh = drh;
        rh = new LoggingHttpRequestHandler(rh);

        BufferedMessageInterceptor bmi = new BufferedMessageInterceptor() {
            @Override
            public Action directResponse(RequestHeader request, MutableResponseHeader response) {
                // System.err.println(new String(request.getHeader())
                // + "+++++++++++\n" + new String(response.getHeader())
                // + "===========");
                return Action.BUFFER;
            }

            @Override
            public Action directRequest(MutableRequestHeader request) {
                // System.err.println(new String(request.getHeader())
                // + "===========");
                return Action.BUFFER;
            }
        };
        rh = new BufferingHttpRequestHandler(rh, bmi, 1024 * 1024, application);

        HttpProxyConnectionHandler hpch = new HttpProxyConnectionHandler(rh);
        SSLContextSelector cp = getSSLContextSelector();
        TargetedConnectionHandler tch = new SSLConnectionHandler(cp, true, hpch);
        tch = new LoopAvoidingTargetedConnectionHandler(sg, tch);
        hpch.setConnectHandler(tch);
        TargetedConnectionHandler socks = new SocksConnectionHandler(tch, true);
        p = new Proxy(listen, socks, null);
        p.setSocketTimeout(90000);
        p.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:uk.org.lidalia.sysoutslf4j.integration.TestSysOutOverSlf4J.java

@Test
public void juliConsoleAppenderStillLogsToConsole() throws Exception {
    OutputStream newSysErr = setUpMockSystemOutput(SystemOutput.ERR);
    SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();

    java.util.logging.Logger log = java.util.logging.Logger.getLogger("");
    for (Handler handler : log.getHandlers()) {
        log.removeHandler(handler);//from ww w . j  a  v a2  s .co m
    }
    log.addHandler(new ConsoleHandler());
    log.info("Should reach the old syserr");

    assertThat(newSysErr.toString(), containsString("INFO: Should reach the old syserr"));
}

From source file:org.freaknet.gtrends.client.GoogleTrendsClientFactory.java

private static void setLogLevel(CmdLineParser cmdLine) throws SecurityException, IllegalArgumentException {
    final Level level;
    if (cmdLine.getLogLevel() != null) {
        level = Level.parse(cmdLine.getLogLevel());
    } else {/* w  w w. j  ava 2 s.  c o  m*/
        level = Level.parse(DEFAULT_LOGGING_LEVEL);
    }
    Logger log = LogManager.getLogManager().getLogger("");

    for (Handler h : log.getHandlers()) {
        log.removeHandler(h);
    }
    Handler handler = new ConsoleHandler();
    handler.setFormatter(new LogFormatter());
    handler.setLevel(level);
    log.setUseParentHandlers(false);

    Logger defaultLog = Logger.getLogger(GoogleConfigurator.getLoggerPrefix());
    defaultLog.addHandler(handler);
    defaultLog.setLevel(level);
    defaultLog.setFilter(new Filter() {
        @Override
        public boolean isLoggable(LogRecord record) {
            if (record.getSourceClassName().startsWith(GoogleConfigurator.getLoggerPrefix())) {
                return (record.getLevel().intValue() >= level.intValue());
            }
            return false;
        }
    });
}

From source file:org.ocsoft.olivia.logger.LogStation.java

/**
 * ????./*www  .  j av a 2 s.c o  m*/
 * @return ?????
 */
@Nonnull
private ConsoleHandler createConsoleLogHandler() {
    ConsoleHandler ch = new ConsoleHandler();
    //logger??JSON??
    ch.setFormatter(new OliviaConsoleLogFormatter());
    return ch;
}

From source file:org.ensembl.healthcheck.testcase.AbstractPerlModuleBasedTestCase.java

protected void setPerlFriendlyLogFormatters() {

    Handler[] configuredHandler = logger.getHandlers();

    // It is possible that no Handler has been configured. In that case we
    // create and add one to the logger.
    ///*from   w  w  w  .j av  a  2  s.  c  o  m*/
    if (configuredHandler.length == 0) {
        logger.addHandler(new ConsoleHandler());
        configuredHandler = logger.getHandlers();
    }

    // Now there is at least one configuredHandler.
    //
    for (Handler h : configuredHandler) {

        savedFormatter.put(h, h.getFormatter());
        h.setFormatter(perlLogMessagesFormatter);

        if (h.getFormatter() != perlLogMessagesFormatter) {
            throw new RuntimeException("Unable to set Formatter!");
        }
    }
}

From source file:lineage.LineageEngine.java

public static void main(String[] args) {
    Options options = new Options();
    // Commands//www  .ja v a2  s . com
    options.addOption("build", false, "Construct the sample lineage trees");

    // Input/Output/Display
    options.addOption("i", true, "Input file path [required]");
    options.addOption("o", true, "Output file path (default: input file with suffix .trees.txt)");
    options.addOption("cp", false, "Input data represents cell prevalaence (CP) values");
    options.addOption("sampleProfile", false,
            "Input file contains the SSNV sample presence-absence profile (this will disable the default SSNV calling step)");
    options.addOption("n", "normal", true,
            "Normal sample column id in the list of samples, 0-based (e.g 0 is the first column) [required without -sampleProfile]");
    options.addOption("clustersFile", true, "SSNV clusters file path");
    options.addOption("s", "save", true, "Maximum number of output trees to save (default: 1)");
    options.addOption("showNetwork", "net", false, "Display the constraint network");
    options.addOption("showTree", "tree", true, "Number of top-ranking trees to display (default: 0)");

    // SSNV filtering / calling
    options.addOption("maxVAFAbsent", "absent", true,
            "Maximum VAF to robustly consider an SSNV as absent from a sample [required without -sampleProfile]");
    options.addOption("minVAFPresent", "present", true,
            "Minimum VAF to robustly consider an SSNV as present in a sample [required without -sampleProfile]");
    options.addOption("maxVAFValid", true, "Maximum allowed VAF in a sample (default: 0.6)");
    options.addOption("minProfileSupport", true,
            "Minimum number of robust SSNVs required for a group presence-absence profile to be labeled robust (default: 2)");

    // Network Construction / Tree Search
    options.addOption("minClusterSize", true,
            "Minimum size a cluster must have to be a considered a node in the network (default: 2)");
    options.addOption("minPrivateClusterSize", true,
            "Minimum size a private mutation cluster must have to be a considered a node in the network (default: 1)");
    options.addOption("minRobustNodeSupport", true,
            "Minimum number of robust SSNVs required for a node to be labeled robust during tree search: non-robust nodes can be removed from the network when no valid lineage trees are found (default: 2)");
    options.addOption("maxClusterDist", true,
            "Maximum mean VAF difference up to which two clusters can be collapsed (default: 0.2)");
    options.addOption("c", "completeNetwork", false,
            "Add all possible edges to the constraint network (default: private nodes are connected only to closest level parents; only nodes with no other parents are descendants of root)");
    options.addOption("e", true, "VAF error margin (default: 0.1)");
    options.addOption("nTreeQPCheck", true,
            "Number of top-ranking trees on which the QP consistency check is run, we have not seen this check fail in practice (default: 0, for best performance)");

    options.addOption("v", "verbose", false, "Verbose mode");
    options.addOption("h", "help", false, "Print usage");

    // display order
    ArrayList<Option> optionsList = new ArrayList<Option>();
    optionsList.add(options.getOption("build"));

    optionsList.add(options.getOption("i"));
    optionsList.add(options.getOption("o"));
    optionsList.add(options.getOption("cp"));
    optionsList.add(options.getOption("sampleProfile"));
    optionsList.add(options.getOption("n"));
    optionsList.add(options.getOption("clustersFile"));
    optionsList.add(options.getOption("s"));
    optionsList.add(options.getOption("net"));
    optionsList.add(options.getOption("tree"));
    optionsList.add(options.getOption("maxVAFAbsent"));
    optionsList.add(options.getOption("minVAFPresent"));
    optionsList.add(options.getOption("maxVAFValid"));
    optionsList.add(options.getOption("minProfileSupport"));
    optionsList.add(options.getOption("minClusterSize"));
    optionsList.add(options.getOption("minPrivateClusterSize"));
    optionsList.add(options.getOption("minRobustNodeSupport"));
    optionsList.add(options.getOption("maxClusterDist"));
    optionsList.add(options.getOption("c"));
    optionsList.add(options.getOption("e"));
    optionsList.add(options.getOption("nTreeQPCheck"));
    optionsList.add(options.getOption("v"));
    optionsList.add(options.getOption("h"));

    CommandLineParser parser = new BasicParser();
    CommandLine cmdLine = null;
    HelpFormatter hf = new HelpFormatter();
    hf.setOptionComparator(new OptionComarator<Option>(optionsList));
    try {
        cmdLine = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        hf.printHelp("lichee", options);
        System.exit(-1);
    }

    // Set-up input args
    Args params = new Args();
    if (cmdLine.hasOption("i")) {
        params.inputFileName = cmdLine.getOptionValue("i");
    } else {
        System.out.println("Required parameter: input file path [-i]");
        hf.printHelp("lichee", options);
        System.exit(-1);
    }
    if (cmdLine.hasOption("o")) {
        params.outputFileName = cmdLine.getOptionValue("o");
    } else {
        params.outputFileName = params.inputFileName + TREES_TXT_FILE_EXTENSION;
    }
    if (cmdLine.hasOption("clustersFile")) {
        params.clustersFileName = cmdLine.getOptionValue("clustersFile");
    }
    if (cmdLine.hasOption("sampleProfile")) {
        Parameters.INPUT_FORMAT = Format.SNV_WITH_PROFILE;
    }

    if (cmdLine.hasOption("n")) {
        params.normalSampleId = Integer.parseInt(cmdLine.getOptionValue("n"));
    } else if (!cmdLine.hasOption("sampleProfile")) {
        System.out.println("Required parameter: normal sample id [-n]");
        hf.printHelp("lichee", options);
        System.exit(-1);
    }
    if (cmdLine.hasOption("showTree")) {
        params.numShow = Integer.parseInt(cmdLine.getOptionValue("showTree"));
    }
    if (cmdLine.hasOption("showNetwork")) {
        params.showNetwork = true;
    }
    if (cmdLine.hasOption("s")) {
        params.numSave = Integer.parseInt(cmdLine.getOptionValue("s"));
    }

    if (cmdLine.hasOption("maxVAFAbsent")) {
        Parameters.MAX_VAF_ABSENT = Double.parseDouble(cmdLine.getOptionValue("maxVAFAbsent"));
    } else if (!cmdLine.hasOption("sampleProfile")) {
        System.out.println("Required parameter: -maxVAFAbsent");
        hf.printHelp("lichee", options);
        System.exit(-1);
    }
    if (cmdLine.hasOption("minVAFPresent")) {
        Parameters.MIN_VAF_PRESENT = Double.parseDouble(cmdLine.getOptionValue("minVAFPresent"));
    } else if (!cmdLine.hasOption("sampleProfile")) {
        System.out.println("Required parameter: -minVAFPresent");
        hf.printHelp("lichee", options);
        System.exit(-1);
    }
    if (cmdLine.hasOption("maxVAFValid")) {
        Parameters.MAX_ALLOWED_VAF = Double.parseDouble(cmdLine.getOptionValue("maxVAFValid"));
    }
    if (cmdLine.hasOption("minProfileSupport")) {
        Parameters.MIN_GROUP_PROFILE_SUPPORT = Integer.parseInt(cmdLine.getOptionValue("minProfileSupport"));
    }
    if (cmdLine.hasOption("minClusterSize")) {
        Parameters.MIN_CLUSTER_SIZE = Integer.parseInt(cmdLine.getOptionValue("minClusterSize"));
    }
    if (cmdLine.hasOption("minPrivateClusterSize")) {
        Parameters.MIN_PRIVATE_CLUSTER_SIZE = Integer.parseInt(cmdLine.getOptionValue("minPrivateClusterSize"));
    }
    if (cmdLine.hasOption("minRobustNodeSupport")) {
        Parameters.MIN_ROBUST_CLUSTER_SUPPORT = Integer
                .parseInt(cmdLine.getOptionValue("minRobustNodeSupport"));
    }
    if (cmdLine.hasOption("maxClusterDist")) {
        Parameters.MAX_COLLAPSE_CLUSTER_DIFF = Double.parseDouble(cmdLine.getOptionValue("maxClusterDist"));
    }
    if (cmdLine.hasOption("c")) {
        Parameters.ALL_EDGES = true;
    }
    if (cmdLine.hasOption("cp")) {
        Parameters.CP = true;
        Parameters.VAF_MAX = 1.0;
        Parameters.MAX_ALLOWED_VAF = 1.0;
    }
    if (cmdLine.hasOption("e")) {
        Parameters.VAF_ERROR_MARGIN = Double.parseDouble(cmdLine.getOptionValue("e"));
    }
    if (cmdLine.hasOption("nTreeQPCheck")) {
        Parameters.NUM_TREES_FOR_CONSISTENCY_CHECK = Integer.parseInt(cmdLine.getOptionValue("nTreeQPCheck"));
    }
    if (cmdLine.hasOption("h")) {
        new HelpFormatter().printHelp(" ", options);
    }
    // logger
    ConsoleHandler h = new ConsoleHandler();
    h.setFormatter(new LogFormatter());
    h.setLevel(Level.INFO);
    logger.setLevel(Level.INFO);
    if (cmdLine.hasOption("v")) {
        h.setLevel(Level.FINEST);
        logger.setLevel(Level.FINEST);
    }
    logger.addHandler(h);
    logger.setUseParentHandlers(false);

    if (cmdLine.hasOption("build")) {
        buildLineage(params);

    } else {
        new HelpFormatter().printHelp("lichee", options);
        System.exit(-1);
    }
}

From source file:net.mmberg.nadia.processor.NadiaProcessor.java

private void init() {
    init = true;/* w ww  .ja v  a2  s . co m*/
    startedOn = new Date();
    //format logging
    logger.setUseParentHandlers(false);
    CustomFormatter fmt = new CustomFormatter();
    Handler ch = new ConsoleHandler();
    ch.setFormatter(fmt);
    logger.addHandler(ch);

    logger.setLevel(Level.INFO);
}