|
From: Maxime <ma...@ta...> - 2017-02-20 03:18:53
|
Hello Fabian Thank you for your email. The problem is that you are using WrapperManager.log() too early, when the backend is not yet ready to transmit the message to the Wrapper. One thing you could do is to subscribe to the WrapperLogFileChangedEvent event which is raised shortly after the backend is connected. First, your class has to implement WrapperEventListener: https://wrapper.tanukisoftware.com/jdoc/index.html?org/tanukisoftware/wrapper/event/WrapperEventListener.html Basically you only need to implement the fired() method. It would look like this: * public void fired( WrapperEvent event ) { if (event instanceof WrapperLogFileChangedEvent ) { WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_WARN, "Bootstrap abruptly cancelled"); } }* If you want to be sure that your message will only be logged once, you may stop listening for this event after the first call. Then you need to add your instance of WrapperEventListener (ErrorMuleContainerWrapper) with the appropriate mask. This can be done like this: * ErrorMuleContainerWrapper emcw = new ErrorMuleContainerWrapper(); WrapperManager.addWrapperEventListener( emcw, WrapperEventListener.EVENT_FLAG_LOGGING ); start(emcw, remainingArgs);* https://wrapper.tanukisoftware.com/jdoc/org/tanukisoftware/wrapper/WrapperManager.html#addWrapperEventListener(org.tanukisoftware.wrapper.event.WrapperEventListener,%20long) Now your class should listen to the logging event which will be fired just after the backend is opened, when the Wrapper notifies the location of the log file. In response to this event, the fired() method will ask the WrapperManager to log your message. After that you may be able to use filters set up in your configuration file. Please let me know if this work. Best Regards, Maxime On Fri, Feb 17, 2017 at 10:32 PM, Fabian Gonzalez < fab...@mu...> wrote: > Hello, Maxime > > thank you very much for your answer! > > I'm trying to get the behaviour I want using filters. The problem is that > it is only responding to messages appended to stdout directly. > > If I set this filter: > > wrapper.filter.trigger.1=Bootstrap abruptly cancelled > wrapper.filter.action.1=SHUTDOWN > wrapper.filter.message.1=Shutting down... > > and from java I add the following code: > > start(new ErrorMuleContainerWrapper(), remainingArgs); > WrapperManager.log(WRAPPER_LOG_LEVEL_WARN, "Bootstrap abruptly > cancelled"); > > It will not shutdown. > > It will not shutdown even if I use: > > start(new ErrorMuleContainerWrapper(), remainingArgs); > WrapperManager.log(WRAPPER_LOG_LEVEL_INFO, "Bootstrap abruptly > cancelled"); > > It will trigger the event when I add the following code: > > start(new ErrorMuleContainerWrapper(), remainingArgs); > System.out.println("Bootstrap abruptly cancelled") > > But in that case, with a WARN level of logging, no message will be > displayed (even the message set in wrapper.filter.message.1). With a log > level of INFO everything is displayed as expected. > > If I add the following code: > > start(new ErrorMuleContainerWrapper(), remainingArgs); > WrapperManager.log(WRAPPER_LOG_LEVEL_WARN, "Bootstrap abruptly > cancelled"); > System.out.println("Bootstrap abruptly cancelled") > > the shutdown will be triggered but no message is displayed in WARN level > (this is the same situation as the one when I try to use log without > setting an Thread,.sleep). > > I was trying to use other options, but I am being unable to DEBUG or even > SUSPEND the application and getting the backend to receive the log in WARN > level and print it on screen or the log file (or even display the filter > message in WARN level). > > What's even more curious is that if I use the following code: > > start(new ErrorMuleContainerWrapper(), remainingArgs); > WrapperManager.log(WRAPPER_LOG_LEVEL_WARN, "Bootstrap abruptly > cancelled"); > while(true); > > The message is not displayed (I suspect it is never flushed in the > backend). > The only way I'm still getting it to work is like this: > > start(new ErrorMuleContainerWrapper(), remainingArgs); > Thread.sleep(1000); > WrapperManager.log(WRAPPER_LOG_LEVEL_WARN, "Bootstrap abruptly > cancelled"); > > Am I missing something about the use of filters? > > Thanks in advance! > > On Thu, Feb 16, 2017 at 10:51 PM, Maxime <ma...@ta...> > wrote: > >> Hello Fabian >> >> Thank you for your email. >> >> What about using filters ? Filters work by searching for sequences of >> text in log outputs of the JVM. When the specified pattern is found, >> several actions can then be taken. For example you can stop the Wrapper or >> trigger a user event that can be transmitted back to your application. In >> your case, this is probably a good way to confirm that your message is >> logged. >> >> Please check our documentation to know more about filters: >> https://wrapper.tanukisoftware.com/doc/english/prop-filter-x-n.html >> >> I remain at your disposal should you have any questions. >> >> Best Regards, >> >> Maxime >> >> On Thu, Feb 16, 2017 at 12:35 AM, Fabian Gonzalez < >> fab...@mu...> wrote: >> >>> Hello, >>> >>> This is my first mail so greetings to all. >>> >>> I'm a having the following issue. >>> The log level is set to WARN in wrapper.conf both for the console and >>> the log file. >>> >>> Before starting the wrapper through WrapperManager.start, I should >>> perform a verification. In case this verification fails, I have to start >>> the java side of the wrapper only to log to wrapper log file as well as the >>> console. >>> So, what I do is perform WrapperManager.start WrapperManager.log and the >>> WrapperManger.stop. >>> The issue I'm having is that I have no way to verify that the socket >>> connection to the wrapper backend is actually opened, so if I perform: >>> >>> WrapperManager.start >>> WrapperManager.log >>> WrapperManager.stop >>> >>> the log command is not sent to the backend before stopping the java side >>> of the application. >>> >>> If I use something like this: >>> >>> WrapperManager.start >>> Thread.sleep(10000) >>> WrapperManager.log >>> WrapperManager.stop >>> >>> I manage to get the the message logged, but I am being confident that >>> the sleep time is the appropriate (kind of a hack). >>> >>> From: >>> >>> https://sourceforge.net/p/wrapper/mailman/message/30555007/ >>> >>> that for levels above INFO, that's the only way I have to log one of my >>> messages to the logfile and the console as it is managed by the backend. Is >>> there any other way apart from the sleep to make sure that the message is >>> logged before sending the WrapperManager.stop. >>> >>> Thanks in advance! >>> >>> ------------------------------------------------------------ >>> ------------------ >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot >>> _______________________________________________ >>> Wrapper-user mailing list >>> Wra...@li... >>> https://lists.sourceforge.net/lists/listinfo/wrapper-user >>> >>> >> >> ------------------------------------------------------------ >> ------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, SlashDot.org! http://sdm.link/slashdot >> _______________________________________________ >> Wrapper-user mailing list >> Wra...@li... >> https://lists.sourceforge.net/lists/listinfo/wrapper-user >> >> > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, SlashDot.org! http://sdm.link/slashdot > _______________________________________________ > Wrapper-user mailing list > Wra...@li... > https://lists.sourceforge.net/lists/listinfo/wrapper-user > > |