use of java.util.logging.Handler in project heron by twitter.
the class LoggingHelper method loggerInit.
/**
* Init java util logging
*
* @param level the Level of message to log
* @param isRedirectStdOutErr whether we redirect std out&err
* @param format the format to log
*/
public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException {
// Set the java util logging format
setLoggingFormat(format);
// Configure the root logger and its handlers so that all the
// derived loggers will inherit the properties
Logger rootLogger = Logger.getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
handler.setLevel(level);
}
rootLogger.setLevel(level);
if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) {
// zookeeper logging scares me. if people want this, we can patch to config-drive this
Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING);
}
if (isRedirectStdOutErr) {
// System.err to Logger, it results in an infinite loop.
for (Handler handler : rootLogger.getHandlers()) {
if (handler instanceof ConsoleHandler) {
rootLogger.removeHandler(handler);
}
}
// now rebind stdout/stderr to logger
Logger logger;
LoggingOutputStream los;
logger = Logger.getLogger("stdout");
los = new LoggingOutputStream(logger, StdOutErrLevel.STDOUT);
System.setOut(new PrintStream(los, true));
logger = Logger.getLogger("stderr");
los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR);
System.setErr(new PrintStream(los, true));
}
}
use of java.util.logging.Handler in project OpenAM by OpenRock.
the class SecureFileHandler method initializeVerifier.
/**
* Initialize SecureLog verifier
* @param verPass verifier password
* @param token AM token
*/
public static void initializeVerifier(AMPassword verPass, Object token) {
/* Remove the relevant verifier initialization code when deploying
* it finally. For the timebeing it will be done in the old way
* of doing it in the constructor thru initializeSecurity();
*/
try {
setVerPassword(verPass, token);
LogManager lmanager = LogManagerUtil.getLogManager();
String logPath = lmanager.getProperty(LogConstants.LOG_LOCATION);
if (!logPath.endsWith("/"))
logPath += "/";
LogManager manager = LogManagerUtil.getLogManager();
Enumeration e = manager.getLoggerNames();
while (e.hasMoreElements()) {
String FileName = (String) e.nextElement();
String verifierFileName = logPath + PREFIX + "ver." + FileName;
SecureLogHelper helper = getSecureLogHelper(FileName);
AMPassword logPassword = getLogPassword();
// explicit auditor role in DSAME to initialize ver.
if (helper != null) {
helper.initializeVerifier(verifierFileName, logPassword, verPassword);
try {
Debug.message(FileName + ":Trying to start the Verifier Thread");
Logger logger = (com.sun.identity.log.Logger) Logger.getLogger(FileName);
Handler[] handlers = logger.getHandlers();
((com.sun.identity.log.handlers.SecureFileHandler) handlers[0]).startVerifierThread();
Debug.message(FileName + ":Started Log Verifier thread");
} catch (Exception ex) {
Debug.error(FileName + ":Unable to start Verifier Thread", ex);
// throw custom exception
}
}
verificationInitialized = true;
}
} catch (Exception e) {
Debug.error("Error initializing Verification", e);
}
}
use of java.util.logging.Handler 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();
}
}
use of java.util.logging.Handler in project ACS by ACS-Community.
the class CommandCenter method main.
public static void main(String[] args) {
for (Handler h : Logger.getLogger("").getHandlers()) {
if (h instanceof ConsoleHandler) {
h.setFormatter(new Formatter() {
DateFormat df = new SimpleDateFormat("HH:mm:ss ");
@Override
public String format(LogRecord record) {
String s = df.format(new Date(record.getMillis()));
s += record.getMessage() + "\n";
return s;
}
});
}
}
// --- parse the command line
StartupOptions startupOptions = new StartupOptions();
for (int i = 0; i < args.length; i++) {
if (i == 0 && equalsOneOf(args[i], new String[] { "-h", "-help", "--help" })) {
printUsage(System.out);
return;
}
try {
if (equalsOneOf(args[i], new String[] { "-r", "-retrieve", "--retrieve" })) {
startupOptions.project = new File(args[++i]);
continue;
}
if (equalsOneOf(args[i], new String[] { "-g", "-geometry", "--geometry" })) {
StringTokenizer toky = new StringTokenizer(args[++i], "x+");
int w = Integer.parseInt(toky.nextToken());
int h = Integer.parseInt(toky.nextToken());
int x = Integer.parseInt(toky.nextToken());
int y = Integer.parseInt(toky.nextToken());
startupOptions.geometry = new Rectangle(x, y, w, h);
continue;
}
if (equalsOneOf(args[i], new String[] { "-x", "-noexit", "--noexit" })) {
startupOptions.doExitOnClose = false;
continue;
}
if (equalsOneOf(args[i], new String[] { "-useNativeSSH", "--useNativeSSH" })) {
log.warning("command line option '-useNativeSSH' no longer supported.");
continue;
}
if (equalsOneOf(args[i], new String[] { "-killNativeSSH", "--killNativeSSH" })) {
log.warning("command line option '-killNativeSSH' no longer supported.");
continue;
}
// msc (Oct 24, 2005): stand-alone argument should be considered a project name
// msc (Apr 28, 2006): alternatively it could be a manager location
String standalone = args[i];
if (standalone.length() > 8 && standalone.substring(0, 8).equalsIgnoreCase("corbaloc")) {
startupOptions.manager = standalone;
continue;
}
String mgrArg = MiscUtils.convertShortNotationToCorbaloc(standalone);
if (mgrArg != null) {
startupOptions.manager = mgrArg;
continue;
}
startupOptions.project = new File(standalone);
} catch (Exception exc) {
// ArrayIndexOutOfBounds, NumberFormat, ...
startupOptions = new StartupOptions();
log.warning("command line argument(s) invalid, some arguments may be ignored: " + Arrays.asList(args));
printUsage(System.err);
}
}
// --- instantiate appropriate logic
commandCenterLogic = new CommandCenterLogic();
commandCenterLogic.prepare(startupOptions);
if (startupOptions.project != null) {
commandCenterLogic.loadProject(startupOptions.project);
}
commandCenterLogic.go();
}
use of java.util.logging.Handler in project ACS by ACS-Community.
the class LocalOnlyAcsLogger method getInstance.
public static synchronized LocalOnlyAcsLogger getInstance(String namespace, Level level) {
if (instance == null) {
LogConfig testLogConfig = new LogConfig();
testLogConfig.setDefaultMinLogLevelLocal(AcsLogLevel.getNativeLevel(level).getAcsLevel());
instance = new LocalOnlyAcsLogger(namespace, testLogConfig);
instance.setUseParentHandlers(false);
Handler logHandler = new StdOutConsoleHandler(testLogConfig, namespace, null);
logHandler.setFormatter(new AcsXMLLogFormatter() {
public String format(LogRecord lr) {
String xml = super.format(lr);
return xml + '\n';
}
});
logHandler.setLevel(level);
instance.addHandler(logHandler);
}
return instance;
}
Aggregations