diff options
Diffstat (limited to 'eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log')
8 files changed, 660 insertions, 0 deletions
diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/AuditLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/AuditLog.java new file mode 100644 index 0000000..952176e --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/AuditLog.java @@ -0,0 +1,130 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * Audit Log captures all log levels supported by audit specifications + * + * @author Rajiv Singla + */ +public interface AuditLog { + + /** + * Logs audit message with provided {@link LogLevelCategory} + * + * @param logLevelCategory log level category + * @param message log message + * @param auditLogSpec audit log spec + * @param optionalLogSpec optional log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, AuditLogSpec auditLogSpec, + OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param logLevelCategory log level category + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, AuditLogSpec auditLogSpec, String... args); + + + /** + * Logs audit message with provided INFO {@link LogLevelCategory} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void info(String message, AuditLogSpec auditLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided INFO {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void info(String message, AuditLogSpec auditLogSpec, String... args); + + + /** + * Logs audit message with provided WARN {@link LogLevelCategory} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void warn(String message, AuditLogSpec auditLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided WARN {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void warn(String message, AuditLogSpec auditLogSpec, String... args); + + /** + * Logs audit message with provided ERROR {@link LogLevelCategory} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void error(String message, AuditLogSpec auditLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided ERROR {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void error(String message, AuditLogSpec auditLogSpec, String... args); + + /** + * Logs audit message with provided FATAL {@link LogLevelCategory} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void fatal(String message, AuditLogSpec auditLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided FATAL {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void fatal(String message, AuditLogSpec auditLogSpec, String... args); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/DebugLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/DebugLog.java new file mode 100644 index 0000000..98a0921 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/DebugLog.java @@ -0,0 +1,76 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.utils.eelf.logger.api.log; + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * Debug Log captures all log levels supported by debug specifications. + * <p> + * <b>NOTE: DEBUG Log is optional as per EELF Specifications</b> + * + * @author Rajiv Singla + */ +public interface DebugLog { + + /** + * Logs debug message with provided {@link LogLevelCategory} + * + * @param logLevelCategory log level category + * @param message log message + * @param debugLogSpec debug log spec + * @param optionalLogSpec optional log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, DebugLogSpec debugLogSpec, + OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs debug message with provided {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param logLevelCategory log level category + * @param message log message + * @param debugLogSpec debug log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, DebugLogSpec debugLogSpec, String... args); + + + /** + * Logs debug message with provided DEBUG {@link LogLevelCategory} + * + * @param message log message + * @param debugLogSpec debug log spec + * @param args argument values for log message interpolation + */ + void debug(String message, DebugLogSpec debugLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs debug message with provided DEBUG {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param debugLogSpec debug log spec + * @param args argument values for log message interpolation + */ + void debug(String message, DebugLogSpec debugLogSpec, String... args); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogFactory.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogFactory.java new file mode 100644 index 0000000..2cfb2ec --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogFactory.java @@ -0,0 +1,85 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.noop.NoOpEELFLogger; + +import java.lang.reflect.InvocationTargetException; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.ServiceLoader; +import java.util.WeakHashMap; + +/** + * EELF Log Factory uses {@link ServiceLoader} to load implementations of {@link EELFLogger} in application + * classpath. If no EELF Logging implementations are found - eelf logging is disabled and {@link NoOpEELFLogger} + * is used. + * + * @author Rajiv Singla + */ +public class EELFLogFactory { + + private static final ServiceLoader<EELFLogger> SERVICE_LOADER = ServiceLoader.load(EELFLogger.class); + private static final Map<Class<?>, EELFLogger> LOGGER_CACHE = new WeakHashMap<>(64); + + private static List<EELFLogger> loggerImplementations = new LinkedList<>(); + + static { + + for (EELFLogger loggerImplementation : SERVICE_LOADER) { + loggerImplementations.add(loggerImplementation); + } + + if (loggerImplementations.isEmpty()) { + System.err.println( + "EELF LOGGING ERROR: Unable to find any EELF Logger Implementations in the classpath."); + System.err.println("=============EELF LOGGING IS DISABLED================"); + loggerImplementations.add(NoOpEELFLogger.getInstance()); + } + + } + + private EELFLogFactory() { + // private constructor + } + + public static <T> EELFLogger getLogger(Class<T> clazz) { + + if (LOGGER_CACHE.get(clazz) != null) { + return LOGGER_CACHE.get(clazz); + } + + EELFLogger EELFLogger = null; + try { + EELFLogger = loggerImplementations.get(0).getClass().getConstructor(Class.class) + .newInstance(clazz); + return EELFLogger; + + } catch ( + InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + throw new IllegalStateException("Error while Creating EELF Logger", e); + } + + } + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogger.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogger.java new file mode 100644 index 0000000..500d814 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogger.java @@ -0,0 +1,67 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.utils.eelf.logger.api.log; + +/** + * EELF Logger is main abstraction which applications use to log EELF Compliant log messages + * + * @author Rajiv Singla + */ +public interface EELFLogger { + + /** + * Provides Audit Log + * + * @return Audit log + */ + AuditLog auditLog(); + + + /** + * Provides Metric Log + * + * @return metric log + */ + MetricLog metricLog(); + + /** + * Provides Error Log + * + * @return error log + */ + ErrorLog errorLog(); + + + /** + * Provides Debug Log + * + * @return debug log + */ + DebugLog debugLog(); + + /** + * Provides logging context + * + * @return logging context + */ + EELFLoggerContext loggingContext(); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLoggerContext.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLoggerContext.java new file mode 100644 index 0000000..5910da5 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLoggerContext.java @@ -0,0 +1,56 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; + +/** + * EELF Logger Context contains fields are set during application creation time and are fixed for the entire + * duration of the application lifetime + * + * @author Rajiv Singla + */ +public interface EELFLoggerContext { + + /** + * Returns App Log Spec + * + * @return current app log spec + */ + AppLogSpec getAppLogSpec(); + + + /** + * Sets new App Log Spec + * + * @param appLogSpec new app log spec + */ + void setAppLogSpec(AppLogSpec appLogSpec); + + + /** + * Returns true if logging context is already initialized + * + * @return true if logger context is already initialized + */ + boolean isInitialized(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/ErrorLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/ErrorLog.java new file mode 100644 index 0000000..6b27755 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/ErrorLog.java @@ -0,0 +1,93 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * @author Rajiv Singla + */ +public interface ErrorLog { + + /** + * Logs error message with provided {@link LogLevelCategory} + * + * @param logLevelCategory log level category + * @param message log message + * @param errorLogSpec error log spec + * @param optionalLogSpec optional log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, ErrorLogSpec errorLogSpec, + OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs error message with provided {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param logLevelCategory log level category + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, ErrorLogSpec errorLogSpec, String... args); + + + /** + * Logs error message with ERROR {@link LogLevelCategory} + * + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void error(String message, ErrorLogSpec errorLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs error message with ERROR {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void error(String message, ErrorLogSpec errorLogSpec, String... args); + + + /** + * Logs error message with WARN {@link LogLevelCategory} + * + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void warn(String message, ErrorLogSpec errorLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs error message with WARN {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void warn(String message, ErrorLogSpec errorLogSpec, String... args); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/MetricLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/MetricLog.java new file mode 100644 index 0000000..ebc33ca --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/MetricLog.java @@ -0,0 +1,130 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * Metric Log captures all log levels supported by metric specifications + * + * @author Rajiv Singla + */ +public interface MetricLog { + + /** + * Logs metric message with provided {@link LogLevelCategory} + * + * @param logLevelCategory log level category + * @param message log message + * @param metricLogSpec metric log spec + * @param optionalLogSpec optional log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, MetricLogSpec metricLogSpec, + OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param logLevelCategory log level category + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, MetricLogSpec metricLogSpec, String... args); + + + /** + * Logs metric message with provided INFO {@link LogLevelCategory} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void info(String message, MetricLogSpec metricLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided INFO {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void info(String message, MetricLogSpec metricLogSpec, String... args); + + + /** + * Logs metric message with provided WARN {@link LogLevelCategory} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void warn(String message, MetricLogSpec metricLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided WARN {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void warn(String message, MetricLogSpec metricLogSpec, String... args); + + /** + * Logs metric message with provided ERROR {@link LogLevelCategory} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void error(String message, MetricLogSpec metricLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided ERROR {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void error(String message, MetricLogSpec metricLogSpec, String... args); + + /** + * Logs metric message with provided FATAL {@link LogLevelCategory} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void fatal(String message, MetricLogSpec metricLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided FATAL {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void fatal(String message, MetricLogSpec metricLogSpec, String... args); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/package-info.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/package-info.java new file mode 100644 index 0000000..e24ccc9 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/package-info.java @@ -0,0 +1,23 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + * + */ + +/** + * Contains Logging API contracts for various EELF Logs (e.g. Audit, Metric, Error, Debug etc) + */ +package org.onap.dcae.utils.eelf.logger.api.log; |