use of java.util.logging.Formatter in project zxing by zxing.
the class ServletContextLogHandler method publish.
@Override
public void publish(LogRecord record) {
Formatter formatter = getFormatter();
String message;
if (formatter == null) {
message = record.getMessage();
} else {
message = formatter.format(record);
}
Throwable throwable = record.getThrown();
if (throwable == null) {
context.log(message);
} else {
context.log(message, throwable);
}
}
use of java.util.logging.Formatter in project OpenAM by OpenRock.
the class DBHandler method configure.
private void configure() throws NullLocationException, FormatterInitException {
setFilter(null);
try {
setEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
Debug.error(tableName + ":DBHandler: unsupportedEncodingException ", e);
}
String bufferSize = lmanager.getProperty(LogConstants.BUFFER_SIZE);
if (bufferSize != null && bufferSize.length() > 0) {
try {
recCountLimit = Integer.parseInt(bufferSize);
} catch (NumberFormatException nfe) {
Debug.warning(tableName + ":DBHandler: NumberFormatException ", nfe);
if (Debug.messageEnabled()) {
Debug.message(tableName + ":DBHandler: Setting buffer size to 1");
}
recCountLimit = 1;
}
} else {
Debug.warning(tableName + ":DBHandler: Invalid buffer size: " + bufferSize);
if (Debug.messageEnabled()) {
Debug.message(tableName + ":DBHandler: Setting buffer size to 1");
}
recCountLimit = 1;
}
String recMaxDBMemStr = lmanager.getProperty(LogConstants.DB_MEM_MAX_RECS);
if (recMaxDBMemStr != null && recMaxDBMemStr.length() > 0) {
try {
recMaxDBMem = Integer.parseInt(recMaxDBMemStr);
} catch (NumberFormatException nfe) {
Debug.warning(tableName + ":DBHandler:recMaxDBMem (" + recMaxDBMemStr + "): NumberFormatException ", nfe);
if (Debug.messageEnabled()) {
Debug.message(tableName + ":DBHandler: Setting Max DB Mem Buffer Size to 2x (" + 2 * recCountLimit + ") the Buffer Size (" + recCountLimit + ")");
}
recMaxDBMem = 2 * recCountLimit;
}
} else {
Debug.warning(tableName + ":DBHandler: Invalid buffer size: " + bufferSize);
if (Debug.messageEnabled()) {
Debug.message(tableName + ":DBHandler: Defaulting Max DB Mem Buffer Size to 2x Buffer Size");
}
recMaxDBMem = 2 * recCountLimit;
}
if (recMaxDBMem < recCountLimit) {
Debug.warning(tableName + ":DBHandler:Maximum DB memory buffer size < Buffer Size, " + "setting to buffer size (" + recCountLimit + ")");
recMaxDBMem = recCountLimit;
}
String status = lmanager.getProperty(LogConstants.TIME_BUFFERING_STATUS);
if (status != null && status.equalsIgnoreCase("ON")) {
timeBufferingEnabled = true;
}
oraDataType = lmanager.getProperty(LogConstants.ORA_DBDATA_FIELDTYPE);
mysqlDataType = lmanager.getProperty(LogConstants.MYSQL_DBDATA_FIELDTYPE);
databaseURL = lmanager.getProperty(LogConstants.LOG_LOCATION);
if ((databaseURL == null) || (databaseURL.length() == 0)) {
throw new NullLocationException("Database URL location is null");
}
String strFormatter = com.sun.identity.log.LogManager.FORMATTER;
if ((strFormatter == null) || (strFormatter.length() == 0)) {
throw new FormatterInitException("Unable To Initialize DBFormatter");
}
userName = lmanager.getProperty(LogConstants.DB_USER);
if ((userName == null) || (userName.length() == 0)) {
throw new NullLocationException("userName is null");
}
password = lmanager.getProperty(LogConstants.DB_PASSWORD);
if ((password == null) || (password.length() == 0)) {
throw new NullLocationException("password not provided");
}
driver = lmanager.getProperty(LogConstants.DB_DRIVER);
if ((driver == null) || (driver.length() == 0)) {
throw new NullLocationException("driver not provided");
}
//
if (driver.toLowerCase().indexOf("oracle") != -1) {
isMySQL = false;
} else if (driver.toLowerCase().indexOf("mysql") != -1) {
isMySQL = true;
} else {
isMySQL = false;
Debug.warning(tableName + ":DBHandler:configure:assuming driver: '" + driver + "' is Oracle-compatible.");
}
try {
Class clz = Class.forName(strFormatter);
Formatter formatter = (Formatter) clz.newInstance();
setFormatter(formatter);
} catch (Exception e) {
// should be Invalid Formatter Exception
Debug.error(tableName + ":DBHandler: Could not load Formatter", e);
throw new FormatterInitException("Unable To Initialize DBFormatter " + e.getMessage());
}
}
use of java.util.logging.Formatter 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.Formatter in project google-cloud-java by GoogleCloudPlatform.
the class LoggingHandlerTest method testReportFormatError.
@Test
public void testReportFormatError() {
expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
expect(options.getService()).andReturn(logging);
logging.setFlushSeverity(Severity.ERROR);
expectLastCall().once();
logging.setWriteSynchronicity(Synchronicity.ASYNC);
expectLastCall().once();
replay(options, logging);
Formatter formatter = EasyMock.createStrictMock(Formatter.class);
RuntimeException ex = new RuntimeException();
ErrorManager errorManager = EasyMock.createStrictMock(ErrorManager.class);
errorManager.error(null, ex, ErrorManager.FORMAT_FAILURE);
expectLastCall().once();
LogRecord record = newLogRecord(Level.FINEST, MESSAGE);
expect(formatter.format(record)).andThrow(ex);
replay(errorManager, formatter);
Handler handler = new LoggingHandler(LOG_NAME, options);
handler.setLevel(Level.ALL);
handler.setErrorManager(errorManager);
handler.setFormatter(formatter);
handler.publish(record);
verify(errorManager, formatter);
}
use of java.util.logging.Formatter in project qpid-broker-j by apache.
the class Slf4jLoggingHandler method publish.
@Override
public void publish(final LogRecord record) {
MappedLevel level = convertLevel(record);
final Logger logger = getLogger(record.getLoggerName());
if (level.isEnabled(logger)) {
Formatter formatter = getFormatter();
try {
String message = formatter.format(record);
try {
level.log(logger, message);
} catch (RuntimeException e) {
reportError(null, e, ErrorManager.WRITE_FAILURE);
}
} catch (RuntimeException e) {
reportError(null, e, ErrorManager.FORMAT_FAILURE);
}
}
}
Aggregations