Example usage for java.util.logging LogManager getLogManager

List of usage examples for java.util.logging LogManager getLogManager

Introduction

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

Prototype

public static LogManager getLogManager() 

Source Link

Document

Returns the global LogManager object.

Usage

From source file:herddb.cli.HerdDBCLI.java

public static void main(String... args) throws IOException {
    try {//from ww w . j  a  v  a  2s .  c o m
        DefaultParser parser = new DefaultParser();
        Options options = new Options();
        options.addOption("x", "url", true, "JDBC URL");
        options.addOption("u", "username", true, "JDBC Username");
        options.addOption("pwd", "password", true, "JDBC Password");
        options.addOption("q", "query", true, "Execute inline query");
        options.addOption("v", "verbose", false, "Verbose output");
        options.addOption("a", "async", false, "Use (experimental) executeBatchAsync for sending DML");
        options.addOption("s", "schema", true, "Default tablespace (SQL schema)");
        options.addOption("fi", "filter", true, "SQL filter mode: all|ddl|dml");
        options.addOption("f", "file", true, "SQL Script to execute (statement separated by 'GO' lines)");
        options.addOption("at", "autotransaction", false,
                "Execute scripts in autocommit=false mode and commit automatically");
        options.addOption("atbs", "autotransactionbatchsize", true, "Batch size for 'autotransaction' mode");
        options.addOption("g", "script", true, "Groovy Script to execute");
        options.addOption("i", "ignoreerrors", false, "Ignore SQL Errors during file execution");
        options.addOption("sc", "sqlconsole", false, "Execute SQL console in interactive mode");
        options.addOption("fmd", "mysql", false,
                "Intruct the parser that the script is coming from a MySQL Dump");
        options.addOption("rwst", "rewritestatements", false, "Rewrite all statements to use JDBC parameters");
        options.addOption("b", "backup", false, "Backup one or more tablespaces (selected with --schema)");
        options.addOption("r", "restore", false, "Restore tablespace");
        options.addOption("nl", "newleader", true, "Leader for new restored tablespace");
        options.addOption("ns", "newschema", true, "Name for new restored tablespace");
        options.addOption("tsm", "tablespacemapper", true,
                "Path to groovy script with a custom functin to map table names to tablespaces");
        options.addOption("dfs", "dumpfetchsize", true,
                "Fetch size for dump operations. Defaults to chunks of 100000 records");
        options.addOption("n", "nodeid", true, "Node id");
        options.addOption("t", "table", true, "Table name");
        options.addOption("p", "param", true, "Parameter name");
        options.addOption("val", "values", true, "Parameter values");
        options.addOption("lts", "list-tablespaces", false, "List available tablespaces");
        options.addOption("ln", "list-nodes", false, "List available nodes");
        options.addOption("sts", "show-tablespace", false,
                "Show full informations about a tablespace (needs -s option)");
        options.addOption("lt", "list-tables", false, "List tablespace tables (needs -s option)");
        options.addOption("st", "show-table", false,
                "Show full informations about a table (needs -s and -t options)");

        options.addOption("ar", "add-replica", false,
                "Add a replica to the tablespace (needs -s and -r options)");
        options.addOption("rr", "remove-replica", false,
                "Remove a replica from the tablespace (needs -s and -r options)");
        options.addOption("adt", "create-tablespace", false, "Create a tablespace (needs -ns and -nl options)");
        options.addOption("at", "alter-tablespace", false,
                "Alter a tablespace (needs -s, -param and --values options)");

        options.addOption("d", "describe", false, "Checks and describes a raw file");
        options.addOption("ft", "filetype", true,
                "Checks and describes a raw file (valid options are txlog, datapage, tablecheckpoint, indexcheckpoint, tablesmetadata");
        options.addOption("mdf", "metadatafile", true,
                "Tables metadata file, required for 'datapage' filetype");
        options.addOption("tsui", "tablespaceuuid", true, "Tablespace UUID, used for describing raw files");

        org.apache.commons.cli.CommandLine commandLine;
        try {
            commandLine = parser.parse(options, args);
        } catch (ParseException error) {
            println("Syntax error: " + error);
            failAndPrintHelp(options);
            return;
        }
        if (args.length == 0) {
            failAndPrintHelp(options);
            return;
        }

        String schema = commandLine.getOptionValue("schema", TableSpace.DEFAULT);
        String tablespaceuuid = commandLine.getOptionValue("tablespaceuuid", "");
        final boolean verbose = commandLine.hasOption("verbose");
        final boolean async = commandLine.hasOption("async");
        final String filter = commandLine.getOptionValue("filter", "all");
        if (!verbose) {
            LogManager.getLogManager().reset();
        }
        String file = commandLine.getOptionValue("file", "");
        String tablesmetadatafile = commandLine.getOptionValue("metadatafile", "");
        String table = commandLine.getOptionValue("table", "");
        boolean describe = commandLine.hasOption("describe");
        String filetype = commandLine.getOptionValue("filetype", "");
        if (describe) {
            try {
                if (file.isEmpty()) {
                    throw new IllegalArgumentException("file option is required");
                }
                describeRawFile(tablespaceuuid, table, tablesmetadatafile, file, filetype);
            } catch (Exception error) {
                if (verbose) {
                    error.printStackTrace();
                } else {
                    println("error:" + error);
                }
                exitCode = 1;
            }
            return;
        }
        String url = commandLine.getOptionValue("url", "jdbc:herddb:server:localhost:7000");
        String username = commandLine.getOptionValue("username",
                ClientConfiguration.PROPERTY_CLIENT_USERNAME_DEFAULT);
        String password = commandLine.getOptionValue("password",
                ClientConfiguration.PROPERTY_CLIENT_PASSWORD_DEFAULT);
        String query = commandLine.getOptionValue("query", "");

        boolean backup = commandLine.hasOption("backup");
        boolean restore = commandLine.hasOption("restore");
        String newschema = commandLine.getOptionValue("newschema", "");
        String leader = commandLine.getOptionValue("newleader", "");
        String script = commandLine.getOptionValue("script", "");
        String tablespacemapperfile = commandLine.getOptionValue("tablespacemapper", "");
        int dumpfetchsize = Integer.parseInt(commandLine.getOptionValue("dumpfetchsize", 100000 + ""));
        final boolean ignoreerrors = commandLine.hasOption("ignoreerrors");
        boolean sqlconsole = commandLine.hasOption("sqlconsole");
        final boolean frommysqldump = commandLine.hasOption("mysql");
        final boolean rewritestatements = commandLine.hasOption("rewritestatements")
                || !tablespacemapperfile.isEmpty() || frommysqldump;
        boolean autotransaction = commandLine.hasOption("autotransaction") || frommysqldump;
        int autotransactionbatchsize = Integer
                .parseInt(commandLine.getOptionValue("autotransactionbatchsize", 100000 + ""));
        if (!autotransaction) {
            autotransactionbatchsize = 0;
        }

        String nodeId = commandLine.getOptionValue("nodeid", "");
        String param = commandLine.getOptionValue("param", "");
        String values = commandLine.getOptionValue("values", "");

        boolean listTablespaces = commandLine.hasOption("list-tablespaces");
        boolean listNodes = commandLine.hasOption("list-nodes");
        boolean showTablespace = commandLine.hasOption("show-tablespace");
        boolean listTables = commandLine.hasOption("list-tables");
        boolean showTable = commandLine.hasOption("show-table");
        if (showTable) {
            if (table.equals("")) {
                println("Specify the table (-t <table>)");
                exitCode = 1;
                System.exit(exitCode);
            }
        }

        boolean createTablespace = commandLine.hasOption("create-tablespace");
        if (createTablespace) {
            if (newschema.equals("")) {
                println("Specify the tablespace name (--newschema <schema>)");
                exitCode = 1;
                System.exit(exitCode);
            }
            if (leader.equals("")) {
                println("Specify the leader node (--newleader <nodeid>)");
                exitCode = 1;
                System.exit(exitCode);
            }
        }
        boolean alterTablespace = commandLine.hasOption("alter-tablespace");
        if (alterTablespace) {
            if (commandLine.getOptionValue("schema", null) == null) {
                println("Cowardly refusing to assume the default schema in an alter command. Explicitly use \"-s "
                        + TableSpace.DEFAULT + "\" instead");
                exitCode = 1;
                System.exit(exitCode);
            }
            if (param.equals("")) {
                println("Specify the parameter (--param <par>)");
                exitCode = 1;
                System.exit(exitCode);
            }
            if (values.equals("")) {
                println("Specify values (--values <vals>)");
                exitCode = 1;
                System.exit(exitCode);
            }

        }
        boolean addReplica = commandLine.hasOption("add-replica");
        if (addReplica) {
            if (commandLine.getOptionValue("schema", null) == null) {
                println("Cowardly refusing to assume the default schema in an alter command. Explicitly use \"-s "
                        + TableSpace.DEFAULT + "\" instead");
                exitCode = 1;
                System.exit(exitCode);
            }
            if (nodeId.equals("")) {
                println("Specify the node (-n <nodeid>)");
                exitCode = 1;
                System.exit(exitCode);
            }
        }
        boolean removeReplica = commandLine.hasOption("remove-replica");
        if (removeReplica) {
            if (commandLine.getOptionValue("schema", null) == null) {
                println("Cowardly refusing to assume the default schema in an alter command. Explicitly use \"-s "
                        + TableSpace.DEFAULT + "\" instead");
                exitCode = 1;
                System.exit(exitCode);
            }
            if (nodeId.equals("")) {
                println("Specify the node (-n <nodeid>)");
                exitCode = 1;
                System.exit(exitCode);
            }
        }

        TableSpaceMapper tableSpaceMapper = buildTableSpaceMapper(tablespacemapperfile);
        try (HerdDBDataSource datasource = new HerdDBDataSource()) {
            datasource.setUrl(url);
            datasource.setUsername(username);
            datasource.setPassword(password);

            try (Connection connection = datasource.getConnection();
                    Statement statement = connection.createStatement()) {
                connection.setSchema(schema);
                if (sqlconsole) {
                    runSqlConsole(connection, statement, PRETTY_PRINT);
                } else if (backup) {
                    performBackup(statement, schema, file, options, connection, dumpfetchsize);
                } else if (restore) {
                    performRestore(file, leader, newschema, options, statement, connection);
                } else if (!query.isEmpty()) {
                    executeStatement(verbose, ignoreerrors, false, false, query, statement, tableSpaceMapper,
                            false, PRETTY_PRINT);
                } else if (!file.isEmpty()) {
                    executeSqlFile(autotransactionbatchsize, connection, file, verbose, async, ignoreerrors,
                            frommysqldump, rewritestatements, statement, tableSpaceMapper, PRETTY_PRINT, filter,
                            datasource);
                } else if (!script.isEmpty()) {
                    executeScript(connection, datasource, statement, script);
                } else if (listTablespaces) {
                    printTableSpaces(verbose, ignoreerrors, statement, tableSpaceMapper);
                } else if (listNodes) {
                    printNodes(verbose, ignoreerrors, statement, tableSpaceMapper);
                } else if (showTablespace) {
                    printTableSpaceInfos(verbose, ignoreerrors, statement, tableSpaceMapper, schema);
                } else if (listTables) {
                    listTables(verbose, ignoreerrors, statement, tableSpaceMapper, schema);
                } else if (showTable) {
                    printTableInfos(verbose, ignoreerrors, statement, tableSpaceMapper, schema, table);
                } else if (addReplica) {
                    changeReplica(verbose, ignoreerrors, statement, tableSpaceMapper, schema, nodeId,
                            ChangeReplicaAction.ADD);
                } else if (removeReplica) {
                    changeReplica(verbose, ignoreerrors, statement, tableSpaceMapper, schema, nodeId,
                            ChangeReplicaAction.REMOVE);
                } else if (createTablespace) {
                    createTablespace(verbose, ignoreerrors, statement, tableSpaceMapper, newschema, leader);
                } else if (alterTablespace) {
                    alterTablespace(verbose, ignoreerrors, statement, tableSpaceMapper, schema, param, values);
                } else {
                    failAndPrintHelp(options);
                    return;
                }
            }
            exitCode = 0;
        } catch (Exception error) {
            if (verbose) {
                error.printStackTrace();
            } else {
                println("error:" + error);
            }
            exitCode = 1;
        }
    } finally {
        System.exit(exitCode);
    }
}

