vidakovic commented on code in PR #6387: URL: https://github.com/apache/fineract/pull/6387#discussion_r3979835016
########## fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/FineractApplicationLifecycleLogger.java: ########## @@ -0,0 +1,94 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.core.boot; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.boot.web.context.WebServerApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.event.ContextClosedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +public class FineractApplicationLifecycleLogger { + + private volatile ConfigurableApplicationContext readyApplicationContext; + + @EventListener + public void onApplicationReady(ApplicationReadyEvent event) { + ConfigurableApplicationContext applicationContext = event.getApplicationContext(); + readyApplicationContext = applicationContext; + Environment environment = applicationContext.getEnvironment(); + log.info("Fineract lifecycle event: {}", createReadyMessage(environment, getServerPort(applicationContext))); + } + + @EventListener + public void onApplicationClosing(ContextClosedEvent event) { + if (event.getApplicationContext() == readyApplicationContext) { + log.info("Fineract lifecycle event: {}", createShuttingDownMessage()); + } + } + + static String createReadyMessage(Environment environment, int serverPort) { Review Comment: Remove `static`... life (in this life cycle logger) will get a lot easier. Repeating what I said in the previous comment: you don't have to pass `Environment` here. Whoever needs it can just do a `context.getEnvironment()`. While we are at it: please be consistent, all the functions from here on are not called in any way from the outside world... and that usually means: `private` modifier. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
