summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Martella <arthur.martella.1@att.com>2019-03-15 12:34:57 -0400
committerArthur Martella <arthur.martella.1@att.com>2019-03-15 12:34:57 -0400
commit99353d295aa4f90b77ab704683fca7e3251eeca3 (patch)
treeba9a9f5f006681eca184cf9eae1b5bfec8f9f77e
parentf0c40a75305068738f0bedfc282f71f826b408ce (diff)
Initial upload of F-GPS seed code 15/21
Includes: API EELF logging code Change-Id: I60638babe7c5a69b5a72b01530f6fce1f411aeef Issue-ID: OPTFRA-440 Signed-off-by: arthur.martella.1@att.com
-rw-r--r--valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/Configuration.java159
-rw-r--r--valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFLogger.java634
-rw-r--r--valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFManager.java502
-rw-r--r--valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/SLF4jWrapper.java1043
4 files changed, 2338 insertions, 0 deletions
diff --git a/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/Configuration.java b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/Configuration.java
new file mode 100644
index 0000000..68c45ed
--- /dev/null
+++ b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/Configuration.java
@@ -0,0 +1,159 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP - F-GPS API
+ * ===================================================================
+ * Copyright © 2019 ATT Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.fgps.api.eelf.configuration;
+
+/**
+ * This interface defines the configuration support and logger names in EELF.
+ * It also defines the MDC key names.
+ *
+ *
+ */
+public interface Configuration {
+
+
+ /**
+ * The name of the property used to define the filename for the logback configuration
+ */
+ public String PROPERTY_LOGGING_FILE_NAME = "org.onap.eelf.logging.file";
+
+ /**
+ * The name of the property used to define the filename for the logback configuration
+ */
+ public String PROPERTY_LOGGING_FILE_PATH = "org.onap.eelf.logging.path";
+
+ /**
+ * Logger name to be used for application general logging
+ */
+ public String GENERAL_LOGGER_NAME = "org.onap.eelf";
+
+
+ /**
+ * Logger name to be used for application metrics logging
+ */
+ public String METRICS_LOGGER_NAME = "org.onap.eelf.metrics";
+
+
+ /**
+ * Logger name to be used for application performance metrics
+ */
+ public String PERF_LOGGER_NAME = "org.onap.eelf.perf";
+
+
+ /**
+ * Logger name to be used for application policy logging
+ */
+ public String POLICY_LOGGER_NAME = "org.onap.eelf.policy";
+
+
+ /**
+ * Logger name to be used for application security logging
+ */
+ public String SECURITY_LOGGER_NAME = "org.onap.eelf.security";
+
+
+ /**
+ * Logger name to be used for application server logging
+ */
+ public String SERVER_LOGGER_NAME = "org.onap.eelf.server";
+
+ /**
+ * Logger name to be used for application audit logging
+ */
+ public String AUDIT_LOGGER_NAME = "org.onap.eelf.audit";
+
+ /**
+ * Logger name to be used for error logging
+ */
+ public String ERROR_LOGGER_NAME = "org.onap.eelf.error";
+
+ /**
+ * Logger name to be used for debug logging
+ */
+ public String DEBUG_LOGGER_NAME = "org.onap.eelf.debug";
+
+ /**
+ * The requestID is primarily used to track the processing of a request referencing
+ * a single instance of a service through the various sub-components.
+ */
+ public String MDC_KEY_REQUEST_ID = "RequestId";
+
+
+ /**
+ * The serviceInstanceID can be used to uniquely identity a service instance.
+ */
+ public String MDC_SERVICE_INSTANCE_ID = "ServiceInstanceId";
+
+
+ /**
+ * The serviceName can be used identify the name of the service.
+ */
+ public String MDC_SERVICE_NAME = "ServiceName";
+
+
+ /**
+ * The instanceUUID can be used to differentiate between multiple instances of the same (named), log writing service/application
+ */
+ public String MDC_INSTANCE_UUID= "InstanceUUID";
+
+ /**
+ * The serverIPAddress can be used to log the host server's IP address. (e.g. Jetty container's listening IP
+ * address)
+ */
+ public String MDC_SERVER_IP_ADDRESS = "ServerIPAddress";
+
+
+ /**
+ * The serverFQDN can be used to log the host server's FQDN.
+ */
+ public String MDC_SERVER_FQDN = "ServerFQDN";
+
+ /**
+ * The remote host name/ip address making the request
+ */
+ public static final String MDC_REMOTE_HOST = "RemoteHost";
+
+ /**
+ * The severity can be used to map to severity in alert messages eg. nagios alerts
+ */
+ public String MDC_ALERT_SEVERITY = "AlertSeverity";
+
+
+
+
+
+}
diff --git a/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFLogger.java b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFLogger.java
new file mode 100644
index 0000000..df7fecf
--- /dev/null
+++ b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFLogger.java
@@ -0,0 +1,634 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP - F-GPS API
+ * ===================================================================
+ * Copyright © 2019 ATT Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.fgps.api.eelf.configuration;
+
+import java.util.Locale;
+
+import org.onap.fgps.api.eelf.i18n.EELFResolvableErrorEnum;
+
+/**
+ * The EELFLogger is the main interface to access loggers in EELF.
+ * <p>
+ * It defines the convenience methods that are available to the application to log messages based
+ * on the string or a key in the resource bundle(s).
+ * </p>
+ *
+ */
+public interface EELFLogger {
+
+ public enum Level {
+ TRACE, DEBUG, INFO, WARN, ERROR, OFF
+ }
+
+
+ /**
+ * Log a warn message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ public void warn(String msg);
+
+
+ /**
+ * Log a warn message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ public void warn(String msg, Object... arguments);
+
+ /**
+ * Log a exception at warn level.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ */
+ public void warn(String msg, Throwable th);
+
+ /**
+ * Log a debug message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ public void debug(String msg);
+
+ /**
+ * Log a debug message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ public void debug(String msg, Object... arguments);
+
+ /**
+ * Log a exception at debug level.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ */
+ public void debug(String msg, Throwable th);
+
+
+ /**
+ * Log a info message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ public void info(String msg);
+
+ /**
+ * Log a info message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ public void info(String msg, Object... arguments);
+
+
+
+ /**
+ * Log a trace message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ public void trace(String msg);
+
+
+ /**
+ * Log a trace message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ public void trace(String msg, Object... arguments);
+
+ /**
+ * Log a exception at trace level.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ */
+ public void trace(String msg, Throwable th);
+
+ /**
+ * Log a error message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ public void error(String msg);
+
+ /**
+ * Log a error message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ public void error(String msg, Object... arguments);
+
+ /**
+ * Log a exception at error level.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ */
+ public void error(String msg, Throwable th);
+
+ /**
+ * Checks if the trace is enabled for the logger
+ */
+ public boolean isTraceEnabled();
+
+ /**
+ * Checks if the info is enabled for the logger
+ */
+ public boolean isInfoEnabled();
+
+ /**
+ * Checks if the error is enabled for the logger
+ */
+ public boolean isErrorEnabled();
+
+ /**
+ * Checks if the warn is enabled for the logger
+ */
+ public boolean isWarnEnabled();
+
+ /**
+ * Checks if the debug is enabled for the logger
+ */
+ public boolean isDebugEnabled();
+
+ /**
+ * Log a message or exception with arguments if the argument list is provided
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param level
+ * One of the message level identifiers, e.g., SEVERE
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ * @param arguments
+ * The list of arguments
+ */
+ public void log(Level level, String msg, Throwable th, Object... arguments);
+
+
+ /**
+ * Log a audit event using audit logger at info level.
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ public void auditEvent(String msg, Object... arguments);
+
+ /**
+ * Log a audit event using audit logger at given level.
+ *
+ * @param level
+ * One of the message level identifiers, e.g., WARN
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ public void auditEvent(Level level, String msg, Object... arguments);
+
+
+
+ /**
+ * Log a metrics event using metrics logger at info level.
+ *
+ * @param msg
+ * @param arguments
+ */
+ public void metricsEvent(String msg, Object... arguments);
+
+ /**
+ * Log a metrics event using metrics logger at info level at given level.
+ *
+ * @param level
+ * One of the message level identifiers, e.g., WARN
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+
+ public void metricsEvent(Level level, String msg, Object... arguments);
+
+
+
+
+ /**
+ * Log a security event using security logger at info level.
+ *
+ * @param msg
+ * @param arguments
+ */
+ public void securityEvent(String msg, Object... arguments);
+
+ /**
+ * Log a security event using security logger at given level.
+ *
+ * @param level
+ * @param msg
+ * @param arguments
+ */
+ public void securityEvent(Level level, String msg, Object... arguments);
+
+
+
+ /**
+ * Log a performance event using performance logger at info level.
+ *
+ * @param msg
+ * @param arguments
+ */
+ public void performanceEvent(String msg, Object... arguments);
+
+ /**
+ * Log a performance event using performance logger at a given level.
+ *
+ * @param level
+ * @param msg
+ * @param arguments
+ */
+ public void performanceEvent(Level level, String msg, Object... arguments);
+
+
+
+ /**
+ * Log an application event using application logger at info.
+ *
+ * @param msg
+ * @param arguments
+ */
+ public void applicationEvent(String msg, Object... arguments);
+
+ /**
+ * Log an application event using application logger at a given level.
+ *
+ * @param level
+ * @param msg
+ * @param arguments
+ */
+ public void applicationEvent(Level level, String msg, Object... arguments);
+
+
+ /**
+ * Log a server event using server logger at info level.
+ *
+ * @param msg
+ * @param arguments
+ */
+ public void serverEvent(String msg, Object... arguments);
+
+ /**
+ * Log a server event using server logger at a given level.
+ *
+ * @param level
+ * @param arguments
+ */
+ public void serverEvent(Level level, String msg, Object... arguments);
+
+
+
+ /**
+ * Log a policy event using policy logger at info level.
+ *
+ * @param msg
+ * @param arguments
+ */
+ public void policyEvent(String msg, Object... arguments);
+
+ /**
+ * Log a policy event using policy logger at a given level.
+ *
+ * @param level
+ * @param msg
+ * @param arguments
+ */
+ public void policyEvent(Level level, String msg, Object... arguments);
+
+ /**
+ * Log a warn message based on message key as defined in resource bundle for the given locale
+ * along with exception.
+ *
+ * @param locale
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void warn(Locale locale,EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+ /**
+ * Log a info message based on message key as defined in resource bundle for the given locale
+ * along with exception.
+ *
+ * @param locale
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void info(Locale locale, EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+ /**
+ * Log a debug message based on message key as defined in resource bundle for the given locale
+ * along with exception.
+ *
+ * @param locale
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void debug(Locale locale, EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+ /**
+ * Log a error message based on message key as defined in resource bundle for the given locale
+ * along with exception.
+ *
+ * @param locale
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void error(Locale locale, EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+ /**
+ * Log a trace message based on message key as defined in resource bundle for the given locale
+ * along with exception.
+ *
+ * @param locale
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void trace(Locale locale,EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+ /**
+ * Log a warn message based on message key as defined in resource bundle for the given locale.
+ *
+ * @param locale
+ * @param errorCode
+ * @param args
+ */
+ public void warn(Locale locale, EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a info message based on message key as defined in resource bundle for the given locale.
+ *
+ * @param locale
+ * @param errorCode
+ * @param args
+ */
+ public void info(Locale locale, EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a debug message based on message key as defined in resource bundle for the given locale.
+ *
+ * @param locale
+ * @param errorCode
+ * @param args
+ */
+ public void debug(Locale locale, EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a error message based on message key as defined in resource bundle for the given locale.
+ *
+ * @param locale
+ * @param errorCode
+ * @param args
+ */
+ public void error(Locale locale, EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a trace message based on message key as defined in resource bundle for the given locale.
+ *
+ * @param locale
+ * @param errorCode
+ * @param args
+ */
+ public void trace(Locale locale, EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a warn message based on message key as defined in resource bundle with arguments.
+ *
+ * @param errorCode
+ * @param args
+ */
+ public void warn(EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a info message based on message key as defined in resource bundle with arguments.
+ *
+ * @param errorCode
+ * @param args
+ */
+ public void info(EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a debug message based on message key as defined in resource bundle with arguments.
+ *
+ * @param errorCode
+ * @param args
+ */
+ public void debug(EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a error message based on message key as defined in resource bundle with arguments.
+ *
+ * @param errorCode
+ * @param args
+ */
+
+ public void error(EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a trace message based on message key as defined in resource bundle with arguments.
+ *
+ * @param errorCode
+ * @param args
+ */
+ public void trace(EELFResolvableErrorEnum errorCode, String... args);
+
+ /**
+ * Log a warn message based on message key as defined in resource bundle along with exception.
+ *
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void warn(EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+
+ /**
+ * Log a info message based on message key as defined in resource bundle along with exception.
+ *
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void info(EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+ /**
+ * Log a debug message based on message key as defined in resource bundle along with exception.
+ *
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void debug(EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+ /**
+ * Log a error message based on message key as defined in resource bundle along with exception.
+ *
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void error(EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+ /**
+ * Log a trace message based on message key as defined in resource bundle along with exception.
+ *
+ * @param errorCode
+ * @param th
+ * @param args
+ */
+ public void trace(EELFResolvableErrorEnum errorCode, Throwable th, String... args);
+
+ /**
+ * Change the logging level for the logger
+ *
+ * @param level
+ */
+ public void setLevel(Level level);
+
+ /**
+ * Turn off the logging for the logger
+ */
+ public void disableLogging();
+
+
+
+ }
diff --git a/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFManager.java b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFManager.java
new file mode 100644
index 0000000..feb98f9
--- /dev/null
+++ b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFManager.java
@@ -0,0 +1,502 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP - F-GPS API
+ * ===================================================================
+ * Copyright © 2019 ATT Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.fgps.api.eelf.configuration;
+
+import static org.onap.fgps.api.eelf.configuration.Configuration.AUDIT_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.DEBUG_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.ERROR_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.GENERAL_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.METRICS_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.PERF_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.POLICY_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.PROPERTY_LOGGING_FILE_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.PROPERTY_LOGGING_FILE_PATH;
+import static org.onap.fgps.api.eelf.configuration.Configuration.SECURITY_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.SERVER_LOGGER_NAME;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.onap.fgps.api.eelf.i18n.EELFMsgs;
+import org.onap.fgps.api.eelf.i18n.EELFResourceManager;
+import org.slf4j.ILoggerFactory;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+
+/**
+ * This is a singleton class used to obtain a named Logger instance.
+ * The EELFManager object can be retrieved using EELFManager.getInstance(). It is created during class initialization and cannot subsequently be changed.
+ * At startup the EELFManager loads the logging configuration file.
+ * If no external logging configuration file is found, it will load the default logging configuration available at org/onap/eelf/logback.xml
+ */
+
+public final class EELFManager {
+
+ /**
+ * This is a string constant for the comma character. It's intended to be used a common string delimiter.
+ */
+ private static final String COMMA = ",";
+
+ /**
+ * The logger to be used to record general application log events
+ */
+ private EELFLogger applicationLogger;
+
+ /**
+ * The logger to be used to record audit events
+ */
+ private EELFLogger auditLogger;
+
+ /**
+ * The logger to be used to record metric events
+ */
+ private EELFLogger metricsLogger;
+
+
+ /**
+ * The logger to be used to record performance events
+ */
+ private EELFLogger performanceLogger;
+
+ /**
+ * The logger to be used to record policy manager application events
+ */
+ private EELFLogger policyLogger;
+
+ /**
+ * The logger to be used to record security events
+ */
+ private EELFLogger securityLogger;
+
+ /**
+ * The logger to be used to record server events
+ */
+ private EELFLogger serverLogger;
+
+ /**
+ * The logger to be used to record error only
+ */
+ private EELFLogger errorLogger;
+
+ /**
+ * The logger to be used to record debug logs
+ */
+ private EELFLogger debugLogger;
+
+ /**
+ * Cache of all other loggers used in application
+ */
+ private Map<String,EELFLogger> loggerCache = new ConcurrentHashMap<String,EELFLogger>();
+
+ /**
+ * This lock is used to serialize access to create the loggers
+ */
+ private Object loggerLock = new Object();
+
+ /**
+ * This lock is used to serialize access to create the loggers
+ */
+ private static final EELFManager logManager = new EELFManager();
+
+ private EELFManager() {
+ ArrayList<String> delayedLogging = new ArrayList<String>();
+ /*
+ * Now, we are ready to initialize logging. Check to see if logging has already been initialized and that the
+ * application logger exists already. If it does, then skip the logging configuration because it was already set
+ * up in the container that is calling us. If not, then we need to set it up.
+ */
+ ILoggerFactory factory = LoggerFactory.getILoggerFactory();
+ if (factory instanceof LoggerContext) {
+ LoggerContext loggerContext = (LoggerContext) factory;
+ if (loggerContext.exists(GENERAL_LOGGER_NAME) == null) {
+ initializeLogging(delayedLogging);
+ } else {
+ delayedLogging.add(EELFResourceManager.getMessage(EELFMsgs.LOGGING_ALREADY_INITIALIZED));
+ }
+ }
+
+ /*
+ * Copy all delayed logging messages to the logger
+ */
+ for (String message : delayedLogging) {
+ // All messages are prefixed with a message code of the form EELF####S
+ // Where:
+ // EELF --- is the product code
+ // #### -- Is the message number
+ // S ----- Is the severity code (I=INFO, D=DEBUG, W=WARN, E=ERROR)
+ char severity = message.charAt(8);
+ switch (severity) {
+ case 'D':
+ getApplicationLogger().debug(message);
+ break;
+ case 'I':
+ getApplicationLogger().info(message);
+ break;
+ case 'W':
+ getApplicationLogger().warn(message);
+ break;
+ case 'E':
+ getApplicationLogger().error(message);
+ }
+ }
+
+ delayedLogging.clear();
+
+ }
+
+ /**
+ * Initialize the logging environment, record all logging messages to the provided list for delayed processing.
+ *
+ * @param delayedLogging
+ * The list to record logging messages to for delayed processing after the logging environment is
+ * created.
+ */
+ private static void initializeLogging(final ArrayList<String> delayedLogging) {
+
+ /*
+ * See if we can find logback-test.xml first, unless a specific file has been provided
+ */
+ String filename = System.getProperty(PROPERTY_LOGGING_FILE_NAME, "logback-test.xml");
+
+ String path = System.getProperty(PROPERTY_LOGGING_FILE_PATH, "${user.home};etc;../etc");
+
+ String msg = EELFResourceManager.format(EELFMsgs.SEARCHING_LOG_CONFIGURATION,path, filename);
+ delayedLogging.add(msg);
+
+ if (scanAndLoadLoggingConfiguration(path, filename, delayedLogging)) {
+ return;
+ }
+
+ /*
+ * If the first attempt was for logback-test.xml and it failed to find it, look again for logback.xml
+ */
+ if (filename.equals("logback-test.xml")) {
+ filename = System.getProperty(PROPERTY_LOGGING_FILE_NAME, "logback.xml");
+
+ if (scanAndLoadLoggingConfiguration(path, filename, delayedLogging)) {
+ return;
+ }
+ }
+
+
+ /*
+ * If we reach here, then no external logging configurations were defined or found. In that case, we need to
+ * initialize the logging framework from hard-coded default values we load from resources.
+ */
+ InputStream stream = EELFManager.class.getClassLoader().getResourceAsStream("org/onap/eelf/logback.xml");
+ try {
+ if (stream != null) {
+ delayedLogging.add(EELFResourceManager.getMessage(EELFMsgs.LOADING_DEFAULT_LOG_CONFIGURATION,"org/onap/eelf/logback.xml"));
+ loadLoggingConfiguration(stream, delayedLogging);
+ } else {
+ delayedLogging.add(EELFResourceManager.format(EELFMsgs.NO_LOG_CONFIGURATION));
+ }
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // not much we can do since logger may not be configured yet
+ e.printStackTrace(System.out);
+ }
+ }
+ }
+
+ }
+
+
+ /**
+ * Loads the logging configuration from the specified stream.
+ *
+ * @param stream
+ * The stream that contains the logging configuration document.
+ * @param delayedLogging
+ */
+ private static void loadLoggingConfiguration(final InputStream stream, final ArrayList<String> delayedLogging) {
+ ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
+ if (loggerFactory instanceof LoggerContext) {
+ configureLogback((LoggerContext) loggerFactory, stream);
+ } else {
+ delayedLogging.add((EELFResourceManager.format(EELFMsgs.UNSUPPORTED_LOGGING_FRAMEWORK)));
+ }
+
+ }
+
+
+
+ /**
+ * @param loggerFactory
+ * the logger factory context
+ * @param stream
+ * The input stream to be configured
+ */
+ private static void configureLogback(final LoggerContext context, final InputStream stream) {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(context);
+
+ try {
+ configurator.doConfigure(stream);
+ } catch (JoranException e) {
+ // not much we can do since logger may not be configured yet
+ e.printStackTrace(System.out);
+ }
+
+
+ }
+
+
+ /**
+ * This method scans a set of directories specified by the path for an occurrence of a file of the specified
+ * filename, and when found, loads that file as a logging configuration file.
+ *
+ * @param path
+ * The path to be scanned. This can be one or more directories, separated by the platform specific path
+ * separator character.
+ * @param filename
+ * The file name to be located. The file name examined within each element of the path for the first
+ * occurrence of the file that exists and which can be read and processed.
+ * @param delayedLogging
+ * @return True if a file was found and loaded, false if no files were found, or none were readable.
+ */
+ private static boolean scanAndLoadLoggingConfiguration(final String path, final String filename,
+ final ArrayList<String> delayedLogging) {
+ String[] pathElements = path.split(COMMA);
+ for (String pathElement : pathElements) {
+ File file = new File(pathElement, filename);
+ if (file.exists() && file.canRead() && !file.isDirectory()) {
+ String msg = EELFResourceManager.getMessage(EELFMsgs.LOADING_LOG_CONFIGURATION,file.getAbsolutePath());
+ delayedLogging.add(msg);
+
+ BufferedInputStream stream = null;
+ try {
+ stream = new BufferedInputStream(new FileInputStream(file));
+ delayedLogging.add(String.format("EELF000I Loading logging configuration from %s",
+ file.getAbsolutePath()));
+ loadLoggingConfiguration(stream, delayedLogging);
+ } catch (FileNotFoundException e) {
+ delayedLogging.add(EELFResourceManager.format(e));
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // not much we can do since logger may not be configured yet
+ e.printStackTrace(System.out);
+ }
+ }
+ }
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ * This method is used to obtain the EELFManager (as well as set it up if not already).
+ *
+ * @return The EELFManager object
+ */
+ public static EELFManager getInstance() {
+
+ return logManager;
+ }
+
+ /**
+ * Returns the logger associated with the name
+ * @return EELFLogger
+ */
+ public EELFLogger getLogger(String name) {
+ synchronized (loggerLock) {
+ if (!loggerCache.containsKey(name)) {
+ loggerCache.put(name,new SLF4jWrapper(name));
+ }
+ }
+ return loggerCache.get(name);
+
+ }
+
+ /**
+ * Returns the logger associated with the clazz
+ *
+ * @param clazz
+ * The class that we are obtaining the logger for
+ * @return EELFLogger The logger
+ */
+ public EELFLogger getLogger(Class<?> clazz) {
+ synchronized (loggerLock) {
+ if (!loggerCache.containsKey(clazz.getName())) {
+ loggerCache.put(clazz.getName(), new SLF4jWrapper(clazz.getName()));
+ }
+ }
+ return loggerCache.get(clazz.getName());
+
+ }
+
+ /**
+ * Returns the application logger
+ * @return EELFLogger
+ */
+ public EELFLogger getApplicationLogger() {
+ synchronized (loggerLock) {
+ if (applicationLogger == null) {
+ applicationLogger = new SLF4jWrapper(GENERAL_LOGGER_NAME);
+ }
+ }
+ return applicationLogger;
+ }
+
+ /**
+ * Returns the metrics logger
+ * @return EELFLogger
+ */
+ public EELFLogger getMetricsLogger() {
+ synchronized (loggerLock) {
+ if (metricsLogger == null) {
+ metricsLogger = new SLF4jWrapper(METRICS_LOGGER_NAME);
+ }
+ }
+ return metricsLogger;
+ }
+
+
+ /**
+ * Returns the audit logger
+ * @return EELFLogger
+ */
+ public EELFLogger getAuditLogger() {
+ synchronized (loggerLock) {
+ if (auditLogger == null) {
+ auditLogger = new SLF4jWrapper(AUDIT_LOGGER_NAME);
+ }
+ }
+ return auditLogger;
+ }
+
+ /**
+ * Returns the performance logger
+ * @return EELFLogger
+ */
+ public EELFLogger getPerformanceLogger() {
+ synchronized (loggerLock) {
+ if (performanceLogger == null) {
+ performanceLogger = new SLF4jWrapper(PERF_LOGGER_NAME);
+ }
+ }
+ return performanceLogger;
+ }
+
+ /**
+ * Returns the server logger
+ * @return EELFLogger
+ */
+ public EELFLogger getServerLogger() {
+ synchronized (loggerLock) {
+ if (serverLogger == null) {
+ serverLogger = new SLF4jWrapper(SERVER_LOGGER_NAME);
+ }
+ }
+ return serverLogger;
+ }
+
+
+ /**
+ * Returns the security logger
+ * @return EELFLogger
+ */
+ public EELFLogger getSecurityLogger() {
+ synchronized (loggerLock) {
+ if (securityLogger == null) {
+ securityLogger = new SLF4jWrapper(SECURITY_LOGGER_NAME);
+ }
+ }
+ return securityLogger;
+ }
+
+ /**
+ * Returns the policy logger
+ * @return EELFLogger
+ */
+ public EELFLogger getPolicyLogger() {
+ synchronized (loggerLock) {
+ if (policyLogger == null) {
+ policyLogger = new SLF4jWrapper(POLICY_LOGGER_NAME);
+ }
+ }
+ return policyLogger;
+ }
+
+
+ /**
+ * Returns the error logger
+ * @return EELFLogger
+ */
+ public EELFLogger getErrorLogger() {
+ synchronized (loggerLock) {
+ if (errorLogger == null) {
+ errorLogger = new SLF4jWrapper(ERROR_LOGGER_NAME);
+ }
+ }
+ return errorLogger;
+ }
+
+ /**
+ * Returns the error logger
+ * @return EELFLogger
+ */
+ public EELFLogger getDebugLogger() {
+ synchronized (loggerLock) {
+ if (debugLogger == null) {
+ debugLogger = new SLF4jWrapper(DEBUG_LOGGER_NAME);
+ }
+ }
+ return debugLogger;
+ }
+
+}
diff --git a/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/SLF4jWrapper.java b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/SLF4jWrapper.java
new file mode 100644
index 0000000..e9dc30a
--- /dev/null
+++ b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/SLF4jWrapper.java
@@ -0,0 +1,1043 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP - F-GPS API
+ * ===================================================================
+ * Copyright © 2019 ATT Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.fgps.api.eelf.configuration;
+
+
+import static org.onap.fgps.api.eelf.configuration.Configuration.AUDIT_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.GENERAL_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.METRICS_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.PERF_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.POLICY_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.SECURITY_LOGGER_NAME;
+import static org.onap.fgps.api.eelf.configuration.Configuration.SERVER_LOGGER_NAME;
+
+import java.util.Locale;
+
+import org.onap.fgps.api.eelf.i18n.EELFResolvableErrorEnum;
+import org.onap.fgps.api.eelf.i18n.EELFResourceManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class provides the implementation of <code>EELFLogger</code> interface.
+ * <p>
+ * It is wrapper of a SLF4J logger with a logback implementation to redirect logging calls to SLF4J.
+ *</p>
+ * @since Sept 8, 2015
+ */
+
+public class SLF4jWrapper implements EELFLogger {
+ private Logger logger;
+
+
+ /**
+ * Create the wrapper around the SLF4J logger
+ *
+ * @param name
+ * The SLF4J logger to be wrapped as a SLF4j logger
+ */
+ public SLF4jWrapper(String name) {
+ this.logger = LoggerFactory.getLogger(name);
+ }
+
+
+ /**
+ * Log a warn message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ @Override
+ public void warn(String msg) {
+ writeToLog(Level.WARN, msg);
+ }
+
+ /**
+ * Log a warn message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void warn(String msg, Object... arguments) {
+ writeToLog(Level.WARN, msg, null, arguments);
+ }
+
+ /**
+ * Log a exception at warn level.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ */
+ @Override
+ public void warn(String msg, Throwable th) {
+ writeToLog(Level.WARN, msg, th);
+ }
+
+ /**
+ * Log a debug message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ @Override
+ public void debug(String msg) {
+ writeToLog(Level.DEBUG, msg);
+ }
+
+ /**
+ * Log a debug message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void debug(String msg, Object... arguments) {
+ writeToLog(Level.DEBUG, msg, null, arguments);
+ }
+
+ /**
+ * Log a exception at debug level.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ */
+ @Override
+ public void debug(String msg, Throwable th) {
+ writeToLog(Level.DEBUG, msg, th);
+ }
+
+ /**
+ * Log a info message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ @Override
+ public void info(String msg) {
+ writeToLog(Level.INFO, msg);
+ }
+
+ /**
+ * Log a info message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void info(String msg, Object... arguments) {
+ writeToLog(Level.INFO, msg, null, arguments);
+ }
+
+ /**
+ * Log a trace message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ @Override
+ public void trace(String msg) {
+ writeToLog(Level.TRACE, msg);
+ }
+
+ /**
+ * Log a trace message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void trace(String msg, Object... arguments) {
+ writeToLog(Level.TRACE, msg, null, arguments);
+ }
+
+
+ /**
+ * Log a exception at trace level.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ */
+ @Override
+ public void trace(String msg, Throwable th) {
+ writeToLog(Level.TRACE, msg, th);
+ }
+
+ /**
+ * Log a error message, with no arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ */
+ @Override
+ public void error(String msg) {
+ writeToLog(Level.ERROR, msg);
+ }
+
+ /**
+ * Log a error message, with arguments.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void error(String msg, Object... arguments) {
+ writeToLog(Level.ERROR, msg, null, arguments);
+ }
+
+
+ /**
+ * Log a exception at error level.
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ */
+ @Override
+ public void error(String msg, Throwable th) {
+ writeToLog(Level.ERROR, msg, th);
+ }
+
+
+ /**
+ * Checks if the trace is enabled for the logger
+ */
+ @Override
+ public boolean isTraceEnabled() {
+ return logger.isTraceEnabled();
+ }
+
+ /**
+ * Checks if the info is enabled for the logger
+ */
+ @Override
+ public boolean isInfoEnabled() {
+ return logger.isInfoEnabled();
+ }
+
+
+ /**
+ * Checks if the error is enabled for the logger
+ */
+ @Override
+ public boolean isErrorEnabled() {
+ return logger.isErrorEnabled();
+ }
+
+ /**
+ * Checks if the warn is enabled for the logger
+ */
+ @Override
+ public boolean isWarnEnabled() {
+ return logger.isWarnEnabled();
+ }
+
+
+ /**
+ * Checks if the debug is enabled for the logger
+ */
+ @Override
+ public boolean isDebugEnabled() {
+ return logger.isDebugEnabled();
+ }
+
+
+
+ /**
+ * Log a message or exception with arguments if the argument list is provided
+ * <P>
+ * If the logger is currently enabled for the given message level then the given message is forwarded to all the
+ * registered output Handler objects.
+ * </p>
+ *
+ * @param level
+ * One of the message level identifiers, e.g., SEVERE
+ * @param msg
+ * The string message
+ * @param th
+ * The exception object
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void log(Level level, String msg, Throwable th, Object... arguments) {
+ writeToLog(level, msg, th, arguments);
+
+ }
+
+
+ /**
+ * Used by audit logger to record audit event with arguments at info level
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void auditEvent(String msg, Object... arguments) {
+ if (checkLoggerExists(AUDIT_LOGGER_NAME)) {
+ writeToLog(Level.INFO, msg, null, arguments);
+ }
+ }
+
+ /**
+ * Used by audit logger to record audit event with arguments at given level
+ *
+ * @param level
+ * One of the message level identifiers, e.g., SEVERE
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void auditEvent(Level level, String msg, Object... arguments) {
+ if (checkLoggerExists(AUDIT_LOGGER_NAME)) {
+ writeToLog(level, msg, null, arguments);
+ }
+
+ }
+
+
+ /**
+ * Used by metrics logger to record metrics event with arguments at info level
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void metricsEvent(String msg, Object... arguments) {
+ if (checkLoggerExists(METRICS_LOGGER_NAME)) {
+ writeToLog(Level.INFO, msg, null, arguments);
+ }
+
+ }
+
+ /**
+ * Used by metrics logger to record audit event with arguments at given level
+ *
+ * @param level
+ * One of the message level identifiers, e.g., SEVERE
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void metricsEvent(Level level, String msg, Object... arguments) {
+ if (checkLoggerExists(METRICS_LOGGER_NAME)) {
+ writeToLog(level, msg, null, arguments);
+ }
+
+ }
+
+
+
+ /**
+ * Used by security logger to record security event with arguments at info level
+ *
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void securityEvent(String msg, Object... arguments) {
+ if (checkLoggerExists(SECURITY_LOGGER_NAME)) {
+ writeToLog(Level.INFO, msg, null, arguments);
+ }
+
+ }
+
+ /**
+ * Used by security logger to record security event with arguments at given level
+ *
+ * @param level
+ * One of the message level identifiers, e.g., SEVERE
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void securityEvent(Level level, String msg, Object... arguments) {
+ if (checkLoggerExists(SECURITY_LOGGER_NAME)) {
+ writeToLog(level, msg, null, arguments);
+ }
+
+ }
+
+
+ @Override
+ public void performanceEvent(String msg, Object... arguments) {
+ if (checkLoggerExists(PERF_LOGGER_NAME)) {
+ writeToLog(Level.INFO, msg, null, arguments);
+ }
+
+ }
+
+ /**
+ * Used by performance logger to record performance event with arguments at given level
+ *
+ * @param level
+ * One of the message level identifiers, e.g., SEVERE
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void performanceEvent(Level level, String msg, Object... arguments) {
+ if (checkLoggerExists(PERF_LOGGER_NAME)) {
+ writeToLog(level, msg, null, arguments);
+ }
+
+ }
+
+
+ @Override
+ public void applicationEvent(String msg, Object... arguments) {
+ if (checkLoggerExists(GENERAL_LOGGER_NAME)) {
+ writeToLog(Level.INFO, msg, null, arguments);
+ }
+
+ }
+
+ /**
+ * Used by application logger to record application generic event with arguments at given level
+ *
+ * @param level
+ * One of the message level identifiers, e.g., SEVERE
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ @Override
+ public void applicationEvent(Level level, String msg, Object... arguments) {
+ if (checkLoggerExists(GENERAL_LOGGER_NAME)) {
+ writeToLog(level, msg, null, arguments);
+
+ }
+ }
+
+
+ @Override
+ public void serverEvent(String msg, Object... arguments) {
+ if (checkLoggerExists(SERVER_LOGGER_NAME)) {
+ writeToLog(Level.INFO, msg, null, arguments);
+ }
+
+ }
+
+ /**
+ * Used by server logger to record server event with arguments at given level
+ *
+ * @param level
+ * One of the message level identifiers, e.g., SEVERE
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ public void serverEvent(Level level, String msg, Object... arguments) {
+ if (checkLoggerExists(SERVER_LOGGER_NAME)) {
+ writeToLog(level, msg, null, arguments);
+ }
+
+ }
+
+
+ @Override
+ public void policyEvent(String msg, Object... arguments) {
+ if (checkLoggerExists(POLICY_LOGGER_NAME)) {
+ writeToLog(Level.INFO, msg, null, arguments);
+ }
+
+ }
+
+ /**
+ * Used by policy logger to record policy event with arguments at given level
+ *
+ * @param level
+ * One of the message level identifiers, e.g., SEVERE
+ * @param msg
+ * The string message
+ * @param arguments
+ * The list of arguments
+ */
+ public void policyEvent(Level level, String msg, Object... arguments) {
+ if (checkLoggerExists(POLICY_LOGGER_NAME)) {
+ writeToLog(level, msg, null, arguments);
+ }
+
+ }
+
+ /**
+ * This method is called by each logging method to determine if the specified level is active, format the message,
+ * and write it to the slf4j logger.
+ *
+ * @param level
+ * The level as defined by EELFLogger.
+ * @param msg
+ * The message to be written, possibly formatted with parameters
+ * @param th
+ * Any throwable to be recorded as part of the logging event, or null
+ * @param arguments
+ * The optional format parameters for the message
+ */
+
+ private void writeToLog(Level level, String msg, Throwable th, Object... arguments) {
+ if (level.equals(Level.TRACE)) {
+ if (logger.isTraceEnabled()) {
+ if (th != null) {
+ if (arguments == null || arguments.length == 0) {
+ logger.trace(msg, th);
+ } else {
+ logger.trace(msg, arguments, th);
+ }
+ } else {
+ if (arguments == null || arguments.length == 0) {
+ logger.trace(msg);
+ } else {
+ logger.trace(msg, arguments);
+ }
+ }
+ }
+ } else if (level.equals(Level.INFO)) {
+ if (logger.isInfoEnabled()) {
+ if (th != null) {
+ if (arguments == null || arguments.length == 0) {
+ logger.info(msg, th);
+ } else {
+ logger.info(msg, arguments, th);
+ }
+ } else {
+ if (arguments == null || arguments.length == 0) {
+ logger.info(msg);
+ } else {
+ logger.info(msg, arguments);
+ }
+ }
+ }
+ } else if (level.equals(Level.WARN)) {
+ if (logger.isWarnEnabled()) {
+ if (th != null) {
+ if (arguments == null || arguments.length == 0) {
+ logger.warn(msg, th);
+ } else {
+ logger.warn(msg, arguments, th);
+ }
+ } else {
+ if (arguments == null || arguments.length == 0) {
+ logger.warn(msg);
+ } else {
+ logger.warn(msg, arguments);
+ }
+ }
+ }
+ } else if (level.equals(Level.ERROR)) {
+ if (logger.isErrorEnabled()) {
+ if (th != null) {
+ if (arguments == null || arguments.length == 0) {
+ logger.error(msg, th);
+ } else {
+ logger.error(msg, arguments, th);
+ }
+ } else {
+ if (arguments == null || arguments.length == 0) {
+ logger.error(msg);
+ } else {
+ logger.error(msg, arguments);
+ }
+ }
+ }
+ } else if (level.equals(Level.DEBUG)) {
+ if (logger.isDebugEnabled()) {
+ if (th != null) {
+ if (arguments == null || arguments.length == 0) {
+ logger.debug(msg, th);
+ } else {
+ logger.debug(msg, arguments, th);
+ }
+ } else {
+ if (arguments == null || arguments.length == 0) {
+ logger.debug(msg);
+ } else {
+ logger.debug(msg, arguments);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * This method is called by each logging method to determine if the specified level is active, format the message,
+ * and write it to the slf4j logger.
+ *
+ * @param level
+ * The level as defined by EELFLogger.
+ * @param msg
+ * The message to be written, possibly formatted with parameters
+ * @param arguments
+ * The optional format parameters for the message
+ */
+
+ private void writeToLog(Level level, String msg, Object... arguments) {
+ if (level.equals(Level.TRACE)) {
+ if (logger.isTraceEnabled()) {
+ if (arguments == null || arguments.length == 0) {
+ logger.trace(msg);
+ } else {
+ logger.trace(msg, arguments);
+ }
+ }
+ } else if (level.equals(Level.INFO)) {
+ if (logger.isInfoEnabled()) {
+
+ if (arguments == null || arguments.length == 0) {
+ logger.info(msg);
+ } else {
+ logger.info(msg, arguments);
+ }
+ }
+ } else if (level.equals(Level.WARN)) {
+ if (logger.isWarnEnabled()) {
+
+ if (arguments == null || arguments.length == 0) {
+ logger.warn(msg);
+ } else {
+ logger.warn(msg, arguments);
+ }
+
+ }
+ } else if (level.equals(Level.ERROR)) {
+ if (logger.isErrorEnabled()) {
+
+ if (arguments == null || arguments.length == 0) {
+ logger.error(msg);
+ } else {
+ logger.error(msg, arguments);
+ }
+
+ }
+ } else if (level.equals(Level.DEBUG)) {
+ if (logger.isDebugEnabled()) {
+
+ if (arguments == null || arguments.length == 0) {
+ logger.debug(msg);
+ } else {
+ logger.debug(msg, arguments);
+ }
+
+ }
+ }
+ }
+
+ @Override
+ public void warn(Locale locale,EELFResolvableErrorEnum errorCode, Throwable th, String... args) {
+ writeToLog(Level.WARN, errorCode, locale, th, args);
+
+ }
+
+ @Override
+ public void info(Locale locale, EELFResolvableErrorEnum errorCode, Throwable th, String... args) {
+ writeToLog(Level.INFO, errorCode, locale, th, args);
+
+ }
+
+ @Override
+ public void debug(Locale locale, EELFResolvableErrorEnum errorCode, Throwable th, String... args) {
+ writeToLog(Level.DEBUG, errorCode, locale, th, args);
+
+ }
+
+ @Override
+ public void trace(Locale locale, EELFResolvableErrorEnum errorCode, Throwable th, String... args) {
+ writeToLog(Level.TRACE, errorCode, locale, th, args);
+
+ }
+
+ @Override
+ public void error(Locale locale, EELFResolvableErrorEnum errorCode, Throwable th, String... args) {
+ writeToLog(Level.ERROR, errorCode, locale, th, args);
+
+ }
+
+
+ /**
+ * This method is called by each logging method to determine if the specified level is active, format the message,
+ * and write it to the slf4j logger.
+ *
+ * @param level
+ * The level as defined by EELFLogger.
+ * @param resource
+ * Retrieves the error code from the loaded bundle(s)
+ * @param locale
+ * The locale to use when selecting and formatting the message
+ * @param th
+ * Any throwable to be recorded as part of the logging event, or null
+ * @param arguments
+ * The optional format parameters for the message
+ */
+
+
+ private void writeToLog(Level level, EELFResolvableErrorEnum resource, Locale locale, Throwable th, String... arguments) {
+ if (level.equals(Level.TRACE)) {
+ if (logger.isTraceEnabled()) {
+ if (th != null) {
+ if (locale == null) {
+ logger.trace(EELFResourceManager.format(resource, th, arguments));
+ } else {
+ logger.trace(EELFResourceManager.format(locale, resource, th, arguments));
+ }
+ } else {
+ if (locale == null) {
+ logger.trace(EELFResourceManager.format(resource, arguments));
+ } else {
+ logger.trace(EELFResourceManager.format(locale, resource, arguments));
+ }
+ }
+ }
+ } else if (level.equals(Level.INFO)) {
+ if (logger.isInfoEnabled()) {
+ if (th != null) {
+ if (locale == null) {
+ logger.info(EELFResourceManager.format(resource, th, arguments));
+ } else {
+ logger.info(EELFResourceManager.format(locale, resource, th, arguments));
+ }
+ } else {
+ if (locale == null) {
+ logger.info(EELFResourceManager.format(resource, arguments));
+ } else {
+ logger.info(EELFResourceManager.format(locale, resource, arguments));
+ }
+ }
+ }
+ } else if (level.equals(Level.WARN)) {
+ if (logger.isWarnEnabled()) {
+ if (th != null) {
+ if (locale == null) {
+ logger.warn(EELFResourceManager.format(resource, th, arguments));
+ } else {
+ logger.warn(EELFResourceManager.format(locale, resource, th, arguments));
+ }
+ } else {
+ if (locale == null) {
+ logger.warn(EELFResourceManager.format(resource, arguments));
+ } else {
+ logger.warn(EELFResourceManager.format(locale, resource, arguments));
+ }
+ }
+ }
+ } else if (level.equals(Level.ERROR)) {
+ if (logger.isErrorEnabled()) {
+ if (th != null) {
+ if (locale == null) {
+ logger.error(EELFResourceManager.format(resource, th, arguments));
+ } else {
+ logger.error(EELFResourceManager.format(locale, resource, th, arguments));
+ }
+ } else {
+ if (locale == null) {
+ logger.error(EELFResourceManager.format(resource, arguments));
+ } else {
+ logger.error(EELFResourceManager.format(locale, resource, arguments));
+ }
+ }
+ }
+ } else if (level.equals(Level.DEBUG)) {
+ if (logger.isDebugEnabled()) {
+ if (th != null) {
+ if (locale == null) {
+ logger.debug(EELFResourceManager.format(resource, th, arguments));
+ } else {
+ logger.debug(EELFResourceManager.format(locale, resource, th, arguments));
+ }
+ } else {
+ if (locale == null) {
+ logger.debug(EELFResourceManager.format(resource, arguments));
+ } else {
+ logger.debug(EELFResourceManager.format(locale, resource, arguments));
+ }
+ }
+ }
+ }
+
+ }
+
+
+
+ @Override
+ public void warn(Locale locale, EELFResolvableErrorEnum errorCode, String... args) {
+ writeToLog(Level.WARN, errorCode, locale, null, args);
+
+ }
+
+
+
+ @Override
+ public void info(Locale locale, EELFResolvableErrorEnum errorCode, String... args) {
+ writeToLog(Level.INFO, errorCode, locale, null, args);
+
+ }
+
+
+
+ @Override
+ public void debug(Locale locale, EELFResolvableErrorEnum errorCode, String... args) {
+ writeToLog(Level.DEBUG, errorCode, locale, null, args);
+
+ }
+
+
+
+ @Override
+ public void error(Locale locale, EELFResolvableErrorEnum errorCode, String... args) {
+ writeToLog(Level.ERROR, errorCode, locale, null, args);
+ }
+
+
+
+ @Override
+ public void trace( Locale locale, EELFResolvableErrorEnum errorCode,String... args) {
+ writeToLog(Level.TRACE, errorCode, locale, null, args);
+
+ }
+
+
+
+ @Override
+ public void warn(EELFResolvableErrorEnum errorCode, String... args) {
+ writeToLog(Level.WARN, errorCode, null, null, args);
+
+ }
+
+
+
+
+ public void info(EELFResolvableErrorEnum errorCode, String... args) {
+ writeToLog(Level.INFO, errorCode, null, null, args);
+
+ }
+
+
+
+
+ public void debug(EELFResolvableErrorEnum errorCode, String... args) {
+ writeToLog(Level.DEBUG, errorCode, null, null, args);
+
+ }
+
+
+
+
+ public void error(EELFResolvableErrorEnum errorCode, String... args) {
+ writeToLog(Level.ERROR, errorCode, null, null, args);
+
+ }
+
+
+
+
+ public void trace(EELFResolvableErrorEnum errorCode, String... args) {
+ writeToLog(Level.TRACE, errorCode, null, null, args);
+
+ }
+
+
+
+
+ public void warn(EELFResolvableErrorEnum errorCode, Throwable th,
+ String... args) {
+ writeToLog(Level.WARN, errorCode, null, th, args);
+
+ }
+
+
+
+
+ public void info(EELFResolvableErrorEnum errorCode, Throwable th,
+ String... args) {
+ writeToLog(Level.INFO, errorCode, null, th, args);
+
+ }
+
+
+
+
+ public void debug(EELFResolvableErrorEnum errorCode, Throwable th,
+ String... args) {
+ writeToLog(Level.DEBUG, errorCode, null, th, args);
+
+ }
+
+
+
+
+ public void error(EELFResolvableErrorEnum errorCode, Throwable th,
+ String... args) {
+ writeToLog(Level.ERROR, errorCode, null, th, args);
+
+ }
+
+
+
+
+ public void trace(EELFResolvableErrorEnum errorCode, Throwable th,
+ String... args) {
+ writeToLog(Level.TRACE, errorCode, null, th, args);
+
+ }
+
+
+ @Override
+ public void setLevel(Level level) {
+ if (logger instanceof ch.qos.logback.classic.Logger) {
+ switch (level) {
+ case INFO: ((ch.qos.logback.classic.Logger)logger).setLevel(ch.qos.logback.classic.Level.INFO); break;
+ case ERROR: ((ch.qos.logback.classic.Logger)logger).setLevel(ch.qos.logback.classic.Level.ERROR); break;
+ case DEBUG: ((ch.qos.logback.classic.Logger)logger).setLevel(ch.qos.logback.classic.Level.DEBUG); break;
+ case TRACE: ((ch.qos.logback.classic.Logger)logger).setLevel(ch.qos.logback.classic.Level.TRACE); break;
+ case WARN: ((ch.qos.logback.classic.Logger)logger).setLevel(ch.qos.logback.classic.Level.WARN); break;
+ case OFF: ((ch.qos.logback.classic.Logger)logger).setLevel(ch.qos.logback.classic.Level.OFF); break;
+
+ }
+
+ }
+
+ }
+
+
+ @Override
+ public void disableLogging() {
+ if (logger instanceof ch.qos.logback.classic.Logger) {
+ ((ch.qos.logback.classic.Logger)logger).setLevel(ch.qos.logback.classic.Level.OFF);
+ }
+
+ }
+
+
+ private boolean checkLoggerExists(String name) {
+ if (logger.getName().equals(name)) {
+ return true;
+
+ } else {
+ return false;
+ }
+ }
+
+
+}