From source file:org.wavescale.hotload.agent.HotLoadAgent.java

public static void premain(String agentArgs, Instrumentation instrumentation) {
    ConfigManager configManager = ConfigManager.getInstance();
    initConfigManager(agentArgs.split(" "));
    LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME).setLevel(configManager.getLogLevel());
    NotifyHandler watchHandler = new WatchHandler();
    try {//from ww  w .  ja  va 2  s  .  c  o  m
        FileWatcher fileMonitor = new FileWatcher(configManager.getDirsToMonitor(),
                configManager.isMonitorRecursive());
        fileMonitor.addNotifyHandler(watchHandler);
        instrumentation.addTransformer(new MethodTransformer());
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, " An I/O error occured with trace:" + e);
    }
}

From source file:org.apache.cxf.tools.common.CommandInterfaceUtils.java

public static void commandCommonMain() {
    if (!testInProgress) {
        System.setProperty("org.apache.cxf.JDKBugHacks.defaultUsesCaches", "true");
        // force commons-logging into j.u.l so we can
        // configure it.
        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");

        try (InputStream commandConfig = CommandInterfaceUtils.class
                .getResourceAsStream("commandLogging.properties")) {
            LogManager.getLogManager().readConfiguration(commandConfig);
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }//from  w w w.  j  a v a2  s  .  c o m
    }
}

