cancel
Showing results for 
Search instead for 
Did you mean: 

Print console log just after server start

anjali_dale
Explorer

I have a requirement to print a console log just after the server start. That is after the line "server started in <some miliseconds> " , line i need to print my custom log, say " here i am JUST after server start".

I tried two methods to do so but both of them are printing log during and not after server start. One was to use TenantListener and add log to afterTenantStartUp() function. Another was to make use of servletContextListener, but no luck with that too printing correctly.

Can someone suggest a proper way or file which can be extended may be to add this custom logger to print right after server start.

Thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

alemasetto
Participant

To print a message on server startup you can use AfterTenantRestartEvent.

You can create a class that extends the abstractEventListener bean and overrides the onEvent method.

Here's an example:

import de.hybris.platform.servicelayer.event.events.AfterTenantRestartEvent;
import de.hybris.platform.servicelayer.event.impl.AbstractEventListener;

public class StartupMessageListener extends AbstractEventListener<AfterTenantRestartEvent> {

@Override
protected void onEvent(AfterTenantRestartEvent afterTenantRestartEvent) {
System.out.println("Hybris startup successful!");
}

}
You also need to register this listener in your spring configuration file
<bean id="startupMessageListener" class="com.yourpackagename.StartupMessageListener" 
parent="abstractEventListener"/>