use of java.util.logging.SimpleFormatter in project mssql-jdbc by Microsoft.
the class AbstractTest method invokeLogging.
/**
* Invoke logging.
*/
public static void invokeLogging() {
Handler handler = null;
String enableLogging = getConfiguredProperty("mssql_jdbc_logging", "false");
// If logging is not enable then return.
if (!"true".equalsIgnoreCase(enableLogging)) {
return;
}
String loggingHandler = getConfiguredProperty("mssql_jdbc_logging_handler", "not_configured");
try {
// handler = new FileHandler("Driver.log");
if ("console".equalsIgnoreCase(loggingHandler)) {
handler = new ConsoleHandler();
} else if ("file".equalsIgnoreCase(loggingHandler)) {
handler = new FileHandler("Driver.log");
System.out.println("Look for Driver.log file in your classpath for detail logs");
}
if (handler != null) {
handler.setFormatter(new SimpleFormatter());
handler.setLevel(Level.FINEST);
Logger.getLogger("").addHandler(handler);
}
// By default, Loggers also send their output to their parent logger.
// Typically the root Logger is configured with a set of Handlers that essentially act as default handlers for all loggers.
Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc");
logger.setLevel(Level.FINEST);
} catch (Exception e) {
System.err.println("Some how could not invoke logging: " + e.getMessage());
}
}
use of java.util.logging.SimpleFormatter in project runwar by cfmlprojects.
the class LogRequest method init.
public void init(ServletConfig config) {
this.logLevel = config.getInitParameter("logLevel");
this.logFilePath = config.getInitParameter("logFilePath");
boolean append = true;
FileHandler handler;
try {
handler = new FileHandler(this.logFilePath, append);
handler.setFormatter(new SimpleFormatter());
log.addHandler(handler);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Add to the desired logger
}
use of java.util.logging.SimpleFormatter in project openj9 by eclipse.
the class LibraryCollector method main.
// used for testing purposes
public static void main(String[] args) {
LibraryCollector collector = new LibraryCollector();
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINEST);
Formatter formatter = new SimpleFormatter();
handler.setFormatter(formatter);
Logger log = Logger.getLogger(PUBLIC_LOGGER_NAME);
log.addHandler(handler);
log.setLevel(Level.FINEST);
// assumes args[0] is the path to the core file, args[1] is the type of collection
CollectorResult result = collector.collectLibrariesFor(args[0], args[1]);
System.out.println("Collection completed with result : " + result.name());
}
use of java.util.logging.SimpleFormatter in project openj9 by eclipse.
the class Session method enableConsoleLogging.
/**
* Enables console logger for the supplied logger. Typically used to surface
* log commands generated by internal components
*
* @param log the logger to enable
*/
private void enableConsoleLogging(Logger log) {
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINE);
Formatter formatter = new SimpleFormatter();
handler.setFormatter(formatter);
log.addHandler(handler);
log.setLevel(Level.FINE);
if (isVerboseEnabled) {
out.println("Console logging is now enabled for " + log.getName());
}
}
use of java.util.logging.SimpleFormatter in project tomee by apache.
the class FileHandler method configure.
/**
* Configure from <code>LogManager</code> properties.
*/
private void configure() {
final Timestamp ts = new Timestamp(System.currentTimeMillis());
final String tsString = ts.toString().substring(0, 19);
date = tsString.substring(0, 10);
// allow classes to override
final String className = this.getClass().getName();
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
// Retrieve configuration of logging file name
rotatable = Boolean.parseBoolean(getProperty(className + ".rotatable", "true"));
if (directory == null) {
directory = getProperty(className + ".directory", "logs");
}
if (prefix == null) {
prefix = getProperty(className + ".prefix", "juli.");
}
if (suffix == null) {
suffix = getProperty(className + ".suffix", ".log");
}
final String sBufferSize = getProperty(className + ".bufferSize", String.valueOf(bufferSize));
try {
bufferSize = Integer.parseInt(sBufferSize);
} catch (final NumberFormatException ignore) {
// no op
}
// Get encoding for the logging file
final String encoding = getProperty(className + ".encoding", null);
if (encoding != null && encoding.length() > 0) {
try {
setEncoding(encoding);
} catch (final UnsupportedEncodingException ex) {
// Ignore
}
}
// Get logging level for the handler
setLevel(Level.parse(getProperty(className + ".level", String.valueOf(Level.ALL))));
// Get filter configuration
final String filterName = getProperty(className + ".filter", null);
if (filterName != null) {
try {
setFilter((Filter) cl.loadClass(filterName).newInstance());
} catch (final Exception e) {
// Ignore
}
}
// Set formatter
final String formatterName = getProperty(className + ".formatter", null);
if (formatterName != null) {
try {
setFormatter((Formatter) cl.loadClass(formatterName).newInstance());
} catch (final Exception e) {
// Ignore and fallback to defaults
setFormatter(new SimpleFormatter());
}
} else {
setFormatter(new SimpleFormatter());
}
// Set error manager
setErrorManager(new ErrorManager());
}
Aggregations