本文整理汇总了Java中java.util.logging.ErrorManager类的典型用法代码示例。如果您正苦于以下问题:Java ErrorManager类的具体用法?Java ErrorManager怎么用?Java ErrorManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ErrorManager类属于java.util.logging包,在下文中一共展示了ErrorManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeWriter
import java.util.logging.ErrorManager; //导入依赖的package包/类
protected void closeWriter() {
writerLock.writeLock().lock();
try {
if (writer == null)
return;
writer.write(getFormatter().getTail(this));
writer.flush();
writer.close();
writer = null;
date = "";
} catch (Exception e) {
reportError(null, e, ErrorManager.CLOSE_FAILURE);
} finally {
writerLock.writeLock().unlock();
}
}
示例2: flush
import java.util.logging.ErrorManager; //导入依赖的package包/类
/**
* Flush the writer.
*/
@Override
public void flush() {
writerLock.readLock().lock();
try {
if (writer == null)
return;
writer.flush();
} catch (Exception e) {
reportError(null, e, ErrorManager.FLUSH_FAILURE);
} finally {
writerLock.readLock().unlock();
}
}
示例3: close
import java.util.logging.ErrorManager; //导入依赖的package包/类
/**
* Close the currently open log file (if any).
*/
public void close() {
try {
if (writer == null)
return;
writer.write(getFormatter().getTail(this));
writer.flush();
writer.close();
writer = null;
date = "";
} catch (Exception e) {
reportError(null, e, ErrorManager.CLOSE_FAILURE);
}
}
示例4: open
import java.util.logging.ErrorManager; //导入依赖的package包/类
/**
* Open the new log file for the date specified by <code>date</code>.
*/
private void open() {
// Create the directory if necessary
File dir = new File(directory);
dir.mkdirs();
// Open the current log file
try {
String pathname = dir.getAbsolutePath() + File.separator +
prefix + date + suffix;
writer = new PrintWriter(new FileWriter(pathname, true), true);
writer.write(getFormatter().getHead(this));
} catch (Exception e) {
reportError(null, e, ErrorManager.OPEN_FAILURE);
writer = null;
}
}
示例5: publish
import java.util.logging.ErrorManager; //导入依赖的package包/类
@Override
public void publish(LogRecord record) {
if (isLoggable(record)) {
try {
if (this.logWriter instanceof LogWriterLogger) {
((LogWriterLogger) this.logWriter).log(record.getLevel().intValue(), getMessage(record),
record.getThrown());
} else {
((LogWriterImpl) this.logWriter).put(record.getLevel().intValue(), getMessage(record),
record.getThrown());
}
} catch (GemFireException ex) {
reportError(null, ex, ErrorManager.WRITE_FAILURE);
}
}
}
示例6: closeWriter
import java.util.logging.ErrorManager; //导入依赖的package包/类
protected void closeWriter() {
writerLock.writeLock().lock();
try {
if (writer == null)
return;
writer.write(getFormatter().getTail(this));
writer.flush();
writer.close();
writer = null;
date = "";
} catch (Exception e) {
reportError(null, e, ErrorManager.CLOSE_FAILURE);
} finally {
writerLock.writeLock().unlock();
}
}
示例7: flush
import java.util.logging.ErrorManager; //导入依赖的package包/类
/**
* Flush the writer.
*/
@Override
public void flush() {
writerLock.readLock().lock();
try {
if (writer == null)
return;
writer.flush();
} catch (Exception e) {
reportError(null, e, ErrorManager.FLUSH_FAILURE);
} finally {
writerLock.readLock().unlock();
}
}
示例8: rotate
import java.util.logging.ErrorManager; //导入依赖的package包/类
private synchronized void rotate()
{
Level oldLevel = getLevel();
setLevel(Level.OFF);
super.close();
if (desc)
rotateDesc();
else
rotateAsc();
try
{
open(files[0], false);
}
catch (IOException ix)
{
// We don't want to throw an exception here, but we
// report the exception to any registered ErrorManager.
reportError(null, ix, ErrorManager.OPEN_FAILURE);
}
setLevel(oldLevel);
}
示例9: findNextGeneration
import java.util.logging.ErrorManager; //导入依赖的package包/类
void findNextGeneration()
{
super.close();
for (int i = count - 1; i > 0; i--)
{
if (files[i].exists())
{
files[i].delete();
}
files[i - 1].renameTo(files[i]);
}
try
{
output = new MeasureOutputStream(new BufferedOutputStream(
new FileOutputStream(files[0])));
}
catch (FileNotFoundException e1)
{
this.getErrorManager().error("Error opening log file", e1,
ErrorManager.OPEN_FAILURE);
}
setOutputStream(output);
}
示例10: findNextGeneration
import java.util.logging.ErrorManager; //导入依赖的package包/类
private void findNextGeneration() {
super.close();
for ( int i = count - 1; i > 0; i-- ) {
if ( files[i].exists() ) {
files[i].delete();
}
files[i - 1].renameTo( files[i] );
}
try {
// $ANALYSIS-IGNORE
output = new MeasureOutputStream( new BufferedOutputStream( new FileOutputStream( files[0] ) ) );
} catch ( FileNotFoundException e1 ) {
// logging.1A=Error happened when open log file.
this.getErrorManager().error( "BatchedAsynchronousFileHandler Output stream open failure. ", //$NON-NLS-1$
e1, ErrorManager.OPEN_FAILURE );
}
setOutputStream( output );
}
示例11: publish
import java.util.logging.ErrorManager; //导入依赖的package包/类
@Override
public void publish(LogRecord record) {
// first check if this record should be logged (log level and filters are checked)
if (!isLoggable(record)) {
return;
}
JSONObject obj = new JSONObject();
try {
obj.put("@timestamp", Utils.iso8601(record.getMillis()));
obj.put("level", record.getLevel().toString());
obj.put("message", getFormatter().formatMessage(record));
obj.put("logger", record.getLoggerName());
obj.put("seqNum", record.getSequenceNumber());
obj.put("threadId", record.getThreadID());
obj.put("sourceClass", record.getSourceClassName());
obj.put("sourceMethod", record.getSourceMethodName());
if (record.getThrown() != null) {
obj.put("stacktrace", Utils.getStackTrace(record.getThrown()));
}
logsene.event(obj);
} catch (JSONException e) {
// should never happen, as exception is thrown when key in put() is null
reportError("Unable to construct json object", e, ErrorManager.GENERIC_FAILURE);
}
}
示例12: testConstructor_Properties
import java.util.logging.ErrorManager; //导入依赖的package包/类
public void testConstructor_Properties() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.MockHandler.level", "FINE");
p
.put("java.util.logging.MockHandler.filter", className
+ "$MockFilter");
p.put("java.util.logging.Handler.formatter", className
+ "$MockFormatter");
p.put("java.util.logging.MockHandler.encoding", "utf-8");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
assertEquals(LogManager.getLogManager().getProperty(
"java.util.logging.MockHandler.level"), "FINE");
assertEquals(LogManager.getLogManager().getProperty(
"java.util.logging.MockHandler.encoding"), "utf-8");
MockHandler h = new MockHandler();
assertSame(h.getLevel(), Level.ALL);
assertNull(h.getFormatter());
assertNull(h.getFilter());
assertNull(h.getEncoding());
assertTrue(h.getErrorManager() instanceof ErrorManager);
LogManager.getLogManager().reset();
}
示例13: createFormattedMessage
import java.util.logging.ErrorManager; //导入依赖的package包/类
private String createFormattedMessage(final ExtLogRecord record) {
final Formatter formatter = getFormatter();
try {
return formatter.format(record);
} catch (Exception e) {
reportError("Could not format message", e, ErrorManager.FORMAT_FAILURE);
return null;
}
}
示例14: createOutputStream
import java.util.logging.ErrorManager; //导入依赖的package包/类
private OutputStream createOutputStream() {
if (address != null || port >= 0) {
try {
switch (protocol) {
case SSL_TCP:
SslTcpOutputStream sos = new SslTcpOutputStream(address, port);
if (sos.isConnected()) {
return sos;
}
break;
case UDP:
return new UdpOutputStream(address, port);
case TCP:
default:
TcpOutputStream tos = new TcpOutputStream(address, port);
if (tos.isConnected()) {
return tos;
}
break;
}
} catch (IOException e) {
reportError("Failed to create socket output stream", e, ErrorManager.OPEN_FAILURE);
}
}
return null;
}
示例15: publish
import java.util.logging.ErrorManager; //导入依赖的package包/类
@Override
public void publish(LogRecord record) {
if (!isLoggable(record)) {
return;
}
// The formatter isn't necessarily thread-safe, so we synchronize around it.
String message;
synchronized (this) {
try {
message = getFormatter().format(record);
} catch (Exception ex) {
// We don't want to throw an exception here, but we
// report the exception to any registered ErrorManager.
reportError(null, ex, ErrorManager.FORMAT_FAILURE);
return;
}
}
VmApiProxyEnvironment environment = getThreadLocalEnvironment();
if (environment != null) {
environment.addLogRecord(convertLogRecord(record, message));
}
}