Example usage for java.util.logging Logger GLOBAL_LOGGER_NAME

List of usage examples for java.util.logging Logger GLOBAL_LOGGER_NAME

Introduction

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

Prototype

String GLOBAL_LOGGER_NAME

To view the source code for java.util.logging Logger GLOBAL_LOGGER_NAME.

Click Source Link

Document

GLOBAL_LOGGER_NAME is a name for the global logger.

Usage

From source file:br.bireme.tb.URLS.java

public static void generateFileStructure(final String url, final String rootDir) throws IOException {
    if (url == null) {
        throw new NullPointerException("url");
    }// w  w  w . j a v  a  2  s.c  o  m
    if (rootDir == null) {
        throw new NullPointerException("rootDir");
    }
    if (url.trim().endsWith(".def")) {
        throw new NullPointerException("initial url file can not be a def file.");
    }
    final File root = new File(rootDir);

    if (root.exists() && (!Utils.deleteFile(root))) {
        final String msg = "Directory [" + root.getAbsolutePath() + "] creation error.";
        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).severe(msg);
        throw new IOException(msg);
    }
    if (!root.mkdirs()) {
        final String msg = "Directory [" + root.getAbsolutePath() + "] creation error.";
        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).severe(msg);
        throw new IOException(msg);
    }

    System.out.println("Searching cvs files\n");
    final Set<String> files = generateCells(url, root);
    System.out.println("Total cell files created: " + files.size());

    try {
        createAllSitemap(files, root);
    } catch (IOException ioe) {
        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, "Sitemap file creation error.", ioe);
    }

    try (final BufferedWriter writer = new BufferedWriter(new FileWriter(new File(root, "index.html")))) {
        writer.append("<!DOCTYPE html>\n");
        writer.append("<html>\n");
        writer.append(" <head>\n");
        writer.append(" <meta charset=\"UTF-8\">\n");
        writer.append(" </head>\n");
        writer.append(" <body>\n");
        writer.append(" <h1>Fichas de Qualificao</h1>\n");
        writer.append(" <ul>\n");
        for (String path : files) {
            writer.append(" <li>\n");
            writer.append(" <a href=\"" + path + "\">" + path + "</a>\n");
            writer.append(" </li>\n");
        }
        writer.append(" </ul>\n");
        writer.append(" </body>\n");
        writer.append("</html>\n");
    } catch (IOException ioe) {
        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, "Index file creation error.", ioe);
    }

    System.out.println("Files saved at: " + root.getAbsolutePath());
}

From source file:com.civprod.writerstoolbox.apps.Context.java

/**
 * @return the mLogger/*from www  .  jav  a2  s.c  o m*/
 */
public String getLoggerName() {
    String rLoggerName = "";
    if (!this.useIndependentLogger) {
        if (this.mParent != null) {
            rLoggerName = mParent.getLoggerName() + ".";
        } else {
            rLoggerName = Logger.GLOBAL_LOGGER_NAME + ".";
        }
    }
    if (modifiable) {
        LoggerLock.readLock().lock();
    }
    try {
        rLoggerName += mLoggerNamePart;
    } finally {
        if (modifiable) {
            LoggerLock.readLock().unlock();
        }
    }
    return rLoggerName;
}

From source file:br.bireme.tb.URLS.java

/**
 * Creates files associating each file with a table cell from a csv file
 * @param url html file where the csv links will be recursively searched.
 * @param root the output directory where the files will be created
 * @return a list of new created file names
 * @throws IOException //  ww  w. j a  v  a  2s.co m
 */
public static Set<String> generateCells(final String url, final File root) throws IOException {
    if (url == null) {
        throw new NullPointerException("url");
    }
    if (root == null) {
        throw new NullPointerException("root");
    }
    try {
        Utils.copyDirectory(new File("template/css"), new File(root, "css"));
        Utils.copyDirectory(new File("template/img"), new File(root, "img"));
    } catch (IOException ioe) {
        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, "skipping diretory: (css/img)", ioe);
    }
    final Set<String> urls = loadCsvFromHtml(new URL(url), root);

    return urls;
}

From source file:br.bireme.tb.URLS.java

/**
 * Loads all cvs links from a root html page if possible otherwise find then
 * recursively. Then the csv s will be loaded and the table cells will be
 * saved at files./*from w ww.  j  a v a 2 s . c o  m*/
 * @param html
 * @param postParam
 * @param tableOptions
 * @param tableNum
 * @param level
 * @param setUrls
 * @param history
 * @param root
 * @return array of int { number of the last table generated, number of csv files read }
 * @throws IOException 
 */
