Description
Configures the system log.
License
Open Source License
Parameter
Parameter | Description |
---|
console | If true, the console log is activated, false it is not. |
file | If true, the file log is activated, false it is not. |
Exception
Declaration
public static void log(boolean console, boolean file) throws IOException
Method Source Code
//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2005-2007 Universidade de Sao Paulo, Sao Carlos/SP, Brazil.
* All Rights Reserved./*from ww w .j a v a2s .com*/
*
* This file is part of Projection Explorer (PEx).
*
* How to cite this work:
*
@inproceedings{paulovich2007pex,
author = {Fernando V. Paulovich and Maria Cristina F. Oliveira and Rosane
Minghim},
title = {The Projection Explorer: A Flexible Tool for Projection-based
Multidimensional Visualization},
booktitle = {SIBGRAPI '07: Proceedings of the XX Brazilian Symposium on
Computer Graphics and Image Processing (SIBGRAPI 2007)},
year = {2007},
isbn = {0-7695-2996-8},
pages = {27--34},
doi = {http://dx.doi.org/10.1109/SIBGRAPI.2007.39},
publisher = {IEEE Computer Society},
address = {Washington, DC, USA},
}
*
* PEx is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* PEx is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* This code was developed by members of Computer Graphics and Image
* Processing Group (http://www.lcad.icmc.usp.br) at Instituto de Ciencias
* Matematicas e de Computacao - ICMC - (http://www.icmc.usp.br) of
* Universidade de Sao Paulo, Sao Carlos/SP, Brazil. The initial developer
* of the original code is Fernando Vieira Paulovich <fpaulovich@gmail.com>,
* Roberto Pinho <robertopinho@yahoo.com.br>.
*
* Contributor(s): Rosane Minghim <rminghim@icmc.usp.br>
*
* You should have received a copy of the GNU General Public License along
* with PEx. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LICENSE BLOCK ***** */
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
public class Main {
/**
* Configures the system log.
* @param console If true, the console log is activated, false it is not.
* @param file If true, the file log is activated, false it is not.
* @throws java.io.IOException
*/
public static void log(boolean console, boolean file) throws IOException {
String filename = "log%g.txt";
int limit = 10000000; // 10 Mb
int numLogFiles = 5;
if (file) {
FileHandler handler = new FileHandler(filename, limit, numLogFiles, true);
handler.setFormatter(new SimpleFormatter());
// handler.setFormatter(new XMLFormatter());
handler.setLevel(Level.ALL);
Logger.getLogger("").addHandler(handler);
Logger.getLogger("Util").log(Level.INFO, "Adding the file logging.");
} else {
Logger.getLogger("Util").log(Level.INFO, "Removing the file logging.");
Logger rootLogger = Logger.getLogger("");
Handler[] handlers = rootLogger.getHandlers();
for (int i = 0; i < handlers.length; i++) {
if (handlers[i] instanceof FileHandler) {
rootLogger.removeHandler(handlers[i]);
}
}
}
//disable console log
if (console) {
Logger rootLogger = Logger.getLogger("");
Handler[] handlers = rootLogger.getHandlers();
for (int i = 0; i < handlers.length; i++) {
if (handlers[i] instanceof ConsoleHandler) {
rootLogger.removeHandler(handlers[i]);
}
}
rootLogger.addHandler(new ConsoleHandler());
Logger.getLogger("Util").log(Level.INFO, "Adding console logging.");
} else {
Logger.getLogger("Util").log(Level.INFO, "Removing console logging.");
Logger rootLogger = Logger.getLogger("");
Handler[] handlers = rootLogger.getHandlers();
for (int i = 0; i < handlers.length; i++) {
if (handlers[i] instanceof ConsoleHandler) {
rootLogger.removeHandler(handlers[i]);
}
}
}
}
}
Related
- log(final PrintStream logger, final Object message)
- log(final PrintStream logger, final String message)
- log(final String file, final String msg)
- log(final String message, final String file)