本文整理汇总了Java中org.apache.log4j.spi.ErrorCode类的典型用法代码示例。如果您正苦于以下问题:Java ErrorCode类的具体用法?Java ErrorCode怎么用?Java ErrorCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ErrorCode类属于org.apache.log4j.spi包,在下文中一共展示了ErrorCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
void connect(InetAddress address, int port) {
if(this.address == null)
return;
try {
// First, close the previous connection if any.
cleanUp();
stw = new SyslogTcpWriter(new Socket(address, port).getOutputStream(), syslogFacility);
} catch(IOException e) {
if (e instanceof InterruptedIOException) {
Thread.currentThread().interrupt();
}
String msg = "Could not connect to remote log4j server at ["
+address.getHostName()+"].";
if(reconnectionDelay > 0) {
msg += " We will try again later.";
fireConnector(); // fire the connector thread
} else {
msg += " We are not retrying.";
errorHandler.error(msg, e, ErrorCode.GENERIC_FAILURE);
}
LogLog.error(msg);
}
}
示例2: append
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
@Override
protected void append(LoggingEvent event) {
if (this.layout == null) {
errorHandler.error("No layout for appender " + name,
null, ErrorCode.MISSING_LAYOUT);
return;
}
String message = this.layout.format(event);
Session session = sessions.get(event.getThreadName());
if (session != null) {
try {
session.getBasicRemote().sendText(gson.toJson(new Response(message, "", false)));
} catch (IOException ex) {
System.err.println("IOException " + ex.getMessage());
}
} else {
System.err.println("No session found for thread " + event.getThreadName());
}
}
示例3: append
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
/**
This method called by {@link AppenderSkeleton#doAppend} method to
do most of the real appending work. */
public void append(LoggingEvent event) {
if(!checkEntryConditions()) {
return;
}
try {
ObjectMessage msg = topicSession.createObjectMessage();
if(locationInfo) {
event.getLocationInformation();
}
msg.setObject(event);
topicPublisher.publish(msg);
} catch(Exception e) {
errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e,
ErrorCode.GENERIC_FAILURE);
}
}
示例4: connect
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
void connect(InetAddress address, int port) {
if(this.address == null)
return;
try {
// First, close the previous connection if any.
cleanUp();
oos = new ObjectOutputStream(new Socket(address, port).getOutputStream());
} catch(IOException e) {
String msg = "Could not connect to remote log4j server at ["
+address.getHostName()+"].";
if(reconnectionDelay > 0) {
msg += " We will try again later.";
fireConnector(); // fire the connector thread
} else {
msg += " We are not retrying.";
errorHandler.error(msg, e, ErrorCode.GENERIC_FAILURE);
}
LogLog.error(msg);
}
}
示例5: activateOptions
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
/**
If the value of <b>File</b> is not <code>null</code>, then {@link
#setFile} is called with the values of <b>File</b> and
<b>Append</b> properties.
@since 0.8.1 */
public
void activateOptions() {
if(fileName != null) {
try {
setFile(fileName, fileAppend, bufferedIO, bufferSize);
}
catch(java.io.IOException e) {
errorHandler.error("setFile("+fileName+","+fileAppend+") call failed.",
e, ErrorCode.FILE_OPEN_FAILURE);
}
} else {
//LogLog.error("File option not set for appender ["+name+"].");
LogLog.warn("File option not set for appender ["+name+"].");
LogLog.warn("Are you using FileAppender instead of ConsoleAppender?");
}
}
示例6: activateOptions
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
/**
* Overriding this method to activate the options for this class
* i.e. Looking up the Connection factory ...
*/
public void activateOptions() {
QueueConnectionFactory queueConnectionFactory;
try {
Context ctx = getInitialContext();
queueConnectionFactory = (QueueConnectionFactory) ctx.lookup(queueConnectionFactoryBindingName);
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup(queueBindingName);
queueSender = queueSession.createSender(queue);
queueConnection.start();
ctx.close();
} catch(Exception e) {
errorHandler.error("Error while activating options for appender named ["+name+
"].", e, ErrorCode.GENERIC_FAILURE);
}
}
示例7: append
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
/**
* This method called by {@link AppenderSkeleton#doAppend} method to
* do most of the real appending work. The LoggingEvent will be
* be wrapped in an ObjectMessage to be put on the JMS queue.
*/
public void append(LoggingEvent event) {
if(!checkEntryConditions()) {
return;
}
try {
ObjectMessage msg = queueSession.createObjectMessage();
msg.setObject(event);
queueSender.send(msg);
} catch(Exception e) {
errorHandler.error("Could not send message in JMSQueueAppender ["+name+"].", e,
ErrorCode.GENERIC_FAILURE);
}
}
示例8: parseAddress
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
InternetAddress[] parseAddress(String addressStr) {
try {
InternetAddress[] as = InternetAddress.parse(addressStr, true);
if (as != null && as.length > 0) {
for (InternetAddress a : as) {
a.setPersonal(a.getPersonal());
}
}
return as;
}catch (UnsupportedEncodingException e1){
errorHandler.error("Could not parse address ["+addressStr+"].", e1,
ErrorCode.ADDRESS_PARSE_FAILURE);
} catch(AddressException e) {
errorHandler.error("Could not parse address ["+addressStr+"].", e,
ErrorCode.ADDRESS_PARSE_FAILURE);
}
return null;
}
示例9: flushBuffer
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
/**
* loops through the buffer of LoggingEvents, gets a
* sql string from getLogStatement() and sends it to execute().
* Errors are sent to the errorHandler.
*
* If a statement fails the LoggingEvent stays in the buffer!
*/
public void flushBuffer() {
//Do the actual logging
removes.ensureCapacity(buffer.size());
for (Iterator i = buffer.iterator(); i.hasNext();) {
LoggingEvent logEvent = (LoggingEvent)i.next();
try {
String sql = getLogStatement(logEvent);
execute(sql);
}
catch (SQLException e) {
errorHandler.error("Failed to excute sql", e,
ErrorCode.FLUSH_FAILURE);
} finally {
removes.add(logEvent);
}
}
// remove from the buffer any events that were reported
buffer.removeAll(removes);
// clear the buffer of reported events
removes.clear();
}
示例10: connect
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
void connect(InetAddress address, int port) {
if(this.address == null)
return;
try {
// First, close the previous connection if any.
cleanUp();
oos = new ObjectOutputStream(new Socket(address, port).getOutputStream());
} catch(IOException e) {
if (e instanceof InterruptedIOException) {
Thread.currentThread().interrupt();
}
String msg = "Could not connect to remote log4j server at ["
+address.getHostName()+"].";
if(reconnectionDelay > 0) {
msg += " We will try again later.";
fireConnector(); // fire the connector thread
} else {
msg += " We are not retrying.";
errorHandler.error(msg, e, ErrorCode.GENERIC_FAILURE);
}
LogLog.error(msg);
}
}
示例11: activateOptions
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
/**
* @see org.apache.log4j.AppenderSkeleton#activateOptions()
*/
@Override
public void activateOptions() {
try {
// Close previous connections if reactivating
if (mongo != null) {
close();
}
initialize();
} catch (final Exception e) {
errorHandler.error("Unexpected exception while initialising MongoDbAppender.", e,
ErrorCode.GENERIC_FAILURE);
}
}
示例12: getPortNums
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
private List<Integer> getPortNums(final String[] ports) {
final List<Integer> portNums = new ArrayList<Integer>();
for (final String port : ports) {
try {
final Integer portNum = Integer.valueOf(port.trim());
if (portNum < 0) {
errorHandler.error(
"MongoDB appender port property can't contain a negative integer",
null, ErrorCode.ADDRESS_PARSE_FAILURE);
} else {
portNums.add(portNum);
}
} catch (final NumberFormatException e) {
errorHandler.error(
"MongoDB appender can't parse a port property value into an integer", e,
ErrorCode.ADDRESS_PARSE_FAILURE);
}
}
return portNums;
}
示例13: saveQueue
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
/**
* Method that creates query for OrientDB from the JSONObject event in the queue
* and executes it in the database
* @see {@link DataBaseAppender}{@link #saveQueue()}
*/
@Override
protected void saveQueue() {
// TODO Auto-generated method stub
if (queue.size() == 0)
return;
StringBuffer cmd = new StringBuffer("begin\n");
for (Object obj : queue) {
cmd.append("insert into " + table + " content " + ((JSONObject) obj).toString() + "\n");
}
cmd.append("commit\n");
//System.out.println(cmd);
try
{
database.command(new OCommandScript("sql", cmd.toString())).execute();
}
catch(Exception e){
errorHandler.error("Unexpected exception while saving events", e,
ErrorCode.GENERIC_FAILURE);
}
}
示例14: append
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
/**
* To a log event to the logger.
*
* @param event
* LoggingEvent.
*/
@Override
public void append( LoggingEvent event )
{
try
{
dirName = ( String ) event.getMDC( "SettopMac" );
fileName = ( String ) event.getMDC( "LogFileName" );
String logFileName = System.getProperty( "cats.home" ) + File.separator + dirName + File.separator
+ fileName;
setFile( logFileName, fileAppend, bufferedIO, bufferSize );
MDC.remove( "SettopMac" );
MDC.remove( "LogFileName" );
}
catch ( IOException ie )
{
errorHandler.error( "Error occured while setting file for the log level " + event.getLevel(), ie,
ErrorCode.FILE_OPEN_FAILURE );
}
super.append( event );
}
示例15: close
import org.apache.log4j.spi.ErrorCode; //导入依赖的package包/类
/**
* Closes this appender instance. Before exiting, the implementation tries to
* flush out buffered log events within configured shutdownTimeout seconds. If
* that doesn't finish within configured shutdownTimeout, it would drop all
* the buffered log events.
*/
@Override
public void close() {
ThreadPoolExecutor threadpool = (ThreadPoolExecutor) kinesisClient.getExecutorService();
threadpool.shutdown();
BlockingQueue<Runnable> taskQueue = threadpool.getQueue();
int bufferSizeBeforeShutdown = threadpool.getQueue().size();
boolean gracefulShutdown = true;
try {
gracefulShutdown = threadpool.awaitTermination(shutdownTimeout, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// we are anyways cleaning up
} finally {
int bufferSizeAfterShutdown = taskQueue.size();
if (!gracefulShutdown || bufferSizeAfterShutdown > 0) {
String errorMsg = "Kinesis Log4J Appender (" + name + ") waited for " + shutdownTimeout
+ " seconds before terminating but could send only " + (bufferSizeAfterShutdown - bufferSizeBeforeShutdown)
+ " logevents, it failed to send " + bufferSizeAfterShutdown
+ " pending log events from it's processing queue";
LOGGER.error(errorMsg);
errorHandler.error(errorMsg, null, ErrorCode.WRITE_FAILURE);
}
}
kinesisClient.shutdown();
}