private static int[] loadCsvFromHtml(final URL html, final String postParam,
        final Map<String, String> tableOptions, final int tableNum, final int level, final Set<String> setUrls,
        final Set<URL> history, final File root) throws IOException {
    assert html != null;
    assert tableNum >= 0;
    assert level >= 0;
    assert setUrls != null;
    assert history != null;
    assert root != null;

    int[] ret = new int[] { tableNum, 0 };

    if ((postParam != null) || (!history.contains(html))) {
        if (level <= MAX_LEVEL) {
            history.add(html);

            final String[] page;
            try {
                page = (postParam == null) ? loadPageGet(html) : loadPagePost(html, postParam);
            } catch (IOException ioe) {
                Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE,
                        "error loading file: [" + html + "] params: [" + postParam + "]", ioe);
                return ret;
            }
            final String content = page[1];
            final Matcher mat = CSV_PATTERN.matcher(content);

            if (mat.find()) { // Found a cvs link in that page  
                final Matcher mat2 = QUALIF_REC_PATTERN.matcher(content);
                if (mat2.find()) {
                    final UrlElem elem = new UrlElem();
                    elem.father = html;
                    elem.fatherParams = postParam;
                    elem.tableOptions = tableOptions;
                    elem.csv = withDomain(html, mat.group(1));
                    elem.qualifRec = withDomain(html, mat2.group(1));
                    try {
                        final String[] csvpage = loadPageGet(elem.csv);
                        final CSV_File csv = new CSV_File();
                        final Table table = csv.parse(csvpage[1], CSV_SEPARATOR);

                        genCellsFromTable(table, elem, root, setUrls, ++ret[0]);
                        ret[1] = 1;
                    } catch (Exception ex) {
                        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE,
                                "skipping file: " + elem.csv, ex);
                    }
                }
            } else { // Did not find a cvs link in that page
                if (postParam != null) {
                    Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE,
                            " skipping loadCsvFromHtml/Def file: " + html + " params:" + postParam
                                    + "\nCSV link not found into def page [" + findErrorMessage(content) + "]");
                }
                final Set<URL> urls = getPageDefHtmlUrls(new URL(page[0]), content, history);
                for (URL url : urls) {
                    try {
                        final String file = url.getFile();
                        final int[] aux;
                        if (file.endsWith(".def")) {
                            aux = loadCsvFromDef(url, ret[0], setUrls, history, root);
                        } else {
                            aux = loadCsvFromHtml(url, null, null, ret[0], level + 1, setUrls, history, root);
                        }
                        ret[0] = aux[0];
                        ret[1] += aux[1];
                    } catch (IOException ioe) {
                        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE,
                                "skipping loadCsvFromHtml/Def file: " + url, ioe);
                        //throw ioe;
                    }
                }
            }
        }
    }

    return ret;
}

From source file:br.bireme.tb.URLS.java

/**
 * Given a table, generates all of its cells and save each one into a file
 * @param table table used to generate cells
 * @param elem //from   w  ww . j  ava  2  s  .c  o  m
 * @param root root directory where the files will be created
 * @param urls
 * @param tableNum table number used to create the file name
 */
private static void genCellsFromTable(final Table table, final UrlElem elem, final File root,
        final Set<String> urls, final int tableNum) {
    assert table != null;
    assert elem != null;
    assert root != null;
    assert urls != null;
    assert tableNum >= 0;

    final ArrayList<ArrayList<String>> elems = table.getLines();
    final Iterator<ArrayList<String>> yit = elems.iterator();
    int idx = 1;

    for (String row : table.getRow()) {
        final Iterator<String> xit = yit.next().iterator();
        for (List<String> hdr : table.getHeader()) {
            if (xit.hasNext()) {
                final Cell cell = new Cell();
                cell.setIdx(idx++);
                cell.setElem(elem);
                cell.setHeader(hdr);
                cell.setNotes(table.getNotes());
                cell.setRow(row);
                cell.setScope(table.getScope());
                cell.setSources(table.getSources());
                cell.setSubtitle(table.getSubtitle());
                cell.setTitle(table.getTitle());
                cell.setValue(xit.next());
                cell.setLabels(adjustLabel(cell.getValue(), table.getLabels()));
                final Matcher mat = REFUSE_PAT.matcher(cell.getValue());
                if (!mat.matches()) {
                    try {
                        urls.add(saveToFile(cell, root, tableNum));
                    } catch (IOException ioe) {
                        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, "Can not save file.",
                                ioe);
                    }
                }
            }
        }
    }
}

From source file:br.bireme.tb.URLS.java

/**
 * Extracts cvs links by combining fields from a def file.
 * @param def url of the def page from which the cvs will be extracted
 * @return array of int { number of the last table generated, number of csv files read }
 * @throws IOException//from   ww w  . j av a  2s .c o m
 */
