Search in sources :

Example 96 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project neo4j by neo4j.

the class SuppressOutput method java_util_logging.

private static Suppressible java_util_logging(final ByteArrayOutputStream redirectTo, Level level) {
    final Handler replacement = redirectTo == null ? null : new StreamHandler(redirectTo, new SimpleFormatter());
    if (replacement != null && level != null) {
        replacement.setLevel(level);
    }
    return new Suppressible() {

        @Override
        public Voice suppress() {
            final Logger logger = LogManager.getLogManager().getLogger("");
            final Level level = logger.getLevel();
            final Handler[] handlers = logger.getHandlers();
            for (Handler handler : handlers) {
                logger.removeHandler(handler);
            }
            if (replacement != null) {
                logger.addHandler(replacement);
                logger.setLevel(Level.ALL);
            }
            return new Voice(this, redirectTo) {

                @Override
                void restore(boolean failure) {
                    for (Handler handler : handlers) {
                        logger.addHandler(handler);
                    }
                    logger.setLevel(level);
                    if (replacement != null) {
                        logger.removeHandler(replacement);
                    }
                }
            };
        }
    };
}
Also used : StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) StreamHandler(java.util.logging.StreamHandler) Handler(java.util.logging.Handler) Level(java.util.logging.Level) Logger(java.util.logging.Logger)

Example 97 with SimpleFormatter

use of java.util.logging.SimpleFormatter 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 98 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project OsmAnd-tools by osmandapp.

the class IndexBatchCreator method generateIndex.

protected void generateIndex(File file, String rName, RegionSpecificData rdata, Set<String> alreadyGeneratedFiles) {
    try {
        // be independent of previous results
        RTree.clearCache();
        String regionName = file.getName();
        log.warn("-------------------------------------------");
        log.warn("----------- Generate " + file.getName() + "\n\n\n");
        int i = file.getName().indexOf('.');
        if (i > -1) {
            regionName = Algorithms.capitalizeFirstLetterAndLowercase(file.getName().substring(0, i));
        }
        if (Algorithms.isEmpty(rName)) {
            rName = regionName;
        } else {
            rName = Algorithms.capitalizeFirstLetterAndLowercase(rName);
        }
        DBDialect osmDb = this.osmDbDialect;
        if (file.length() / 1024 / 1024 > INMEM_LIMIT && osmDb == DBDialect.SQLITE_IN_MEMORY) {
            log.warn("Switching SQLITE in memory dialect to SQLITE");
            osmDb = DBDialect.SQLITE;
        }
        final boolean indAddr = indexAddress && (rdata == null || rdata.indexAddress);
        final boolean indPoi = indexPOI && (rdata == null || rdata.indexPOI);
        final boolean indTransport = indexTransport && (rdata == null || rdata.indexTransport);
        final boolean indMap = indexMap && (rdata == null || rdata.indexMap);
        final boolean indRouting = indexRouting && (rdata == null || rdata.indexRouting);
        if (!indAddr && !indPoi && !indTransport && !indMap && !indRouting) {
            log.warn("! Skip country because nothing to index !");
            file.delete();
            return;
        }
        IndexCreatorSettings settings = new IndexCreatorSettings();
        settings.indexMap = indMap;
        settings.indexAddress = indAddr;
        settings.indexPOI = indPoi;
        settings.indexTransport = indTransport;
        settings.indexRouting = indRouting;
        if (zoomWaySmoothness != null) {
            settings.zoomWaySmoothness = zoomWaySmoothness;
        }
        boolean worldMaps = rName.toLowerCase().contains("world");
        if (worldMaps) {
            if (rName.toLowerCase().contains("basemap")) {
                return;
            }
            if (rName.toLowerCase().contains("seamarks")) {
                settings.keepOnlySeaObjects = true;
                settings.indexTransport = false;
                settings.indexAddress = false;
            }
        } else {
            if (srtmDir != null && (rdata == null || rdata.indexSRTM)) {
                settings.srtmDataFolder = srtmDir;
            }
        }
        IndexCreator indexCreator = new IndexCreator(workDir, settings);
        indexCreator.setDialects(osmDb, osmDb);
        indexCreator.setLastModifiedDate(file.lastModified());
        indexCreator.setRegionName(rName);
        String mapFileName = regionName + "_" + IndexConstants.BINARY_MAP_VERSION + IndexConstants.BINARY_MAP_INDEX_EXT;
        indexCreator.setMapFileName(mapFileName);
        try {
            alreadyGeneratedFiles.add(file.getName());
            Log warningsAboutMapData = null;
            File logFileName = new File(workDir, mapFileName + GEN_LOG_EXT);
            FileHandler fh = null;
            // configure log path
            try {
                FileOutputStream fout = new FileOutputStream(logFileName);
                fout.write((new Date() + "\n").getBytes());
                fout.write((MapCreatorVersion.APP_MAP_CREATOR_FULL_NAME + "\n").getBytes());
                fout.close();
                fh = new FileHandler(logFileName.getAbsolutePath(), 10 * 1000 * 1000, 1, true);
                fh.setFormatter(new SimpleFormatter());
                fh.setLevel(Level.ALL);
                Jdk14Logger jdk14Logger = new Jdk14Logger("tempLogger");
                jdk14Logger.getLogger().setLevel(Level.ALL);
                jdk14Logger.getLogger().setUseParentHandlers(false);
                jdk14Logger.getLogger().addHandler(fh);
                warningsAboutMapData = jdk14Logger;
            } catch (SecurityException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            if (fh != null) {
                LogManager.getLogManager().getLogger("").addHandler(fh);
            }
            try {
                indexCreator.generateIndexes(file, new ConsoleProgressImplementation(1), null, mapZooms, new MapRenderingTypesEncoder(renderingTypesFile, file.getName()), warningsAboutMapData);
            } finally {
                if (fh != null) {
                    fh.close();
                    LogManager.getLogManager().getLogger("").removeHandler(fh);
                }
            }
            File generated = new File(workDir, mapFileName);
            File dest = new File(indexDirFiles, generated.getName());
            if (!generated.renameTo(dest)) {
                FileOutputStream fout = new FileOutputStream(dest);
                FileInputStream fin = new FileInputStream(generated);
                Algorithms.streamCopy(fin, fout);
                fin.close();
                fout.close();
            }
            File copyLog = new File(indexDirFiles, logFileName.getName());
            FileOutputStream fout = new FileOutputStream(copyLog);
            FileInputStream fin = new FileInputStream(logFileName);
            Algorithms.streamCopy(fin, fout);
            fin.close();
            fout.close();
        // logFileName.renameTo(new File(indexDirFiles, logFileName.getName()));
        } catch (Exception e) {
            // $NON-NLS-1$
            log.error("Exception generating indexes for " + file.getName(), e);
        }
    } catch (OutOfMemoryError e) {
        System.gc();
        log.error("OutOfMemory", e);
    }
    System.gc();
}
Also used : IndexCreatorSettings(net.osmand.obf.preparation.IndexCreatorSettings) Jdk14Logger(org.apache.commons.logging.impl.Jdk14Logger) Log(org.apache.commons.logging.Log) SimpleFormatter(java.util.logging.SimpleFormatter) IndexCreator(net.osmand.obf.preparation.IndexCreator) IOException(java.io.IOException) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) Date(java.util.Date) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FileHandler(java.util.logging.FileHandler) DBDialect(net.osmand.obf.preparation.DBDialect) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 99 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project OsmAnd-tools by osmandapp.

