com.jk.services.server.commons.util.JKLogServicePublisher Maven / Gradle / Ivy
/*
* Copyright 2002-2023 Dr. Jalal Kiswani.
* Email: [email protected]
* Check out https://j-framework.com for more details
*
* All the opensource projects of Dr. Jalal Kiswani are free for personal and academic use only,
* for commercial usage and support, please contact the author.
*
* 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 com.jk.services.server.commons.util;
import com.jk.core.logging.JKLogger;
import com.jk.core.logging.JKLoggerFactory;
import com.jk.services.client.logging.JKLogServiceClient;
import com.jk.web.monitoring.JKMonitorService;
import jakarta.faces.application.ViewExpiredException;
import jakarta.servlet.http.HttpServletRequest;
/**
* This class extends {@link JKMonitorService} and is responsible for publishing
* exceptions to a logging service.
*
* It logs exceptions and sends them to the logging service using a
* {@link JKLogServiceClient}.
*
* @author Dr. Jalal H. Kiswani
* @version 1.0
*/
public class JKLogServicePublisher extends JKMonitorService {
/**
* Represents the class logger.
*/
JKLogger logger = JKLoggerFactory.getLogger(getClass());
/**
* Represents the logging service.
*/
JKLogServiceClient logService = new JKLogServiceClient();
/**
* This method constructs a new {@code JKLogServicePublisher}.
*/
public JKLogServicePublisher() {
logger.debug("Initialized");
}
/**
* {@inheritDoc}
*/
@Override
public void publish(HttpServletRequest request, Throwable exception) {
if (exception instanceof ViewExpiredException) {
return;
}
String message = exception.getClass().getName();
if (exception.getMessage() != null) {
message = exception.getMessage();
}
if (message.length() > 255) {
message = message.substring(0, 255);
}
logger.debug("Publishing Exception ({}) to logging service", exception);
logService.callError(message);
}
}