org.apache.log4j.spi.ErrorCode Java Examples
The following examples show how to use
org.apache.log4j.spi.ErrorCode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JMSQueueAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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); } }
Example #2
Source File: JMSQueueAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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); } }
Example #3
Source File: FileAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** 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?"); } }
Example #4
Source File: SocketAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
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); } }
Example #5
Source File: KinesisAppender.java From kinesis-log4j-appender with Apache License 2.0 | 6 votes |
/** * This method is called whenever a logging happens via logger.log(..) API * calls. Implementation for this appender will take in log events instantly * as long as the buffer is not full (as per user configuration). This call * will block if internal buffer is full until internal threads create some * space by publishing some of the records. * * If there is any error in parsing logevents, those logevents would be * dropped. */ @Override public void append(LoggingEvent logEvent) { if (initializationFailed) { error("Check the configuration and whether the configured stream " + streamName + " exists and is active. Failed to initialize kinesis log4j appender: " + name); return; } try { String message = layout.format(logEvent); ByteBuffer data = ByteBuffer.wrap(message.getBytes(encoding)); kinesisClient.putRecordAsync(new PutRecordRequest().withPartitionKey(UUID.randomUUID().toString()) .withStreamName(streamName).withData(data), asyncCallHander); } catch (Exception e) { LOGGER.error("Failed to schedule log entry for publishing into Kinesis stream: " + streamName); errorHandler.error("Failed to schedule log entry for publishing into Kinesis stream: " + streamName, e, ErrorCode.WRITE_FAILURE, logEvent); } }
Example #6
Source File: JMSAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** 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); } }
Example #7
Source File: KinesisAppender.java From kinesis-log4j-appender with Apache License 2.0 | 6 votes |
/** * 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(); }
Example #8
Source File: IMAppender.java From olat with Apache License 2.0 | 5 votes |
/** * Send the contents of the cyclic buffer as an IM message. */ protected void sendBuffer() { try { final StringBuilder buf = new StringBuilder(); final int len = cb.length(); for (int i = 0; i < len; i++) { final LoggingEvent event = cb.get(); buf.append(layout.format(event)); // if layout doesn't handle exception, the appender has to do it if (layout.ignoresThrowable()) { final String[] s = event.getThrowableStrRep(); if (s != null) { for (int j = 0; j < s.length; j++) { buf.append(Layout.LINE_SEP); buf.append(s[j]); } } } } if (chatroom) { groupchat.sendMessage(buf.toString()); } else { final Iterator iter = chats.iterator(); while (iter.hasNext()) { final Chat chat = (Chat) iter.next(); chat.sendMessage(buf.toString()); } } } catch (final Exception e) { errorHandler.error("Could not send message in IMAppender [" + name + "]", e, ErrorCode.GENERIC_FAILURE); } }
Example #9
Source File: QuietWriter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public void flush() { try { out.flush(); } catch (Exception e) { errorHandler.error("Failed to flush writer,", e, ErrorCode.FLUSH_FAILURE); } }
Example #10
Source File: IMAppender.java From olat with Apache License 2.0 | 5 votes |
/** * Options are activated and become effective only after calling this method. */ @Override public void activateOptions() { try { cb = new CyclicBuffer(bufferSize); // Create a connection to the XMPP server LogLog.debug("Stablishing connection with XMPP server"); con = new XMPPConnection(InstantMessagingModule.getConnectionConfiguration()); // Most servers require you to login before performing other tasks LogLog.debug("About to login as [" + username + "/" + password + "]"); con.connect(); con.login(username, password); // Start a conversation with IMAddress if (chatroom) { LogLog.debug("About to create ChatGroup"); groupchat = new MultiUserChat(con, (String) recipientsList.get(0)); LogLog.debug("About to join room"); groupchat.join(nickname != null ? nickname : username); } else { final Iterator iter = recipientsList.iterator(); while (iter.hasNext()) { chats.add(con.getChatManager().createChat((String) iter.next(), null)); } // chat = con.createChat(recipients); } } catch (final XMPPException xe) { errorHandler.error("Error while activating options for appender named [" + name + "] Could not connect to instant messaging server with user: " + getUsername(), xe, ErrorCode.GENERIC_FAILURE); } catch (final Exception e) { errorHandler.error("Error while activating options for appender named [" + name + "]", e, ErrorCode.GENERIC_FAILURE); } }
Example #11
Source File: IMAppender.java From olat with Apache License 2.0 | 5 votes |
/** * Send the contents of the cyclic buffer as an IM message. */ protected void sendBuffer() { try { final StringBuilder buf = new StringBuilder(); final int len = cb.length(); for (int i = 0; i < len; i++) { final LoggingEvent event = cb.get(); buf.append(layout.format(event)); // if layout doesn't handle exception, the appender has to do it if (layout.ignoresThrowable()) { final String[] s = event.getThrowableStrRep(); if (s != null) { for (int j = 0; j < s.length; j++) { buf.append(Layout.LINE_SEP); buf.append(s[j]); } } } } if (chatroom) { groupchat.sendMessage(buf.toString()); } else { final Iterator iter = chats.iterator(); while (iter.hasNext()) { final Chat chat = (Chat) iter.next(); chat.sendMessage(buf.toString()); } } } catch (final Exception e) { errorHandler.error("Could not send message in IMAppender [" + name + "]", e, ErrorCode.GENERIC_FAILURE); } }
Example #12
Source File: CLMLogFileAppender.java From helix with Apache License 2.0 | 5 votes |
public void activateOptions() { if (fileName != null) { try { fileName = getNewLogFileName(); setFile(fileName, fileAppend, bufferedIO, bufferSize); } catch (Exception e) { errorHandler.error("Error while activating log options", e, ErrorCode.FILE_OPEN_FAILURE); } } }
Example #13
Source File: SnmpTrapAppender.java From cloudstack with Apache License 2.0 | 5 votes |
@Override protected void append(LoggingEvent event) { SnmpEnhancedPatternLayout snmpEnhancedPatternLayout; if (getLayout() == null) { errorHandler.error("No layout set for the Appender named [" + getName() + ']', null, ErrorCode.MISSING_LAYOUT); return; } if (getLayout() instanceof SnmpEnhancedPatternLayout) { snmpEnhancedPatternLayout = (SnmpEnhancedPatternLayout)getLayout(); } else { return; } if (!isAsSevereAsThreshold(event.getLevel())) { return; } SnmpTrapInfo snmpTrapInfo = snmpEnhancedPatternLayout.parseEvent(event); if (snmpTrapInfo != null && !_snmpHelpers.isEmpty()) { for (SnmpHelper helper : _snmpHelpers) { try { helper.sendSnmpTrap(snmpTrapInfo); } catch (Exception e) { errorHandler.error(e.getMessage()); } } } }
Example #14
Source File: QuietWriter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public void write(String string) { if (string != null) { try { out.write(string); } catch (Exception e) { errorHandler.error("Failed to write [" + string + "].", e, ErrorCode.WRITE_FAILURE); } } }
Example #15
Source File: QuietWriter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public void flush() { try { out.flush(); } catch (Exception e) { errorHandler.error("Failed to flush writer,", e, ErrorCode.FLUSH_FAILURE); } }
Example #16
Source File: QuietWriter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public void write(String string) { if (string != null) { try { out.write(string); } catch (Exception e) { errorHandler.error("Failed to write [" + string + "].", e, ErrorCode.WRITE_FAILURE); } } }
Example #17
Source File: GelfJsonAppender.java From xian with Apache License 2.0 | 5 votes |
@Override protected void append(final LoggingEvent event) { GelfMessage gelfMessage = GelfMessageFactory.makeMessage(layout, event, this); String originalMessage; if (event != null && event.getMessage() != null) { originalMessage = event.getMessage().toString().trim(); if (originalMessage.startsWith("{")/* && originalMessage.endsWith("}")*/) { try { JSONObject fields = (JSONObject) JSON.parse(originalMessage); for (String key : fields.keySet()) { gelfMessage.getAdditonalFields().put(key, fields.get(key)); } } catch (JSONException ignored) { //ignored because the log content is not a json string. } } } if (getGelfSender() == null) { errorHandler.error("Could not send GELF message. Gelf Sender is not initialised and equals null"); } else { GelfSenderResult gelfSenderResult = getGelfSender().sendMessage(gelfMessage); if (!GelfSenderResult.OK.equals(gelfSenderResult)) { errorHandler.error("Error during sending GELF message. Error code: " + gelfSenderResult.getCode() + ".", gelfSenderResult.getException(), ErrorCode.WRITE_FAILURE); } } }
Example #18
Source File: IMAppender.java From olat with Apache License 2.0 | 5 votes |
/** * Options are activated and become effective only after calling this method. */ @Override public void activateOptions() { try { cb = new CyclicBuffer(bufferSize); // Create a connection to the XMPP server LogLog.debug("Stablishing connection with XMPP server"); con = new XMPPConnection(InstantMessagingModule.getConnectionConfiguration()); // Most servers require you to login before performing other tasks LogLog.debug("About to login as [" + username + "/" + password + "]"); con.connect(); con.login(username, password); // Start a conversation with IMAddress if (chatroom) { LogLog.debug("About to create ChatGroup"); groupchat = new MultiUserChat(con, (String) recipientsList.get(0)); LogLog.debug("About to join room"); groupchat.join(nickname != null ? nickname : username); } else { final Iterator iter = recipientsList.iterator(); while (iter.hasNext()) { chats.add(con.getChatManager().createChat((String) iter.next(), null)); } // chat = con.createChat(recipients); } } catch (final XMPPException xe) { errorHandler.error("Error while activating options for appender named [" + name + "] Could not connect to instant messaging server with user: " + getUsername(), xe, ErrorCode.GENERIC_FAILURE); } catch (final Exception e) { errorHandler.error("Error while activating options for appender named [" + name + "]", e, ErrorCode.GENERIC_FAILURE); } }
Example #19
Source File: DailyFileAppender1.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** If the a value for {@link #FILE_OPTION} is non-null, then {@link #setFile} is called with the values of {@link #FILE_OPTION} and {@link #APPEND_OPTION}. @since 0.8.1 */ public void activateOptions() { try { setFile(null, super.fileAppend); } catch(java.io.IOException e) { errorHandler.error("setFile(null,"+fileAppend+") call failed.", e, ErrorCode.FILE_OPEN_FAILURE); } }
Example #20
Source File: SMTPAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
InternetAddress[] parseAddress(String addressStr) { try { return InternetAddress.parse(addressStr, true); } catch(AddressException e) { errorHandler.error("Could not parse address ["+addressStr+"].", e, ErrorCode.ADDRESS_PARSE_FAILURE); return null; } }
Example #21
Source File: SMTPAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
InternetAddress getAddress(String addressStr) { try { return new InternetAddress(addressStr); } catch(AddressException e) { errorHandler.error("Could not parse address ["+addressStr+"].", e, ErrorCode.ADDRESS_PARSE_FAILURE); return null; } }
Example #22
Source File: CountingQuietWriter.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void write(String string) { try { out.write(string); count += string.length(); } catch(IOException e) { errorHandler.error("Write failure.", e, ErrorCode.WRITE_FAILURE); } }
Example #23
Source File: QuietWriter.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void flush() { try { out.flush(); } catch(IOException e) { errorHandler.error("Failed to flush writer,", e, ErrorCode.FLUSH_FAILURE); } }
Example #24
Source File: QuietWriter.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void write(String string) { try { out.write(string); } catch(IOException e) { errorHandler.error("Failed to write ["+string+"].", e, ErrorCode.WRITE_FAILURE); } }
Example #25
Source File: JDBCLog.java From MultimediaDesktop with Apache License 2.0 | 5 votes |
public void setDriver(String driverClass) { try { Class.forName(driverClass); } catch (Exception e) { errorHandler.error("Failed to load driver", e, ErrorCode.GENERIC_FAILURE); } }
Example #26
Source File: JDBCLog.java From MultimediaDesktop with Apache License 2.0 | 5 votes |
public void close() { flushBuffer(); try { if (connection != null && !connection.isClosed()) connection.close(); } catch (SQLException e) { errorHandler.error("Error closing connection", e, ErrorCode.GENERIC_FAILURE); } this.closed = true; }
Example #27
Source File: GelfAppender.java From xian with Apache License 2.0 | 5 votes |
@Override protected void append(LoggingEvent event) { GelfMessage gelfMessage = GelfMessageFactory.makeMessage(layout, event, this); if (getGelfSender() == null) { errorHandler.error("Could not send GELF message. Gelf Sender is not initialised and equals null"); } else { GelfSenderResult gelfSenderResult = getGelfSender().sendMessage(gelfMessage); if (!GelfSenderResult.OK.equals(gelfSenderResult)) { errorHandler.error("Error during sending GELF message. Error code: " + gelfSenderResult.getCode() + ".", gelfSenderResult.getException(), ErrorCode.WRITE_FAILURE); } } }
Example #28
Source File: GelfAppender.java From xian with Apache License 2.0 | 5 votes |
private String getLocalHostName() { String hostName = null; try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { errorHandler.error("Unknown local hostname", e, ErrorCode.GENERIC_FAILURE); } return hostName; }
Example #29
Source File: SocketAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void append(LoggingEvent event) { if(event == null) return; if(address==null) { errorHandler.error("No remote host is set for SocketAppender named \""+ this.name+"\"."); return; } if(oos != null) { try { if(locationInfo) { event.getLocationInformation(); } if (application != null) { event.setProperty("application", application); } oos.writeObject(event); //LogLog.debug("=========Flushing."); oos.flush(); if(++counter >= RESET_FREQUENCY) { counter = 0; // Failing to reset the object output stream every now and // then creates a serious memory leak. //System.err.println("Doing oos.reset()"); oos.reset(); } } catch(IOException e) { oos = null; LogLog.warn("Detected problem with connection: "+e); if(reconnectionDelay > 0) { fireConnector(); } else { errorHandler.error("Detected problem with connection, not reconnecting.", e, ErrorCode.GENERIC_FAILURE); } } } }
Example #30
Source File: KinesisAppender.java From kinesis-log4j-appender with Apache License 2.0 | 4 votes |
private void error(String message, Exception e) { LOGGER.error(message, e); errorHandler.error(message, e, ErrorCode.GENERIC_FAILURE); throw new IllegalStateException(message, e); }