Re: Log4j2 with syslog4j
can you please send your configuration *and* the actual exception message with traceback (NOT the code)? On Tuesday, May 10, 2022, 08:39:06 AM EDT, EDMONDO SENA wrote: The exception is the following: Which exception are you seeing? That block of code could throw about 5 different exceptions.Can Which exception are you seeing? That block of code could throw about 5 different exceptions. Can you post the actual exception and traceback?Sent from AT Yahoo Mail on AndroidOn Tue, May 10, 2022 at 5:19 AM, EDMONDO SENA wrote: Hi all,I am sending the logs of my subsystems to the SyslogServerbut I see that the following exception is raised in TCPSocketManager.Could you help me understand why? I am using log4j 2.17 and syslog0.9.46.The exception is this line 243 of the TCPSocketManager class:206 @SuppressWarnings("sync-override") // synchronization on "this"is done within the method207 @Override208 protected voidwrite(final byte[] bytes, final int offset, final int length, finalboolean immediateFlush) {209 if (socket == null) {210if (reconnector != null && !immediateFail) {211reconnector.latch();212 }213 if (socket == null){214 throw new AppenderLoggingException("Error writingto " + getName() + ": socket not available");215 }216}217 synchronized (this) {218 try {219 writeAndFlush(bytes, offset, length, immediateFlush);220} catch (final IOException causeEx) {221 final Stringconfig = inetAddress + ":" + port;222 if (retry & == null) {223 reconnector =createReconnector();224 try {225 reconnector.reconnect();226 } catch (finalIOException reconnEx) {227 LOGGER.debug("Cannotreestablish socket connection to {}: {}; starting reconnector thread{}",228 config,reconnEx.getLocalizedMessage(), reconnector.getName(), reconnEx);229 reconnector.start();230throw new AppenderLoggingException(231String.format("Error sending to %s for %s", getName(), config),causeEx);232 }233 try {234 writeAndFlush(bytes, offset, length,immediateFlush);235 } catch (final IOException e){236 throw new AppenderLoggingException(237 String.format("Error writing to %s afterreestablishing connection for %s", getName(),238 config),239causeEx);240 }241 return;242 }243 final String message =String.format("Error writing to %s for connection %s", getName(),config);244 throw new AppenderLoggingException(message,causeEx);245 }246 }247 }Thanks in advance. //Edmondo.you post the actual exception and traceback?
Re: Log4j2 with syslog4j
Which exception are you seeing? That block of code could throw about 5 different exceptions. Can you post the actual exception and traceback? Sent from AT Yahoo Mail on Android On Tue, May 10, 2022 at 5:19 AM, EDMONDO SENA wrote: Hi all, I am sending the logs of my subsystems to the SyslogServer but I see that the following exception is raised in TCPSocketManager. Could you help me understand why? I am using log4j 2.17 and syslog0.9.46. The exception is this line 243 of the TCPSocketManager class: 206 @SuppressWarnings("sync-override") // synchronization on "this" is done within the method207 @Override208 protected void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) {209 if (socket == null) {210 if (reconnector != null && !immediateFail) {211 reconnector.latch();212 }213 if (socket == null) {214 throw new AppenderLoggingException("Error writing to " + getName() + ": socket not available");215 }216 }217 synchronized (this) {218 try {219 writeAndFlush(bytes, offset, length, immediateFlush);220 } catch (final IOException causeEx) {221 final String config = inetAddress + ":" + port;222 if (retry && reconnector == null) {223 reconnector = createReconnector();224 try {225 reconnector.reconnect();226 } catch (final IOException reconnEx) {227 LOGGER.debug("Cannot reestablish socket connection to {}: {}; starting reconnector thread {}",228 config, reconnEx.getLocalizedMessage(), reconnector.getName(), reconnEx);229 reconnector.start();230 throw new AppenderLoggingException(231 String.format("Error sending to %s for %s", getName(), config), causeEx);232 }233 try {234 writeAndFlush(bytes, offset, length, immediateFlush);235 } catch (final IOException e) {236 throw new AppenderLoggingException(237 String.format("Error writing to %s after reestablishing connection for %s", getName(),238 config),239 causeEx);240 }241 return;242 }243 final String message = String.format("Error writing to %s for connection %s", getName(), config);244 throw new AppenderLoggingException(message, causeEx);245 }246 }247 } Thanks in advance. //Edmondo.
Re: authapi.jar with Log4j2
...and make sure that the log4j v1 jar files are NOT on the classpath. On Friday, October 29, 2021, 11:21:52 AM EDT, Gary Gregory wrote: Make sure the log4j 2 jars are first on the class path and do not include any log4j 1 jars. Gary On Fri, Oct 29, 2021, 11:18 EDMONDO SENA wrote: > > it has already been done and it doesn't work! > > This is the exception: > > Exception in thread "main" > Java.lang.NoSuchMethodError:org.apache.log4j.spi.LocationInfo. > > > > > On 2021/10/29 15:09:59, Doug Wegscheid wrote: > > Put the log4j-1.2-api.jar on the classpath along with the other > necessary log4j2 jars, and configure log4j2. > > > > Sent from AT Yahoo Mail on Android > > > > On Fri, Oct 29, 2021 at 11:07 AM, EDMONDO SENA > wrote: it's not that simple one, a thing is to write, one thing is to > understand what to do! Said so it seems a simplistic discussion. > > > > //Edmondo. > > > > > > > > On 2021/10/29 14:13:31, Doug Wegscheid > wrote: > > > You can your existing authapi.jar: > > > "Log4j 2 provides support for the Log4j 1 logging methods by providing > alternate implementations of the classes containing those methods. These > classes may be found in the log4j-1.2-api jar distributed with the project. > All calls to perform logging will result in the data passed to the logging > methods to be forwarded to the Log4j2 API where they can be processed by > implementations of the Log4j 2 API." > > > > > > Sent from AT Yahoo Mail on Android > > > > > > On Fri, Oct 29, 2021 at 9:04 AM, EDMONDO SENA > wrote: I have already seen this site but I have not found any answer to my > problem. > > > > > > //Edmondo. > > > > > > > > > > > > On 2021/10/29 12:52:55, Gary Gregory wrote: > > > > Edmondo, > > > > > > > > Please see > https://logging.apache.org/log4j/2.x/manual/compatibility.html > > > > > > > > Gary > > > > > > > > On Fri, Oct 29, 2021, 04:22 EDMONDO SENA wrote: > > > > > > > > > > > > > > Good Morning, > > > > > > > > > > authapi.jar is a 3pp library which uses old log4 inside. > > > > > Is there any way to get authapi.jar to work with log4j 2? > > > > > > > > > > What can I do to make them work together? > > > > > Do I need to download a new authapi.jar version for log4j2? > > > > > > > > > > Thanks in advance. > > > > > Kind regards. > > > > > > > > > > //Edmondo. > > > > > > > > > > > > > > > > - > > > > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > > > > For additional commands, e-mail: > log4j-user-h...@logging.apache.org > > > > > > > > > > > > > > > > > > > > - > > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > > > > > > > > - > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > >
Re: authapi.jar with Log4j2
Put the log4j-1.2-api.jar on the classpath along with the other necessary log4j2 jars, and configure log4j2. Sent from AT Yahoo Mail on Android On Fri, Oct 29, 2021 at 11:07 AM, EDMONDO SENA wrote: it's not that simple one, a thing is to write, one thing is to understand what to do! Said so it seems a simplistic discussion. //Edmondo. On 2021/10/29 14:13:31, Doug Wegscheid wrote: > You can your existing authapi.jar: > "Log4j 2 provides support for the Log4j 1 logging methods by providing > alternate implementations of the classes containing those methods. These > classes may be found in the log4j-1.2-api jar distributed with the project. > All calls to perform logging will result in the data passed to the logging > methods to be forwarded to the Log4j2 API where they can be processed by > implementations of the Log4j 2 API." > > Sent from AT Yahoo Mail on Android > > On Fri, Oct 29, 2021 at 9:04 AM, EDMONDO SENA wrote: I >have already seen this site but I have not found any answer to my problem. > > //Edmondo. > > > > On 2021/10/29 12:52:55, Gary Gregory wrote: > > Edmondo, > > > > Please see https://logging.apache.org/log4j/2.x/manual/compatibility.html > > > > Gary > > > > On Fri, Oct 29, 2021, 04:22 EDMONDO SENA wrote: > > > > > > > > Good Morning, > > > > > > authapi.jar is a 3pp library which uses old log4 inside. > > > Is there any way to get authapi.jar to work with log4j 2? > > > > > > What can I do to make them work together? > > > Do I need to download a new authapi.jar version for log4j2? > > > > > > Thanks in advance. > > > Kind regards. > > > > > > //Edmondo. > > > > > > > > > - > > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > > > > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: authapi.jar with Log4j2
You can your existing authapi.jar: "Log4j 2 provides support for the Log4j 1 logging methods by providing alternate implementations of the classes containing those methods. These classes may be found in the log4j-1.2-api jar distributed with the project. All calls to perform logging will result in the data passed to the logging methods to be forwarded to the Log4j2 API where they can be processed by implementations of the Log4j 2 API." Sent from AT Yahoo Mail on Android On Fri, Oct 29, 2021 at 9:04 AM, EDMONDO SENA wrote: I have already seen this site but I have not found any answer to my problem. //Edmondo. On 2021/10/29 12:52:55, Gary Gregory wrote: > Edmondo, > > Please see https://logging.apache.org/log4j/2.x/manual/compatibility.html > > Gary > > On Fri, Oct 29, 2021, 04:22 EDMONDO SENA wrote: > > > > > Good Morning, > > > > authapi.jar is a 3pp library which uses old log4 inside. > > Is there any way to get authapi.jar to work with log4j 2? > > > > What can I do to make them work together? > > Do I need to download a new authapi.jar version for log4j2? > > > > Thanks in advance. > > Kind regards. > > > > //Edmondo. > > > > > > - > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: STDERR to log file
Look at https://stackoverflow.com/questions/1200175/log4j-redirect-stdout-to-dailyrollingfileappender Sent from AT Yahoo Mail on Android On Tue, Jul 21, 2020 at 3:00 AM, Sumit Bhardwaj wrote: Hello Experts, Is there a way to redirect STDERR to log file using log4j2? I am aware of the redirection approach, but with that the size of the output file become uncontrollable for 24X7 running applications. Thanks in advance! Best Sumit
Re: loggerConfig.getAppenderRefs().clear()
also, would a FailoverAppender with the external appender being the primary be a solution? On Wednesday, March 25, 2020, 10:58:16 AM EDT, EDMONDO SENA wrote: 1) Do the external appenders come and go, or do we know ahead of time if they are available? No, come and go! 2) Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution? More or less yes. On 2020/03/25 14:53:08, Doug Wegscheid wrote: > ah. a couple of solutions present themself (and hopefully someone more >conversant with log4j4 can chime in). > Would a RoutingAppender() that knows if external or internal logging is to be > done and then routes messages to the appropriate appender a solution? > Do the external appenders come and go, or do we know ahead of time if they > are available? > > > > On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA > wrote: > > In order to disable local logging when the external logging is enabled. > So, remove all local appenders and disable local logging for re-enabling the > delivery towards another system to run-time. > > > On 2020/03/25 14:29:26, Doug Wegscheid wrote: > > upon examination, I see that clearAppenders() is not public, so that won't > >work. > > There is probably a way to do what you want, if you can tell us why you > > need to clear the appenders. > > > > On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA > > wrote: > > > > > > Can you explain me how can i do it? > > > > Regards. > > > > > > > > > > On 2020/03/25 14:18:03, Doug Wegscheid wrote: > > > you are trying to clear the list of appenderRefs. Are you trying to call > > >clearAppenders() instead of clear()? > > > > > > On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA > > > wrote: > > > > > > > > > Why this instruction goes in UnsupportedOperationException? > > > > > > List value = loggerConfig.getAppenderRefs(); > > > value.clear(); > > > > > > - > > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > > > > > - > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: loggerConfig.getAppenderRefs().clear()
Matt, thanks for chiming in. I was running some test cases, and I saw that exact behaviour: lost messages when doing the ctx.update(). On Wednesday, March 25, 2020, 10:58:17 AM EDT, Matt Sicker wrote: Appenders shouldn't be directly modified like that as it would lead to a loss of log events during that operation. The appropriate ways to programmatically initialize configuration is documented here: https://logging.apache.org/log4j/2.x/manual/customconfig.html#Configurator On Wed, 25 Mar 2020 at 09:53, Doug Wegscheid wrote: > > ah. a couple of solutions present themself (and hopefully someone more >conversant with log4j4 can chime in). > Would a RoutingAppender() that knows if external or internal logging is to be > done and then routes messages to the appropriate appender a solution? > Do the external appenders come and go, or do we know ahead of time if they > are available? > > > > On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA > wrote: > > In order to disable local logging when the external logging is enabled. > So, remove all local appenders and disable local logging for re-enabling the > delivery towards another system to run-time. > > > On 2020/03/25 14:29:26, Doug Wegscheid wrote: > > upon examination, I see that clearAppenders() is not public, so that won't > >work. > > There is probably a way to do what you want, if you can tell us why you > > need to clear the appenders. > > > > On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA > > wrote: > > > > > > Can you explain me how can i do it? > > > > Regards. > > > > > > > > > > On 2020/03/25 14:18:03, Doug Wegscheid wrote: > > > you are trying to clear the list of appenderRefs. Are you trying to call > > >clearAppenders() instead of clear()? > > > > > > On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA > > > wrote: > > > > > > > > > Why this instruction goes in UnsupportedOperationException? > > > > > > List value = loggerConfig.getAppenderRefs(); > > > value.clear(); > > > > > > - > > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > > > > > - > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > -- Matt Sicker - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: loggerConfig.getAppenderRefs().clear()
Matt's suggestion works. You can make a routing appender that will switch between appenders under program control. Example of something that switches between two different ConsoleAppenders Configuration: Component to do the ablookup: package org.wegscd; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.lookup.StrLookup; @Plugin(name = "ablookup", category = StrLookup.CATEGORY) public class ABLookup implements StrLookup { static String ab; public ABLookup() { System.out.println ("ABLookup instantiated"); } @Override public String lookup(String key) { if (key.equalsIgnoreCase("ab")) { return ab; } return null; } @Override public String lookup(LogEvent event, String key) { return lookup(key); } public static void setAB(String _ab) { ab = _ab; } } Test Program: import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.wegscd.ABLookup; public class MainAB { static Logger logger; public static void main(String[] args) { System.setProperty("log4j2.configurationFile", "ab.xml"); logger = LoggerFactory.getLogger(MainAB.class); logger.warn ("Start (goes nowhere, since ab is not set"); ABLookup.setAB("A"); logger.info("this should go to ConsoleA"); ABLookup.setAB("B"); logger.info("this should go to ConsoleB"); logger.warn ("Done"); } } Output ABLookup instantiated ConsoleA this should go to ConsoleA ConsoleB this should go to ConsoleB ConsoleB Done On Wednesday, March 25, 2020, 11:03:48 AM EDT, Matt Sicker wrote: Take a look at this: https://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender This appender is extremely flexible for that use case. I'd recommend avoiding the use of an inline script (JavaScript or Groovy) unless absolutely necessary as that's likely the slowest routing mechanism (though you could always benchmark that). On Wed, 25 Mar 2020 at 09:58, EDMONDO SENA wrote: > > > 1) Do the external appenders come and go, or do we know ahead of time if > they are available? > No, come and go! > > 2) Would a RoutingAppender() that knows if external or internal logging is > to be done and then routes messages to the appropriate appender a solution? > > More or less yes. > > > On 2020/03/25 14:53:08, Doug Wegscheid wrote: > > ah. a couple of solutions present themself (and hopefully someone more > >conversant with log4j4 can chime in). > > Would a RoutingAppender() that knows if external or internal logging is to > > be done and then routes messages to the appropriate appender a solution? > > Do the external appenders come and go, or do we know ahead of time if they > > are available? > > > > > > > > On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA > > wrote: > > > > In order to disable local logging when the external logging is enabled. > > So, remove all local appenders and disable local logging for re-enabling > > the delivery towards another system to run-time. > > > > > > On 2020/03/25 14:29:26, Doug Wegscheid wrote: > > > upon examination, I see that clearAppenders() is not public, so that > > >won't work. > > > There is probably a way to do what you want, if you can tell us why you > > > need to clear the appenders. > > > > > > On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA > > > wrote: > > > > > > > > > Can you explain me how can i do it? > > > > > > Regards. > > > > > > > > > > > > > > > On 2020/03/25 14:18:03, Doug Wegscheid wrote: > > > > you are trying to clear the list of appenderRefs. Are you trying to > > > >call clearAppenders() instead of clear()? > > > > > > > > On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA > > > > wrote: > > > > > > > > > > > > Why this instruction goes in UnsupportedOperationException? > > > > > > > > List value = loggerConfig.getAppenderRefs(); > > > > value.clear(); > > > > > > > > ---
Re: loggerConfig.getAppenderRefs().clear()
ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in). Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution? Do the external appenders come and go, or do we know ahead of time if they are available? On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA wrote: In order to disable local logging when the external logging is enabled. So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time. On 2020/03/25 14:29:26, Doug Wegscheid wrote: > upon examination, I see that clearAppenders() is not public, so that won't >work. > There is probably a way to do what you want, if you can tell us why you need > to clear the appenders. > > On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA > wrote: > > > Can you explain me how can i do it? > > Regards. > > > > > On 2020/03/25 14:18:03, Doug Wegscheid wrote: > > you are trying to clear the list of appenderRefs. Are you trying to call > >clearAppenders() instead of clear()? > > > > On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA > > wrote: > > > > > > Why this instruction goes in UnsupportedOperationException? > > > > List value = loggerConfig.getAppenderRefs(); > > value.clear(); > > > > - > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: loggerConfig.getAppenderRefs().clear()
upon examination, I see that clearAppenders() is not public, so that won't work. There is probably a way to do what you want, if you can tell us why you need to clear the appenders. On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA wrote: Can you explain me how can i do it? Regards. On 2020/03/25 14:18:03, Doug Wegscheid wrote: > you are trying to clear the list of appenderRefs. Are you trying to call >clearAppenders() instead of clear()? > > On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA > wrote: > > > Why this instruction goes in UnsupportedOperationException? > > List value = loggerConfig.getAppenderRefs(); > value.clear(); > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: loggerConfig.getAppenderRefs().clear()
you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()? On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA wrote: Why this instruction goes in UnsupportedOperationException? List value = loggerConfig.getAppenderRefs(); value.clear(); - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: removeAllAppenders() Log4j2
I understand that, but am trying to help you find a solution that works with 2.x. While your code removed all the appenders in 1,x, that might not be necessary under 2.x, but I can't help you with that if you don't share more information about why the appenders need to be removed. If you share that information, I (or someone else) might be able to help you get your application converted over to 2.x. That being said, you are welcome to try the #clearAppenders(). On Wednesday, March 25, 2020, 9:16:47 AM EDT, EDMONDO SENA wrote: Sorry but my question is: Is possible to use in some way removeAllAppenders? Why this instruction has been deleted? On 2020/03/25 13:14:52, Doug Wegscheid wrote: > why do you need to remove all appenders? what happens if you do not? > > On Wednesday, March 25, 2020, 9:12:45 AM EDT, EDMONDO SENA > wrote: > > > When you close or switch off our system we've to remove all appenders. > In log4j this instruction was possible! > > > On 2020/03/25 12:59:30, Doug Wegscheid wrote: > > However: from > >https://logging.apache.org/log4j/log4j-2.1/manual/configuration.html: > > | Note that unlike Log4j 1.x, the public Log4j 2 API does not expose > > methods to add, modify or remove appenders and filters or manipulate the > > configuration in any way. > > > > *Why* do you need to remove the appenders? Perhaps there is another way to > > do whatever needs doing? > > > > > > > > > > > > On Wednesday, March 25, 2020, 8:34:56 AM EDT, EDMONDO SENA > > wrote: > > > > Hello, > > > > Is there a similar functionality for Log4j2 that remove All appenders for > > Loggers? > > Kind regards. > > > > - > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: removeAllAppenders() Log4j2
why do you need to remove all appenders? what happens if you do not? On Wednesday, March 25, 2020, 9:12:45 AM EDT, EDMONDO SENA wrote: When you close or switch off our system we've to remove all appenders. In log4j this instruction was possible! On 2020/03/25 12:59:30, Doug Wegscheid wrote: > However: from >https://logging.apache.org/log4j/log4j-2.1/manual/configuration.html: > | Note that unlike Log4j 1.x, the public Log4j 2 API does not expose methods > to add, modify or remove appenders and filters or manipulate the > configuration in any way. > > *Why* do you need to remove the appenders? Perhaps there is another way to do > whatever needs doing? > > > > > > On Wednesday, March 25, 2020, 8:34:56 AM EDT, EDMONDO SENA > wrote: > > Hello, > > Is there a similar functionality for Log4j2 that remove All appenders for > Loggers? > Kind regards. > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: removeAllAppenders() Log4j2
Are you looking at clearAppenders()? On Wednesday, March 25, 2020, 8:56:57 AM EDT, EDMONDO SENA wrote: I think It removes the appender single by single not all in one instruction! On 2020/03/25 12:46:19, Doug Wegscheid wrote: > I googled for "log4j2 remove all appenders" and found this: > How to remove appender from logger in log4j2 programmatically? > > | > | > | > | | | > > | > > | > | > | | > How to remove appender from logger in log4j2 programmatically? > > Is there any way I can remove appender from a logger in log4j2 > programmatically ? The website says "Log4j 2 API... > | > > | > > | > > > is that helpful? > One of the answers does indicate that removing all appenders might not be > necessary, perhaps you need smarter filtering? > > > On Wednesday, March 25, 2020, 8:34:56 AM EDT, EDMONDO SENA > wrote: > > Hello, > > Is there a similar functionality for Log4j2 that remove All appenders for > Loggers? > Kind regards. > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: removeAllAppenders() Log4j2
However: from https://logging.apache.org/log4j/log4j-2.1/manual/configuration.html: | Note that unlike Log4j 1.x, the public Log4j 2 API does not expose methods to add, modify or remove appenders and filters or manipulate the configuration in any way. *Why* do you need to remove the appenders? Perhaps there is another way to do whatever needs doing? On Wednesday, March 25, 2020, 8:34:56 AM EDT, EDMONDO SENA wrote: Hello, Is there a similar functionality for Log4j2 that remove All appenders for Loggers? Kind regards. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: removeAllAppenders() Log4j2
I googled for "log4j2 remove all appenders" and found this: How to remove appender from logger in log4j2 programmatically? | | | | | | | | | | | How to remove appender from logger in log4j2 programmatically? Is there any way I can remove appender from a logger in log4j2 programmatically ? The website says "Log4j 2 API... | | | is that helpful? One of the answers does indicate that removing all appenders might not be necessary, perhaps you need smarter filtering? On Wednesday, March 25, 2020, 8:34:56 AM EDT, EDMONDO SENA wrote: Hello, Is there a similar functionality for Log4j2 that remove All appenders for Loggers? Kind regards. - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: getAppender
There is no appender named "LoggerLog4jDebug". The appender is probably "LoggerLog4jDebugAppender"? On Thursday, March 19, 2020, 11:19:35 AM EDT, EDMONDO SENA wrote: The code is: try { ConfigurationSource source = new ConfigurationSource(new FileInputStream("Log4jApache.xml")); Configurator.initialize(null, source); } catch (IOException e) { System.err.println("Error while initializing log4j from file: log4j.xml"); e.printStackTrace(); } LoggerContext context = (LoggerContext) LogManager.getContext(false); Appender appender = context.getConfiguration().getAppender("LoggerLog4jDebug"); System.out.println("appender = " + appender); File xml is:
Re: Defer evaluation of FileAppender filename until file is opened?
Found it: need to make sure we have a key for the route, even if it won't be used. Added pattern="x" to Works perfectly! On Wednesday, February 5, 2020, 2:48:30 AM EST, Doug Wegscheid wrote: That looks promising, but I am having an issue with the RoutingAppender throwing an NPE when the first event gets past the filter on the RoutingAppender: 2020-02-05 02:38:08,798 Log4j2-TF-1-AsyncLogger[AsyncContext@2cdf8d8a]-1 ERROR An exception occurred processing Appender MyRoute java.lang.NullPointerException at java.base/java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936) at org.apache.logging.log4j.core.appender.routing.RoutingAppender.getAppender(RoutingAppender.java:286) at org.apache.logging.log4j.core.appender.routing.RoutingAppender.getControl(RoutingAppender.java:249) at org.apache.logging.log4j.core.appender.routing.RoutingAppender.append(RoutingAppender.java:228) at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156) at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129) at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120) at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84) at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:543) at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:502) at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:485) at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:473) at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:98) at org.apache.logging.log4j.core.async.AsyncLogger.actualAsyncLog(AsyncLogger.java:485) at org.apache.logging.log4j.core.async.RingBufferLogEvent.execute(RingBufferLogEvent.java:161) at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:46) at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:29) at com.lmax.disruptor.BatchEventProcessor.processEvents(BatchEventProcessor.java:168) at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:125) at java.base/java.lang.Thread.run(Thread.java:834) I suspect I am missing something in my configuration? On Wednesday, February 5, 2020, 12:14:13 AM EST, Ralph Goers wrote: Yes, so your best bet is to use the RoutingAppender and only supply a default Route. The Appender itself will only be created when something is logged to the Route. Ralph > On Feb 4, 2020, at 6:55 PM, Doug Wegscheid wrote: > > yes, that works as designed, but does not resolve my problem. The filename is > not evaluated when the first event is written (after we have a good > date/time), it's evaluated when log4j2 is configured (which is before when we > have a good date/time set). > On Tuesday, February 4, 2020, 08:19:16 PM EST, Ralph Goers > wrote: > > The FileAppender has an option named createOnDemand. If you set it to true > then the file will only be created when a log event is written to it. See > http://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender > <http://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender>. > > Ralph > > > >> On Feb 4, 2020, at 2:10 PM, Doug Wegscheid wrote: >> >> >> I am trying to have log4j2 write log files with names mmdd-HHMMSS.log, >> but not start writing the file until we have a good system time (>year >> 1986). I have an application running on a system that boots up, and takes a >> while to get the correct time; until that happens, the system thinks it's >> back in 1970, and there really is no point to writing a log file with a bum >> date. >> >> Using a custom filter, I can get the FileAppender to not write any events >> until the system time is set. I can get the FileAppender to not open the >> file until the first event is passed by the custom filter >> (createOnDemand="true"). Using Log4J2 - assigning file appender filename at >> runtime, I can get th
Re: Defer evaluation of FileAppender filename until file is opened?
That looks promising, but I am having an issue with the RoutingAppender throwing an NPE when the first event gets past the filter on the RoutingAppender: 2020-02-05 02:38:08,798 Log4j2-TF-1-AsyncLogger[AsyncContext@2cdf8d8a]-1 ERROR An exception occurred processing Appender MyRoute java.lang.NullPointerException at java.base/java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936) at org.apache.logging.log4j.core.appender.routing.RoutingAppender.getAppender(RoutingAppender.java:286) at org.apache.logging.log4j.core.appender.routing.RoutingAppender.getControl(RoutingAppender.java:249) at org.apache.logging.log4j.core.appender.routing.RoutingAppender.append(RoutingAppender.java:228) at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156) at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129) at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120) at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84) at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:543) at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:502) at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:485) at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:473) at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:98) at org.apache.logging.log4j.core.async.AsyncLogger.actualAsyncLog(AsyncLogger.java:485) at org.apache.logging.log4j.core.async.RingBufferLogEvent.execute(RingBufferLogEvent.java:161) at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:46) at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:29) at com.lmax.disruptor.BatchEventProcessor.processEvents(BatchEventProcessor.java:168) at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:125) at java.base/java.lang.Thread.run(Thread.java:834) I suspect I am missing something in my configuration? On Wednesday, February 5, 2020, 12:14:13 AM EST, Ralph Goers wrote: Yes, so your best bet is to use the RoutingAppender and only supply a default Route. The Appender itself will only be created when something is logged to the Route. Ralph > On Feb 4, 2020, at 6:55 PM, Doug Wegscheid wrote: > > yes, that works as designed, but does not resolve my problem. The filename is > not evaluated when the first event is written (after we have a good > date/time), it's evaluated when log4j2 is configured (which is before when we > have a good date/time set). > On Tuesday, February 4, 2020, 08:19:16 PM EST, Ralph Goers > wrote: > > The FileAppender has an option named createOnDemand. If you set it to true > then the file will only be created when a log event is written to it. See > http://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender > <http://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender>. > > Ralph > > > >> On Feb 4, 2020, at 2:10 PM, Doug Wegscheid wrote: >> >> >> I am trying to have log4j2 write log files with names mmdd-HHMMSS.log, >> but not start writing the file until we have a good system time (>year >> 1986). I have an application running on a system that boots up, and takes a >> while to get the correct time; until that happens, the system thinks it's >> back in 1970, and there really is no point to writing a log file with a bum >> date. >> >> Using a custom filter, I can get the FileAppender to not write any events >> until the system time is set. I can get the FileAppender to not open the >> file until the first event is passed by the custom filter >> (createOnDemand="true"). Using Log4J2 - assigning file appender filename at >> runtime, I can get the file named mmdd-HHMMSS.log, but the >> mmdd-HHMMSS.log in the configuration XML seems to get evaluated when >> log4j2 is initialized (not when the file is opened), so my file name is >> still 19700101-00.log. >> >> Is there a way to defer evaluation of the name for a log4j2 FileAppender >> until the file is actually opened? Alternatively, is there a sneaky way to >> use RollingFileAppender to do this? (I
Re: Defer evaluation of FileAppender filename until file is opened?
yes, that works as designed, but does not resolve my problem. The filename is not evaluated when the first event is written (after we have a good date/time), it's evaluated when log4j2 is configured (which is before when we have a good date/time set). On Tuesday, February 4, 2020, 08:19:16 PM EST, Ralph Goers wrote: The FileAppender has an option named createOnDemand. If you set it to true then the file will only be created when a log event is written to it. See http://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender <http://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender>. Ralph > On Feb 4, 2020, at 2:10 PM, Doug Wegscheid wrote: > > > I am trying to have log4j2 write log files with names mmdd-HHMMSS.log, > but not start writing the file until we have a good system time (>year 1986). > I have an application running on a system that boots up, and takes a while to > get the correct time; until that happens, the system thinks it's back in > 1970, and there really is no point to writing a log file with a bum date. > > Using a custom filter, I can get the FileAppender to not write any events > until the system time is set. I can get the FileAppender to not open the file > until the first event is passed by the custom filter (createOnDemand="true"). > Using Log4J2 - assigning file appender filename at runtime, I can get the > file named mmdd-HHMMSS.log, but the mmdd-HHMMSS.log in the > configuration XML seems to get evaluated when log4j2 is initialized (not when > the file is opened), so my file name is still 19700101-00.log. > > Is there a way to defer evaluation of the name for a log4j2 FileAppender > until the file is actually opened? Alternatively, is there a sneaky way to > use RollingFileAppender to do this? (I don't see a way to change the filename > of the current file there, just old files) > > I could do a custom appender (FileAppender/FileManager just are not all that > long), but I'm trying to avoid that if possible. >