use of java.util.logging.FileHandler in project zemberek-nlp by ahmetaa.
the class Log method removeHandler.
public static void removeHandler(Path path) {
if (handlers.containsKey(path)) {
FileHandler handler = handlers.remove(path);
logger.removeHandler(handler);
}
}
use of java.util.logging.FileHandler 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.FileHandler 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.FileHandler in project 360-Engine-for-Android by 360.
the class LogUtils method enableLogcat.
/**
* Enable logging.
*/
public static void enableLogcat() {
mEnabled = true;
/**
* Enable the SD Card logger *
*/
sLogger = Logger.getLogger(APP_NAME_PREFIX);
try {
FileHandler fileHandler = new FileHandler(APP_FILE_NAME, LOG_FILE_LIMIT, LOG_FILE_COUNT);
fileHandler.setFormatter(new Formatter() {
@Override
public String format(final LogRecord logRecord) {
StringBuilder sb = new StringBuilder();
sb.append(DATE_FORMAT.format(new Date(logRecord.getMillis())));
sb.append(" ");
sb.append(logRecord.getMessage());
sb.append("\n");
return sb.toString();
}
});
sLogger.addHandler(fileHandler);
} catch (IOException e) {
logE("LogUtils.logToFile() IOException, data will not be logged " + "to file", e);
sLogger = null;
}
if (Settings.ENABLED_PROFILE_ENGINES) {
/**
* Enable the SD Card profiler *
*/
sProfileLogger = Logger.getLogger("profiler");
try {
FileHandler fileHandler = new FileHandler("/sdcard/engineprofiler.log", LOG_FILE_LIMIT, LOG_FILE_COUNT);
fileHandler.setFormatter(new Formatter() {
@Override
public String format(final LogRecord logRecord) {
StringBuilder sb = new StringBuilder();
sb.append(DATE_FORMAT.format(new Date(logRecord.getMillis())));
sb.append("|");
sb.append(logRecord.getMessage());
sb.append("\n");
return sb.toString();
}
});
sProfileLogger.addHandler(fileHandler);
} catch (IOException e) {
logE("LogUtils.logToFile() IOException, data will not be logged " + "to file", e);
sProfileLogger = null;
}
}
}
use of java.util.logging.FileHandler in project ignite by apache.
the class CommandHandler method execute.
/**
* Parse and execute command.
*
* @param rawArgs Arguments to parse and execute.
* @return Exit code.
*/
public int execute(List<String> rawArgs) {
LocalDateTime startTime = LocalDateTime.now();
Thread.currentThread().setName("session=" + ses);
logger.info("Control utility [ver. " + ACK_VER_STR + "]");
logger.info(COPYRIGHT);
logger.info("User: " + System.getProperty("user.name"));
logger.info("Time: " + startTime.format(formatter));
String commandName = "";
Throwable err = null;
boolean verbose = false;
try {
if (isHelp(rawArgs)) {
printHelp(rawArgs);
return EXIT_CODE_OK;
}
verbose = F.exist(rawArgs, CMD_VERBOSE::equalsIgnoreCase);
ConnectionAndSslParameters args = new CommonArgParser(logger).parseAndValidate(rawArgs.iterator());
Command command = args.command();
commandName = command.name();
GridClientConfiguration clientCfg = getClientConfiguration(args);
int tryConnectMaxCount = 3;
boolean suppliedAuth = !F.isEmpty(args.userName()) && !F.isEmpty(args.password());
boolean credentialsRequested = false;
while (true) {
try {
if (!args.autoConfirmation()) {
command.prepareConfirmation(clientCfg);
if (!confirm(command.confirmationPrompt())) {
logger.info("Operation cancelled.");
return EXIT_CODE_OK;
}
}
logger.info("Command [" + commandName + "] started");
logger.info("Arguments: " + argumentsToString(rawArgs));
logger.info(DELIM);
lastOperationRes = command.execute(clientCfg, logger, args.verbose());
break;
} catch (Throwable e) {
if (!isAuthError(e))
throw e;
if (suppliedAuth)
throw new GridClientAuthenticationException("Wrong credentials.");
if (tryConnectMaxCount == 0) {
throw new GridClientAuthenticationException("Maximum number of " + "retries exceeded");
}
logger.info(credentialsRequested ? "Authentication error, please try again." : "This cluster requires authentication.");
if (credentialsRequested)
tryConnectMaxCount--;
String user = retrieveUserName(args, clientCfg);
String pwd = new String(requestPasswordFromConsole("password: "));
clientCfg = getClientConfiguration(user, pwd, args);
credentialsRequested = true;
}
}
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_OK);
return EXIT_CODE_OK;
} catch (IllegalArgumentException e) {
logger.severe("Check arguments. " + errorMessage(e));
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);
if (verbose)
err = e;
return EXIT_CODE_INVALID_ARGUMENTS;
} catch (Throwable e) {
if (isAuthError(e)) {
logger.severe("Authentication error. " + errorMessage(e));
logger.info("Command [" + commandName + "] finished with code: " + ERR_AUTHENTICATION_FAILED);
if (verbose)
err = e;
return ERR_AUTHENTICATION_FAILED;
}
if (isConnectionError(e)) {
IgniteCheckedException cause = X.cause(e, IgniteCheckedException.class);
if (isConnectionClosedSilentlyException(e))
logger.severe("Connection to cluster failed. Please check firewall settings and " + "client and server are using the same SSL configuration.");
else {
if (isSSLMisconfigurationError(cause))
e = cause;
logger.severe("Connection to cluster failed. " + errorMessage(e));
}
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_CONNECTION_FAILED);
if (verbose)
err = e;
return EXIT_CODE_CONNECTION_FAILED;
}
if (X.hasCause(e, IllegalArgumentException.class)) {
IllegalArgumentException iae = X.cause(e, IllegalArgumentException.class);
logger.severe("Check arguments. " + errorMessage(iae));
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);
if (verbose)
err = e;
return EXIT_CODE_INVALID_ARGUMENTS;
}
logger.severe(errorMessage(e));
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_UNEXPECTED_ERROR);
err = e;
return EXIT_CODE_UNEXPECTED_ERROR;
} finally {
LocalDateTime endTime = LocalDateTime.now();
Duration diff = Duration.between(startTime, endTime);
if (nonNull(err))
logger.info("Error stack trace:" + System.lineSeparator() + X.getFullStackTrace(err));
logger.info("Control utility has completed execution at: " + endTime.format(formatter));
logger.info("Execution time: " + diff.toMillis() + " ms");
Arrays.stream(logger.getHandlers()).filter(handler -> handler instanceof FileHandler).forEach(Handler::close);
}
}
Aggregations