From source file:net.oneandone.shared.artifactory.App.java

private static void initLogging() {
    final InputStream resourceAsStream = App.class.getResourceAsStream("/logging.properties");
    try {//w w w. j a  v a2s  . co  m
        try {
            LogManager.getLogManager().readConfiguration(resourceAsStream);
        } finally {
            resourceAsStream.close();
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } catch (SecurityException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.eclipse.ecr.common.logging.JavaUtilLoggingHelper.java

/**
 * Redirects {@code java.util.logging} to Apache Commons Logging do not log
 * below the threshold level./* w ww.  j a  va2s. c o  m*/
 *
 * @since 5.4.2
 */
public static synchronized void redirectToApacheCommons(Level threshold) {
    if (activeHandler != null) {
        return;
    }
    try {
        Logger rootLogger = LogManager.getLogManager().getLogger("");
        for (Handler handler : rootLogger.getHandlers()) {
            rootLogger.removeHandler(handler);
        }
        activeHandler = new LogHandler();
        activeHandler.setLevel(threshold);
        rootLogger.addHandler(activeHandler);
        rootLogger.setLevel(threshold);
        log.info("Redirecting java.util.logging to Apache Commons Logging, threshold is "
                + threshold.toString());
    } catch (Exception e) {
        log.error("Handler setup failed", e);
    }
}

From source file:com.twitter.common.logging.LogUtil.java

/**
 * Gets the log directory as configured with the log manager.  This will attempt to expand any
 * directory wildcards that are included in log file property.
 *
 * @return The configured log directory.
 *//*from  w ww.j ava 2s  .c o m*/
public static File getLogManagerLogDir() {
    return getLogManagerLogDir(LogManager.getLogManager().getProperty(LOG_MANAGER_FILE_PROP));
}

From source file:com.archivas.logging.FileHandler.java

private static int getCount() {
    LogManager manager = LogManager.getLogManager();
    String cname = FileHandler.class.getName();

    String countStr = manager.getProperty(cname + ".count");
    int count = 9;
    if (countStr != null) {
        count = Integer.valueOf(countStr);
    }/* w  ww.j a  v  a2  s . co m*/

    return count;
}

From source file:LogWindow.java

private WindowHandler() {
    LogManager manager = LogManager.getLogManager();
    String className = this.getClass().getName();
    String level = manager.getProperty(className + ".level");
    setLevel(level != null ? Level.parse(level) : Level.INFO);
    if (window == null)
        window = new LogWindow();
}

From source file:org.activiti.engine.impl.util.LogUtil.java

public static void readJavaUtilLoggingConfigFromClasspath() {
    InputStream inputStream = ReflectUtil.getResourceAsStream("logging.properties");
    try {/*from w ww . j ava  2 s . c o  m*/
        if (inputStream != null) {
            LogManager.getLogManager().readConfiguration(inputStream);

            String redirectCommons = LogManager.getLogManager().getProperty("redirect.commons.logging");
            if ((redirectCommons != null) && (!redirectCommons.equalsIgnoreCase("false"))) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.Jdk14Logger");
            }
        }
    } catch (Exception e) {
        throw new PvmException("couldn't initialize logging properly", e);
    } finally {
        IoUtil.closeSilently(inputStream);
    }
}

From source file:uap.workflow.engine.util.LogUtil.java

public static void readJavaUtilLoggingConfigFromClasspath() {
    InputStream inputStream = ReflectUtil.getResourceAsStream("logging.properties");
    try {/*  w  w w .  jav a2s  .  c  om*/
        if (inputStream != null) {
            LogManager.getLogManager().readConfiguration(inputStream);
            String redirectCommons = LogManager.getLogManager().getProperty("redirect.commons.logging");
            if ((redirectCommons != null) && (!redirectCommons.equalsIgnoreCase("false"))) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.Jdk14Logger");
            }
        }
    } catch (Exception e) {
        throw new WorkflowRuntimeException("couldn't initialize logging properly", e);
    } finally {
        IoUtil.closeSilently(inputStream);
    }
}