the class OsmExtractionUI method configLogFile.

public static void configLogFile() {
    new File(LOG_PATH).getParentFile().mkdirs();
    try {
        FileHandler fh = new FileHandler(LOG_PATH, 5000000, 1, true);
        fh.setFormatter(new SimpleFormatter());
        LogManager.getLogManager().getLogger("").addHandler(fh);
    } catch (SecurityException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) IOException(java.io.IOException) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 100 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project BlocklyArduinoIDEPlugin by technologiescollege.

the class AbstractLauncher method setupLogFile.

/**
 * Make java.util.logger log to a file. Default it will log to $TMPDIR/fxlauncher.log. This can be overriden by using
 * comman line parameter <code>--logfile=logfile</code>
 *
 * @throws IOException
 */
protected void setupLogFile() throws IOException {
    String filename = System.getProperty("java.io.tmpdir") + File.separator + "fxlauncher.log";
    if (getParameters().getNamed().containsKey("logfile"))
        filename = getParameters().getNamed().get("logfile");
    System.out.println("logging to " + filename);
    FileHandler handler = new FileHandler(filename);
    handler.setFormatter(new SimpleFormatter());
    log.addHandler(handler);
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) FileHandler(java.util.logging.FileHandler)

Aggregations

SimpleFormatter (java.util.logging.SimpleFormatter)100 FileHandler (java.util.logging.FileHandler)59 Logger (java.util.logging.Logger)36 File (java.io.File)28 Handler (java.util.logging.Handler)23 IOException (java.io.IOException)17 StreamHandler (java.util.logging.StreamHandler)16 Properties (java.util.Properties)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 LogRecord (java.util.logging.LogRecord)13 BalancerRunner (org.mobicents.tools.sip.balancer.BalancerRunner)13 Config (edu.neu.ccs.pyramid.configuration.Config)11 ConsoleHandler (java.util.logging.ConsoleHandler)10 Formatter (java.util.logging.Formatter)9 Test (org.junit.Test)7 MockResponse (com.google.mockwebserver.MockResponse)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 Pair (edu.neu.ccs.pyramid.util.Pair)3