private static int[] loadCsvFromDef(final URL def, final int tableNum, final Set<String> setUrls,
        final Set<URL> history, final File root) throws IOException {
    assert def != null;
    assert tableNum >= 0;
    assert setUrls != null;
    assert history != null;
    assert root != null;

    final Set<DEF_File.DefUrls> urls = new DEF_File().generateDefUrls(def);
    final int[] ret = new int[2];
    ret[0] = tableNum;

    for (DEF_File.DefUrls url : urls) {
        try {
            final int[] aux = loadCsvFromHtml(new URL(url.url), url.postParams, url.options, ret[0], MAX_LEVEL,
                    setUrls, history, root);
            ret[0] = aux[0];
            ret[1] += aux[1];
        } catch (IOException ioe) {
            Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE,
                    "skipping loadCsvFromHtml file: " + url.url, ioe);
        }
    }

    return ret;
}

From source file:br.bireme.tb.URLS.java

public static void main(final String[] args) throws IOException {
    if (args.length != 1) {
        usage();/*from   www  .j a  v  a2s. c  o m*/
    }

    final String out = args[0].trim();
    final String outDir = (out.endsWith("/")) ? out : out + "/";
    final String LOG_DIR = "log";
    final File logDir = new File(LOG_DIR);
    if (!logDir.exists()) {
        if (!logDir.mkdir()) {
            throw new IOException("log directory [" + LOG_DIR + "] creation error");
        }
    }

    final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
    final FileHandler fh = new FileHandler(getLogFileName(LOG_DIR), false);
    logger.addHandler(fh);

    final String URL = URLS.ROOT_URL;
    final TimeString time = new TimeString();

    time.start();
    generateFileStructure(URL, outDir + "celulasIDB");

    System.out.println("Total time: " + time.getTime());
}

From source file:org.springframework.jdbc.datasource.AbstractDataSource.java

@Override
public Logger getParentLogger() {
    return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
}

From source file:org.wattdepot.server.WattDepotServer.java

/**
 * Creates a new instance of the WattDepot server.
 * /*from   w  ww. j  a  v  a  2s  .  c o  m*/
 * @param properties
 *          The ServerProperties used to initialize this server.
 * @return The WattDepotServer.
 * @throws Exception
 *           if there is a problem starting the server.
 */
public static WattDepotServer newInstance(ServerProperties properties) throws Exception {
    int port = Integer.parseInt(properties.get(ServerProperties.PORT_KEY));
    WattDepotServer server = new WattDepotServer();
    // System.out.println("WattDepotServer.");
    //    LoggerUtil.showLoggers();
    boolean enableLogging = Boolean.parseBoolean(properties.get(ServerProperties.ENABLE_LOGGING_KEY));
    server.serverProperties = properties;
    server.hostName = server.serverProperties.getFullHost();

    // Get the WattDepotPersistence implementation.
    String depotClass = properties.get(ServerProperties.WATT_DEPOT_IMPL_KEY);
    server.depot = (WattDepotPersistence) Class.forName(depotClass).getConstructor(ServerProperties.class)
            .newInstance(properties);
    if (server.depot.getSessionOpen() != server.depot.getSessionClose()) {
        throw new RuntimeException("opens and closed mismatched.");
    }
    server.depot.initializeMeasurementTypes();
    if (server.depot.getSessionOpen() != server.depot.getSessionClose()) {
        throw new RuntimeException("opens and closed mismatched.");
    }
    server.depot.initializeSensorModels();
    if (server.depot.getSessionOpen() != server.depot.getSessionClose()) {
        throw new RuntimeException("opens and closed mismatched.");
    }
    server.depot.setServerProperties(properties);
    server.restletServer = new WattDepotComponent(server.depot, port);
    server.logger = server.restletServer.getLogger();

    // Set up logging.
    if (enableLogging) {
        LoggerUtil.useConsoleHandler();
        Logger base = LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME);
        base = base.getParent();
        String level = properties.get(ServerProperties.LOGGING_LEVEL_KEY);
        LoggerUtil.setLoggingLevel(base, level);

        server.logger.info("Starting WattDepot server.");
        server.logger.info("Host: " + server.hostName);
        server.logger.info(server.serverProperties.echoProperties());
    } else {
        LoggerUtil.useConsoleHandler();
        Logger base = LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME);
        base = base.getParent();
        LoggerUtil.setLoggingLevel(base, Level.SEVERE.toString());
    }
    server.restletServer.start();

    server.logger.info("WattDepot server now running.");

    //    LoggerUtil.showLoggers();
    return server;
}

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 w  w w  . j ava  2  s . co  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);
    }
}