diff options
author | Singla, Rajiv (rs153v) <rs153v@att.com> | 2018-07-25 12:04:38 -0400 |
---|---|---|
committer | Singla, Rajiv (rs153v) <rs153v@att.com> | 2018-07-26 00:37:25 -0400 |
commit | eaeba3db217233dd20972f2d3d8a094d44ce0637 (patch) | |
tree | 137c21ffb5091f1977f8cfa341816f0c79fbecec /eelf-logger | |
parent | 9747c6954732c614850e3ef9cd6d6c7b74b3ceb8 (diff) |
Initial commit for EELF Logger
Issue-ID: DCAEGEN2-633
Change-Id: I108929219d2d6570080d2fe7792cbc5a6530bb59
Signed-off-by: Singla, Rajiv (rs153v) <rs153v@att.com>
Diffstat (limited to 'eelf-logger')
95 files changed, 6680 insertions, 0 deletions
diff --git a/eelf-logger/cpd-exclude.properties b/eelf-logger/cpd-exclude.properties new file mode 100644 index 0000000..399fb30 --- /dev/null +++ b/eelf-logger/cpd-exclude.properties @@ -0,0 +1,21 @@ +#
+# ================================================================================
+# 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=========================================================
+#
+#
+
+# Ignored as there are different log specs
+org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl,org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl
diff --git a/eelf-logger/eelf-logger-api/pom.xml b/eelf-logger/eelf-logger-api/pom.xml new file mode 100644 index 0000000..1d7fa1b --- /dev/null +++ b/eelf-logger/eelf-logger-api/pom.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.dcaegen2.utils</groupId> + <artifactId>eelf-logger</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>eelf-logger-api</artifactId> + <packaging>jar</packaging> + + <!-- EELF LOGGING API CONTAINS VARIOUS INTERFACES REQUIRED TO SUPPORT SUPPORT EELF LOGGING SPECIFICATIONS --> + <name>dcaegen2-utils-eelf-logger-api</name> + <description>API contracts for EELF Logging Framework</description> + + <properties> + <main.basedir>${project.parent.basedir}</main.basedir> + <!-- SONAR SETTINGS : EXCLUDE TEST COVERAGE AS API ONLY CONTAINS INTERFACES AND NO BUSINESS LOGIC--> + <sonar.coverage.exclusions>**/api/**</sonar.coverage.exclusions> + </properties> + + <!-- NOTE: THIS API MODULE MUST NOT HAVE ANY DEPENDENCIES IN COMPILE SCOPE--> + +</project> diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/AppLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/AppLogInfo.java new file mode 100644 index 0000000..bdce8d1 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/AppLogInfo.java @@ -0,0 +1,101 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Captures information about application which is doing the logging. All app log fields must remain same for + * the whole duration of the application once its instance is created. + * + * @author Rajiv Singla + */ +public interface AppLogInfo extends LogInfo { + + /** + * Required field contains UUID which identifies this service instance inside an inventory management system + * (e.g. A&AI) to reference/manage this service as a unit + * + * @return remote VM Name or service the request is acting upon. + */ + String getServiceInstanceID(); + + /** + * Required field contains a universally unique identifier used to differentiate between multiple instances of + * the same (named), log writing service/application. Its value is set at instance creation time (and read by it, + * e.g. at start/initialization time from the environment). This value should be picked up by the component + * instance from its configuration file and subsequently used to enable differentiating log records created by + * multiple, locally load balanced EELF component or sub component instances that are otherwise identically + * configured. + * + * @return instance UUID + */ + String getInstanceUUID(); + + /** + * Optional field contains VM Name where app is deployed. + * DCAE sub components should populate this field but it can be empty if + * determined that its value can be added by the log files collecting agent itself (e.g. Splunk). + * <p> + * <b> Example: host.vm.name.com</b> + * </p> + * + * @return virtual server name + */ + String getVirtualServerName(); + + /** + * Optional field contains the logging component host server’s IP address. + * <p> + * <b>Example: 127.0.0.100</b> + * </p> + * + * @return server ip address + */ + String getServerIPAddress(); + + /** + * Required field for VM's fully qualified domain name or hosting machine fully qualified domain name. + * <p> + * <b> Example: host.fqdn.com</b> + * </p> + * + * @return server host fully qualified domain name + */ + String getServerFQDN(); + + + /** + * Contains default values for {@link AppLogInfo} + */ + interface Defaults { + + String DEFAULT_SERVICE_INSTANCE_ID = "UNKNOWN_INSTANCE_ID"; + + String DEFAULT_INSTANCE_UUID = ""; + + String DEFAULT_VIRTUAL_SERVER_NAME = ""; + + String DEFAULT_SERVER_IP_ADDRESS = "UNKNOWN_IP_ADDRESS"; + + String DEFAULT_SERVER_FQDN = "UNKNOWN_SERVER_FQDN"; + + } + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CodeLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CodeLogInfo.java new file mode 100644 index 0000000..bea195d --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CodeLogInfo.java @@ -0,0 +1,55 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Capture field required to log details about code which is generating the log message. + * <p> + * <b>NOTE: When using a logging framework(e.g. logback) implementation these fields may be automatically deduced - so + * settings these fields is not required by the application and even if application sets these fields the logging + * framework may ignore it + * </b> + * </p> + * + * @author Rajiv Singla + */ +public interface CodeLogInfo extends LogInfo { + + + /** + * Optional field used if wanting to trace processing of a request over a number of sub-components of a single EELF + * component. It should be preceded by a log record that establishes its chaining back to the corresponding + * requestID. + * + * @return thread ID used to trace processing of request over number of sub-components of single EELF Component. + */ + String getThreadId(); + + + /** + * Optional field: If available for OO programing languages that support this concept. This is the name of the + * class that has caused the log record to be created. + * + * @return name of the class that has the caused the log record to be created + */ + String getClassName(); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CustomFieldsLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CustomFieldsLogInfo.java new file mode 100644 index 0000000..634afa6 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CustomFieldsLogInfo.java @@ -0,0 +1,62 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Captures fields required to log Custom fields + * + * @author Rajiv Singla + */ +public interface CustomFieldsLogInfo extends LogInfo { + + /** + * Optional field that can be used by developers to include additional application-specific + * information to support operations and troubleshooting of the system. + * + * @return additional application-specific information to support operations and troubleshooting of the system. + */ + String getCustomField1(); + + /** + * Optional field that can be used by developers to include additional application-specific + * information to support operations and troubleshooting of the system. + * + * @return additional application-specific information to support operations and troubleshooting of the system. + */ + String getCustomField2(); + + /** + * Optional field that can be used by developers to include additional application-specific + * information to support operations and troubleshooting of the system. + * + * @return additional application-specific information to support operations and troubleshooting of the system. + */ + String getCustomField3(); + + /** + * Optional field that can be used by developers to include additional application-specific + * information to support operations and troubleshooting of the system. + * + * @return additional application-specific information to support operations and troubleshooting of the system. + */ + String getCustomField4(); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ErrorLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ErrorLogInfo.java new file mode 100644 index 0000000..876037c --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ErrorLogInfo.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.info; + +/** + * Captures fields required to log error related information + * + * @author Rajiv Singla + */ +public interface ErrorLogInfo extends LogInfo { + + + /** + * Required field contains an error code representing the error condition. The codes can be chose by + * the logging application but they should adhere to the guidelines embodied in the table below: + * <table summary="Error Codes" cellspacing=0 border=1> + * <tr> + * <td style=min-width:50px>Error type</td> + * <td style=min-width:50px>Notes</td> + * </tr> + * <tr> + * <td style=min-width:50px>100</td> + * <td style=min-width:50px>Permission errors</td> + * </tr> + * <tr> + * <td style=min-width:50px>200</td> + * <td style=min-width:50px>Availability errors/Timeouts</td> + * </tr> + * <tr> + * <td style=min-width:50px>300</td> + * <td style=min-width:50px>Data errors</td> + * </tr> + * <tr> + * <td style=min-width:50px>400</td> + * <td style=min-width:50px>Schema errors</td> + * </tr> + * <tr> + * <td style=min-width:50px>500</td> + * <td style=min-width:50px>Business process errors</td> + * </tr> + * <tr> + * <td style=min-width:50px>900</td> + * <td style=min-width:50px>Unknown Errors</td> + * </tr> + * </table> + * + * @return error Code + */ + Integer getErrorCode(); + + + /** + * Required field contains a human readable description of the error condition. + * + * @return human readable description of the error condition + */ + String getErrorDescription(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogInfo.java new file mode 100644 index 0000000..4a3680f --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogInfo.java @@ -0,0 +1,30 @@ +/* + * ================================================================================ + * 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.info; + +import java.io.Serializable; + +/** + * Marker interface for all EELF Logging Information Components + * + * @author Rajiv Singla + */ +public interface LogInfo extends Serializable { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogLevelCategory.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogLevelCategory.java new file mode 100644 index 0000000..665a280 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogLevelCategory.java @@ -0,0 +1,36 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Captures various logging levels. + * NOTE: Enum ordered signifies low to high log level severity + * + * @author Rajiv Singla + */ +public enum LogLevelCategory implements LogInfo { + + DEBUG, + INFO, + WARN, + ERROR, + FATAL; + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MessageLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MessageLogInfo.java new file mode 100644 index 0000000..cd53ccf --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MessageLogInfo.java @@ -0,0 +1,62 @@ +/* + * ================================================================================ + * 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.info; + +import java.util.Date; + +/** + * Captures fields required for message level logging. These fields are mostly derived fields. For example: creation + * timestamp can be auto generated based on system time, {@link RequestStatusCode} and {@link NagiosAlertLevel} can be + * derived based on {@link LogLevelCategory} + * + * @author Rajiv Singla + */ +public interface MessageLogInfo extends LogInfo { + + + /** + * Required field to capture when the message was created + * The value should be represented in UTC and formatted according to ISO 8601. + * <p> + * <b>Example: 2015-06-03T13:21:58+00:00</b> + * </p> + * + * @return message creation creationTimestamp + */ + Date getCreationTimestamp(); + + /** + * Required field contains a value of COMPLETE or ERROR to indicate high level success or failure of the + * request related activities. + * + * @return value to indicate high level success or failure of the request related activities + */ + RequestStatusCode getStatusCode(); + + + /** + * Optional field for Nagios monitoring/alerting severity code + * + * @return nagios monitoring/alerting severity code + */ + NagiosAlertLevel getAlertSeverity(); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MiscLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MiscLogInfo.java new file mode 100644 index 0000000..bf1e451 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MiscLogInfo.java @@ -0,0 +1,45 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Captures optional / deprecated fields that can be populated as per EELF Logging Requirements + * + * @author Rajiv Singla + */ +public interface MiscLogInfo extends LogInfo { + + /** + * Optional field that can can be used to capture the flow of a transaction through the system by + * indicating the components and operations involved in processed. If present, it can be denoted by a comma + * separated list of components and applications. + * + * @return list of comma separated components and operations involved in processing + */ + String getProcessId(); + + /** + * This field is deprecated and should be left empty. + * + * @return deprecated field value - should be empty + */ + String getUnused(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/NagiosAlertLevel.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/NagiosAlertLevel.java new file mode 100644 index 0000000..3da5fc3 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/NagiosAlertLevel.java @@ -0,0 +1,52 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Enum for Nagios monitoring/alerting codes as per table below. + * <p> + * <table cellspacing=0 border=1> + * <tr><th>Return Code</th><th>Service State</th><th>Host State</th></tr> + * <tr><td>0</td><td>OK</td><td>UP</td></tr> + * <tr><td>1</td><td>WARNING</td><td>UP or DOWN/UNREACHABLE*</td></tr> + * <tr><td>2</td><td>CRITICAL</td><td>DOWN/UNREACHABLE</td></tr> + * <tr><td>3</td><td>UNKNOWN</td><td>DOWN/UNREACHABLE</td></tr> + * </table> + * + * @author Rajiv Singla + */ +public enum NagiosAlertLevel implements LogInfo { + + OK("0"), + WARNING("1"), + CRITICAL("2"), + UNKNOWN("3"); + + private String severityCode; + + NagiosAlertLevel(final String severityCode) { + this.severityCode = severityCode; + } + + public String getSeverityCode() { + return severityCode; + } + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestIdLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestIdLogInfo.java new file mode 100644 index 0000000..68d5a17 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestIdLogInfo.java @@ -0,0 +1,44 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Captures fields required for logging request information + * + * @author Rajiv Singla + */ +public interface RequestIdLogInfo extends LogInfo { + + /** + * Required field containing requestID which uniquely that identifies a single transaction request within the EELF + * platform. Its value is conforms to RFC4122 UUID. The requestID value is passed using a REST API from one + * EELF component to another via HTTP Headers named X-RequestID + * <p> + * <b>724229c0-9945-11e5-bcde-0002a5d5c51b:1234</b> + * </p> + * If receiving a composite requestID value, e.g. something of the form UUID-1:UUID-2, the receiving component + * should only use the UUID-1 portion (i.e. remove the “:” and any trailing suffix, e.g. UUID-2) as the requestID + * field value for its log files. + * + * @return requestID which uniquely that identifies a single transaction request within the EELF + */ + String getRequestId(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestStatusCode.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestStatusCode.java new file mode 100644 index 0000000..b022b80 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestStatusCode.java @@ -0,0 +1,32 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Enum to indicate high level success or failure of the request related activities + * + * @author Rajiv Singla + */ +public enum RequestStatusCode { + + ERROR, + COMPLETE; + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestTimingLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestTimingLogInfo.java new file mode 100644 index 0000000..7448e69 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestTimingLogInfo.java @@ -0,0 +1,64 @@ +/* + * ================================================================================ + * 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.info; + +import java.util.Date; + +/** + * Captures Logging fields required for request timing related information + * + * @author Rajiv Singla + */ +public interface RequestTimingLogInfo extends LogInfo { + + /** + * Required field containing creationTimestamp when the request processing started. + * The value should be represented in UTC and formatted according to ISO 8601. + * <p> + * <b>Example: 2015-06-03T13:21:58+00:00</b> + * </p> + * + * @return request activity begin creationTimestamp + */ + Date getBeginTimestamp(); + + + /** + * Required field containing creationTimestamp when the request processed stopped. + * The value should be represented in UTC and formatted according to ISO 8601. + * <p> + * <b>Example: 2015-06-03T13:21:58+00:00</b> + * </p> + * + * @return request activity end creationTimestamp + */ + Date getEndTimestamp(); + + + /** + * Required field contains the elapsed time to complete processing of an API call or transaction request (e.g., + * processing of a message that was received). This value should be the difference between EndTimestamp and + * BeginTimestamp fields and should be expressed in milliseconds. + * + * @return request processing elapsed time in milliseconds + */ + Long getElapsedTime(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ResponseLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ResponseLogInfo.java new file mode 100644 index 0000000..1929e7f --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ResponseLogInfo.java @@ -0,0 +1,81 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Captures field required for logging Response information + * + * @author Rajiv Singla + */ +public interface ResponseLogInfo extends LogInfo { + + /** + * Required field contains application-specific response codes. While error codes are + * application-specific, they + * should conform categories mentioned in table below in order to provide consistency + * <p> + * <table cellspacing=0 border=1> + * <tr> + * <th style=min-width:50px><b>Error type</b></th> + * <th style=min-width:50px><b>Notes</b></th> + * </tr> + * <tr> + * <td style=min-width:50px>0</td> + * <td style=min-width:50px>Success</td> + * </tr> + * <tr> + * <td style=min-width:50px>100</td> + * <td style=min-width:50px>Permission errors</td> + * </tr> + * <tr> + * <td style=min-width:50px>200</td> + * <td style=min-width:50px>Availability errors/Timeouts</td> + * </tr> + * <tr> + * <td style=min-width:50px>300</td> + * <td style=min-width:50px>Data errors</td> + * </tr> + * <tr> + * <td style=min-width:50px>400</td> + * <td style=min-width:50px>Schema errors</td> + * </tr> + * <tr> + * <td style=min-width:50px>500</td> + * <td style=min-width:50px>Business process errors</td> + * </tr> + * <tr> + * <td style=min-width:50px>900</td> + * <td style=min-width:50px>Unknown Errors</td> + * </tr> + * </table> + * + * @return application-specific error code + */ + Integer getResponseCode(); + + + /** + * Required field contains a human readable description of the {@link #getResponseCode()}. + * + * @return human readable description of the response code + */ + String getResponseDescription(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ServiceLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ServiceLogInfo.java new file mode 100644 index 0000000..0287cef --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ServiceLogInfo.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Captures information about logging fields for application acting as service and handling requests from other + * applications + * + * @author Rajiv Singla + */ +public interface ServiceLogInfo extends LogInfo { + + /** + * Required field contains the developer given name of the ecomp component's exposed api (~='method', function') + * invoked. For example if the application is exposing a REST interface and exposing runtime metrics then the + * service name can be: appName-getMetrics + * + * @return name of the API invoked by the application + */ + String getServiceName(); + + + /** + * Optional field contains the name of the client or user invoking the service. + * It may be an application, user name or mech id. + * + * @return name of the client or user invoking the API if known + */ + String getPartnerName(); + + + /** + * Optional field contains requesting remote client application’s IP address. Use UNKNOWN or an empty string if not + * available. + * + * @return remote client application’s IP address + */ + String getClientIPAddress(); + + +} + + + diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/TargetServiceLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/TargetServiceLogInfo.java new file mode 100644 index 0000000..d9b1f98 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/TargetServiceLogInfo.java @@ -0,0 +1,54 @@ +/* + * ================================================================================ + * 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.info; + +/** + * Captures fields for logging application which is calling an external/target service + * + * @author Rajiv Singla + */ +public interface TargetServiceLogInfo extends LogInfo { + + /** + * Required field containing name of EELF component/sub component or non-EELF entity which is invoked by the + * logging application + * + * @return target entity name which is invoked by the logging application + */ + String getTargetEntity(); + + + /** + * Required field containing name of External API/operation activities invoked on {@link #getTargetEntity()} + * + * @return target service name invoked by the logging application + */ + String getTargetServiceName(); + + + /** + * Optional field containing target VNF or VM being acted upon by the logging application. This field contains the + * virtual entity that is the target of the action for example the FQDN of the target virtual entity + * + * @return target Virtual Entity + */ + String getTargetVirtualEntity(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/package-info.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/package-info.java new file mode 100644 index 0000000..45bddd1 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/package-info.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * 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========================================================= + * + */ + +/** + * Captures EELF logging information about various types. + * <p> + * The logging information is segregated into various information different types as to their relevance in particular + * cases. + * + * @author Rajiv Singla + */ +package org.onap.dcae.utils.eelf.logger.api.info; 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; diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpAuditLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpAuditLog.java new file mode 100644 index 0000000..6c1c583 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpAuditLog.java @@ -0,0 +1,90 @@ +/* + * ================================================================================ + * 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.noop; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.AuditLog; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * A no operation implementation of AuditLog + * + * @author Rajiv Singla + */ +public class NoOpAuditLog implements AuditLog { + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final AuditLogSpec auditLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + // no operation + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final AuditLogSpec auditLogSpec, + final String... args) { + // no operation + } + + @Override + public void info(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void info(final String message, final AuditLogSpec auditLogSpec, final String... args) { + // no operation + } + + @Override + public void warn(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void warn(final String message, final AuditLogSpec auditLogSpec, final String... args) { + // no operation + } + + @Override + public void error(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void error(final String message, final AuditLogSpec auditLogSpec, final String... args) { + // no operation + } + + @Override + public void fatal(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void fatal(final String message, final AuditLogSpec auditLogSpec, final String... args) { + // no operation + } +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpDebugLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpDebugLog.java new file mode 100644 index 0000000..dd36b52 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpDebugLog.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.noop; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.DebugLog; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * A no operation implementation of Debug Log + * + * @author Rajiv Singla + */ +public class NoOpDebugLog implements DebugLog { + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + // no operation + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec, + final String... args) { + // no operation + } + + @Override + public void debug(final String message, final DebugLogSpec debugLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void debug(final String message, final DebugLogSpec debugLogSpec, final String... args) { + // no operation + } +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpEELFLogger.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpEELFLogger.java new file mode 100644 index 0000000..c761ba1 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpEELFLogger.java @@ -0,0 +1,77 @@ +/* + * ================================================================================ + * 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.noop; + + +import org.onap.dcae.utils.eelf.logger.api.log.AuditLog; +import org.onap.dcae.utils.eelf.logger.api.log.DebugLog; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLoggerContext; +import org.onap.dcae.utils.eelf.logger.api.log.ErrorLog; +import org.onap.dcae.utils.eelf.logger.api.log.MetricLog; + +/** + * A no operation implementation of {@link EELFLogger} + * + * @author Rajiv Singla + */ +public class NoOpEELFLogger implements EELFLogger { + + private static final AuditLog NO_OP_AUDIT_LOG = new NoOpAuditLog(); + private static final MetricLog NO_OP_METRIC_LOG = new NoOpMetricLog(); + private static final ErrorLog NO_OP_ERROR_LOG = new NoOpErrorLog(); + private static final DebugLog NO_OP_DEBUG_LOG = new NoOpDebugLog(); + + private static final NoOpEELFLogger NO_OP_EELF_LOGGER = new NoOpEELFLogger(); + + private NoOpEELFLogger() { + // private constructor + } + + public static NoOpEELFLogger getInstance() { + return NO_OP_EELF_LOGGER; + } + + @Override + public AuditLog auditLog() { + return NO_OP_AUDIT_LOG; + } + + @Override + public MetricLog metricLog() { + return NO_OP_METRIC_LOG; + } + + @Override + public ErrorLog errorLog() { + return NO_OP_ERROR_LOG; + } + + @Override + public DebugLog debugLog() { + return NO_OP_DEBUG_LOG; + } + + @Override + public EELFLoggerContext loggingContext() { + return null; + } + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpErrorLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpErrorLog.java new file mode 100644 index 0000000..c1b4e13 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpErrorLog.java @@ -0,0 +1,68 @@ +/* + * ================================================================================ + * 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.noop; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.ErrorLog; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * A no operation implementation of Error Log + * + * @author Rajiv Singla + */ +public class NoOpErrorLog implements ErrorLog { + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final ErrorLogSpec errorLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + // no operation + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final ErrorLogSpec errorLogSpec, + final String... args) { + // no operation + } + + @Override + public void error(final String message, final ErrorLogSpec errorLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void error(final String message, final ErrorLogSpec errorLogSpec, final String... args) { + // no operation + } + + @Override + public void warn(final String message, final ErrorLogSpec errorLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void warn(final String message, final ErrorLogSpec errorLogSpec, final String... args) { + // no operation + } +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpMetricLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpMetricLog.java new file mode 100644 index 0000000..1c67862 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpMetricLog.java @@ -0,0 +1,89 @@ +/* + * ================================================================================ + * 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.noop; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.MetricLog; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * A no operation implementation of Metric Log + * + * @author Rajiv Singla + */ +public class NoOpMetricLog implements MetricLog { + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final MetricLogSpec metricLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + // no operation + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final MetricLogSpec metricLogSpec, + final String... args) { + // no operation + } + + @Override + public void info(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void info(final String message, final MetricLogSpec metricLogSpec, final String... args) { + // no operation + } + + @Override + public void warn(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void warn(final String message, final MetricLogSpec metricLogSpec, final String... args) { + // no operation + } + + @Override + public void error(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void error(final String message, final MetricLogSpec metricLogSpec, final String... args) { + // no operation + } + + @Override + public void fatal(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void fatal(final String message, final MetricLogSpec metricLogSpec, final String... args) { + // no operation + } +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/package-info.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/package-info.java new file mode 100644 index 0000000..f7ed917 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/package-info.java @@ -0,0 +1,26 @@ +/* + * ================================================================================ + * 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 no operation implementation of EELF Logging API. Generally used as a fallback when no EELF Logging + * implementation is detected in the application classpath + * + * @author Rajiv Singla + */ +package org.onap.dcae.utils.eelf.logger.api.noop; diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AppLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AppLogSpec.java new file mode 100644 index 0000000..83643fb --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AppLogSpec.java @@ -0,0 +1,32 @@ +/* + * ================================================================================ + * 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.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; + +/** + * App Log spec captures fields which are fixed for the duration of application once its instance is created. They + * should be populated for all specifications regardless of if they are relevant to that specification + * + * @author Rajiv Singla + */ +public interface AppLogSpec extends AppLogInfo { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AuditLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AuditLogSpec.java new file mode 100644 index 0000000..46360b1 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AuditLogSpec.java @@ -0,0 +1,42 @@ +/* + * ================================================================================ + * 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.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; + +/** + * Captures fields required for EELF Audit Log Specification. + * + * @author Rajiv Singla + */ +public interface AuditLogSpec extends + // request id must be preset for all log specifications + RequestIdLogInfo, + // duration related fields + RequestTimingLogInfo, + // app acting as a service fields + ServiceLogInfo, ResponseLogInfo { + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/DebugLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/DebugLogSpec.java new file mode 100644 index 0000000..ac4bd64 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/DebugLogSpec.java @@ -0,0 +1,34 @@ +/* + * ================================================================================ + * 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.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; + +/** + * Captures fields required for EELF Debug Log Specification. + * NOTE: As per specification debug log is optional + * + * @author Rajiv Singla + */ +public interface DebugLogSpec extends + // request id must be preset for all log specifications + RequestIdLogInfo { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/ErrorLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/ErrorLogSpec.java new file mode 100644 index 0000000..455f433 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/ErrorLogSpec.java @@ -0,0 +1,42 @@ +/* + * ================================================================================ + * 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.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; + +/** + * Captures fields required for EELF Error Log Specification + * + * @author Rajiv Singla + */ +public interface ErrorLogSpec extends + // request id must be preset for all log specifications + RequestIdLogInfo, + // app acting as a service fields + ServiceLogInfo, + // app calling external service fields + TargetServiceLogInfo, + // error details fields + ErrorLogInfo { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/MetricLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/MetricLogSpec.java new file mode 100644 index 0000000..5b5f698 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/MetricLogSpec.java @@ -0,0 +1,36 @@ +/* + * ================================================================================ + * 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.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; + +/** + * Captures fields required for EELF Metric Log Specification. + * + * @author Rajiv Singla + */ +public interface MetricLogSpec extends + // Audit log spec + AuditLogSpec, + // App calling external service fields + TargetServiceLogInfo { + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/OptionalLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/OptionalLogSpec.java new file mode 100644 index 0000000..dac08ab --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/OptionalLogSpec.java @@ -0,0 +1,39 @@ +/* + * ================================================================================ + * 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.spec; + +import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo; + +/** + * Captures fields which are optional or derived from other fields + * + * @author Rajiv Singla + */ +public interface OptionalLogSpec extends + // message fields are mostly auto generated or can be derived from other fields + MessageLogInfo, + // Code log info can be derived by the underlying logging framework or provided optionally by the app + CodeLogInfo, + // custom and misc log info are mostly optional + CustomFieldsLogInfo, MiscLogInfo { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/package-info.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/package-info.java new file mode 100644 index 0000000..b4c1df8 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/package-info.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * 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 various EELF Logging Specifications. + * <p> + * Some specifications are fixed for the whole duration of the + * application, some specification are either optional or derived and some are required for particular EELF Logging + * specification. These logging specification are composed of various logging information in + * {@link org.onap.dcae.utils.eelf.logger.api.info} package + */ +package org.onap.dcae.utils.eelf.logger.api.spec; diff --git a/eelf-logger/eelf-logger-logback-impl/pom.xml b/eelf-logger/eelf-logger-logback-impl/pom.xml new file mode 100644 index 0000000..165d216 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/pom.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> + +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.dcaegen2.utils</groupId> + <artifactId>eelf-logger</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>eelf-logger-logback-impl</artifactId> + <packaging>jar</packaging> + + <!-- EELF LOGGING IMPLEMENTATION BACKED BY LOGBACK LOGGING FRAMEWORK--> + <name>dcaegen2-utils-eelf-logger-logback-impl</name> + <description>Implements EEL Logging Specification using Logback</description> + + <properties> + <main.basedir>${project.parent.basedir}</main.basedir> + </properties> + + <dependencies> + + <!-- ECOMP LOGGER MODEL --> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>eelf-logger-model</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- LOGBACK --> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + </dependency> + + </dependencies> + + +</project> diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/EELFLoggerDefaults.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/EELFLoggerDefaults.java new file mode 100644 index 0000000..eceaf20 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/EELFLoggerDefaults.java @@ -0,0 +1,105 @@ +/* + * ================================================================================ + * 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.logback; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogInfo; +import org.onap.dcae.utils.eelf.logger.model.info.AppLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.CustomFieldsLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ErrorLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.MiscLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ResponseLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.TargetServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.OptionalLogSpecImpl; + +import java.util.Date; + +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.createDefaultAppLogInfo; + + +/** + * This utility class various default implementations for EELF Logger. Users should use these default rather then + * creating their own {@link LogInfo} objects. + * + * @author Rajiv Singla + */ +public class EELFLoggerDefaults { + + private static final String UNKNOWN_FIELD_VALUE = "UNKNOWN"; + + // =============== APP LOG SPEC ======================// + /** + * Provides Default {@link AppLogInfoImpl} + */ + public static final AppLogInfoImpl DEFAULT_APP_LOG_INFO = createDefaultAppLogInfo(); + + + // =============== AUDIT LOG SPEC ===================== // + + private static final String DEFAULT_PARTNER_NAME = + System.getProperty("user.name") != null ? System.getProperty("user.name") : UNKNOWN_FIELD_VALUE; + + public static final ServiceLogInfoImpl DEFAULT_SERVICE_LOG_INFO = + new ServiceLogInfoImpl(UNKNOWN_FIELD_VALUE, DEFAULT_PARTNER_NAME, ""); + + + public static final RequestTimingLogInfoImpl DEFAULT_REQUEST_TIMING_LOG_INFO = + new RequestTimingLogInfoImpl(new Date(), new Date(), null); + + + public static final ResponseLogInfoImpl DEFAULT_RESPONSE_LOG_INFO = + new ResponseLogInfoImpl(900, "UNDEFINED"); + + + // =============== METRIC LOG SPEC ===================== // + + public static final TargetServiceLogInfoImpl DEFAULT_TARGET_SERVICE_LOG_INFO = + new TargetServiceLogInfoImpl(UNKNOWN_FIELD_VALUE, UNKNOWN_FIELD_VALUE, UNKNOWN_FIELD_VALUE); + + // =============== ERROR LOG SPEC ===================== // + + public static final ErrorLogInfoImpl DEFAULT_ERROR_LOG_INFO = + new ErrorLogInfoImpl(900, "UNDEFINED ERROR"); + + + // ============= OPTIONAL LOG SPEC =================== // + + /** + * Provides Default {@link CustomFieldsLogInfoImpl} + */ + public static final CustomFieldsLogInfoImpl DEFAULT_CUSTOM_FIELDS_LOG_INFO = + new CustomFieldsLogInfoImpl("", "", "", ""); + + /** + * Provides Default {@link MiscLogInfoImpl} + */ + public static final MiscLogInfoImpl DEFAULT_MISC_LOG_INFO = new MiscLogInfoImpl("", ""); + + + /** + * Provides Default {@link OptionalLogSpecImpl} + */ + public static final OptionalLogSpecImpl DEFAULT_OPTIONAL_LOG_SPEC = new OptionalLogSpecImpl(null, null, + DEFAULT_CUSTOM_FIELDS_LOG_INFO, DEFAULT_MISC_LOG_INFO); + + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/filter/MarkerFilter.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/filter/MarkerFilter.java new file mode 100644 index 0000000..a664190 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/filter/MarkerFilter.java @@ -0,0 +1,71 @@ +/* + * ================================================================================ + * 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.logback.filter; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.filter.AbstractMatcherFilter; +import ch.qos.logback.core.spi.FilterReply; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Logback Marker filter + * + * @author Rajiv Singla + */ +public class MarkerFilter extends AbstractMatcherFilter<ILoggingEvent> { + + private String markersString; + private Set<Marker> markersToAccept = new HashSet<>(); + + @Override + public FilterReply decide(final ILoggingEvent event) { + + if (!isStarted()) { + return FilterReply.NEUTRAL; + } + + if (markersToAccept.contains(event.getMarker())) { + return onMatch; + } else { + return onMismatch; + } + } + + public void setMarkers(String markersString) { + this.markersString = markersString; + } + + + public void start() { + + if (markersString != null && markersString.trim().split(",").length > 0) { + + final String[] markerStrings = markersString.trim().split(","); + for (String markerString : markerStrings) { + markersToAccept.add(MarkerFactory.getMarker(markerString.trim())); + } + super.start(); + } + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/AuditLogLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/AuditLogLayout.java new file mode 100644 index 0000000..5d848ac --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/AuditLogLayout.java @@ -0,0 +1,81 @@ +/* + * ================================================================================ + * 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.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; + + +/** + * Audit log layout generates log messages as per EELF Audit Log Specifications + * + * @author Rajiv Singla + */ +public class AuditLogLayout extends LayoutBase<ILoggingEvent> { + + @Override + public String doLayout(final ILoggingEvent event) { + + final AppLogSpec appLogSpec = LogUtils.getAppLogSpec(); + final LogLevelCategory logLevelCategory = LogUtils.getLogLevelCategory(); + final Class<?> loggerClass = LogUtils.getLoggerClass(); + final OptionalLogSpec optionalLogSpec = LogUtils.getOptionalLogSpec(loggerClass, logLevelCategory); + final AuditLogSpec auditLogSpec = LogUtils.getAuditLogSpec(); + + final String beginTimestamp = LogUtils.formatDate(auditLogSpec.getBeginTimestamp()); + final String endTimestamp = LogUtils.formatDate(auditLogSpec.getEndTimestamp()); + + final String[] auditLogValues = { + beginTimestamp, + endTimestamp, + auditLogSpec.getRequestId(), + appLogSpec.getServiceInstanceID(), + event.getThreadName(), + appLogSpec.getVirtualServerName(), + auditLogSpec.getServiceName(), + auditLogSpec.getPartnerName(), + optionalLogSpec.getStatusCode().name(), + auditLogSpec.getResponseCode().toString(), + auditLogSpec.getResponseDescription(), + appLogSpec.getInstanceUUID(), + logLevelCategory != null ? logLevelCategory.name() : "", + optionalLogSpec.getAlertSeverity().getSeverityCode(), + appLogSpec.getServerIPAddress(), + auditLogSpec.getElapsedTime().toString(), + appLogSpec.getServerFQDN(), + auditLogSpec.getClientIPAddress(), + optionalLogSpec.getClassName(), + optionalLogSpec.getUnused(), + optionalLogSpec.getProcessId(), + optionalLogSpec.getCustomField1(), + optionalLogSpec.getCustomField2(), + optionalLogSpec.getCustomField3(), + optionalLogSpec.getCustomField4(), + event.getFormattedMessage() + }; + + return LogUtils.createLogMessageString(auditLogValues); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ConsoleLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ConsoleLayout.java new file mode 100644 index 0000000..589d863 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ConsoleLayout.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.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Marker; + +/** + * Console layout is used to log messages on the console for debugging purposes. + * + * @author Rajiv Singla + */ +public class ConsoleLayout extends LayoutBase<ILoggingEvent> { + + private static final MetricLogLayout METRIC_LOG_LAYOUT = new MetricLogLayout(); + private static final AuditLogLayout AUDIT_LOG_LAYOUT = new AuditLogLayout(); + private static final ErrorLogLayout ERROR_LOG_LAYOUT = new ErrorLogLayout(); + private static final DebugLogLayout DEBUG_LOG_LAYOUT = new DebugLogLayout(); + + @Override + public String doLayout(final ILoggingEvent event) { + + final Marker eventMarker = event.getMarker(); + + if (eventMarker.equals(LogUtils.AUDIT_LOG_MARKER)) { + return AUDIT_LOG_LAYOUT.doLayout(event); + } else if (eventMarker.equals(LogUtils.METRIC_LOG_MARKER)) { + return METRIC_LOG_LAYOUT.doLayout(event); + } else if (eventMarker.equals(LogUtils.ERROR_LOG_MARKER)) { + return ERROR_LOG_LAYOUT.doLayout(event); + } else if (eventMarker.equals(LogUtils.DEBUG_LOG_MARKER)) { + return DEBUG_LOG_LAYOUT.doLayout(event); + } + + return "Console Layout not defined for Marker: " + eventMarker; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/DebugLogLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/DebugLogLayout.java new file mode 100644 index 0000000..e7b1cd4 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/DebugLogLayout.java @@ -0,0 +1,54 @@ +/* + * ================================================================================ + * 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.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +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; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; + + +/** + * @author Rajiv Singla + */ +public class DebugLogLayout extends LayoutBase<ILoggingEvent> { + + @Override + public String doLayout(final ILoggingEvent event) { + + final LogLevelCategory logLevelCategory = LogUtils.getLogLevelCategory(); + final Class<?> loggerClass = LogUtils.getLoggerClass(); + final OptionalLogSpec optionalLogSpec = LogUtils.getOptionalLogSpec(loggerClass, logLevelCategory); + + final DebugLogSpec debugLogSpec = LogUtils.getDebugLogSpec(); + + final String creationTimestamp = LogUtils.formatDate(optionalLogSpec.getCreationTimestamp()); + + final String[] debugLogValues = { + creationTimestamp, + debugLogSpec.getRequestId(), + event.getFormattedMessage() + }; + + return LogUtils.createLogMessageString(debugLogValues); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ErrorLogLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ErrorLogLayout.java new file mode 100644 index 0000000..4eefe36 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ErrorLogLayout.java @@ -0,0 +1,64 @@ +/* + * ================================================================================ + * 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.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +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; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; + + +/** + * Error Log Layout generates log messages as per EELF Error Log Specifications + * + * @author Rajiv Singla + */ +public class ErrorLogLayout extends LayoutBase<ILoggingEvent> { + + @Override + public String doLayout(final ILoggingEvent event) { + + final LogLevelCategory logLevelCategory = LogUtils.getLogLevelCategory(); + final Class<?> loggerClass = LogUtils.getLoggerClass(); + final OptionalLogSpec optionalLogSpec = LogUtils.getOptionalLogSpec(loggerClass, logLevelCategory); + + final ErrorLogSpec errorLogSpec = LogUtils.getErrorLogSpec(); + + final String creationTimestamp = LogUtils.formatDate(optionalLogSpec.getCreationTimestamp()); + + final String[] errorLogValues = { + creationTimestamp, + errorLogSpec.getRequestId(), + event.getThreadName(), + errorLogSpec.getServiceName(), + errorLogSpec.getPartnerName(), + errorLogSpec.getTargetEntity(), + errorLogSpec.getTargetServiceName(), + logLevelCategory != null ? logLevelCategory.name() : "", + errorLogSpec.getErrorCode() != null ? errorLogSpec.getErrorCode().toString() : "", + errorLogSpec.getErrorDescription(), + event.getFormattedMessage() + }; + + return LogUtils.createLogMessageString(errorLogValues); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/MetricLogLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/MetricLogLayout.java new file mode 100644 index 0000000..509ff8f --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/MetricLogLayout.java @@ -0,0 +1,83 @@ +/* + * ================================================================================ + * 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.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; + +/** + * Metric Log Layout generates log messages as per EELF Metric Log Specifications + * + * @author Rajiv Singla + */ +public class MetricLogLayout extends LayoutBase<ILoggingEvent> { + + @Override + public String doLayout(final ILoggingEvent event) { + + final AppLogSpec appLogSpec = LogUtils.getAppLogSpec(); + final LogLevelCategory logLevelCategory = LogUtils.getLogLevelCategory(); + final Class<?> loggerClass = LogUtils.getLoggerClass(); + final OptionalLogSpec optionalLogSpec = LogUtils.getOptionalLogSpec(loggerClass, logLevelCategory); + final MetricLogSpec metricLogSpec = LogUtils.getMetricLogSpec(); + + final String beginTimestamp = LogUtils.formatDate(metricLogSpec.getBeginTimestamp()); + final String endTimestamp = LogUtils.formatDate(metricLogSpec.getEndTimestamp()); + + final String[] metricLogValues = { + beginTimestamp, + endTimestamp, + metricLogSpec.getRequestId(), + appLogSpec.getServiceInstanceID(), + event.getThreadName(), + appLogSpec.getVirtualServerName(), + metricLogSpec.getServiceName(), + metricLogSpec.getPartnerName(), + metricLogSpec.getTargetEntity(), + metricLogSpec.getTargetServiceName(), + optionalLogSpec.getStatusCode().name(), + metricLogSpec.getResponseCode().toString(), + metricLogSpec.getResponseDescription(), + appLogSpec.getInstanceUUID(), + logLevelCategory != null ? logLevelCategory.name() : "", + optionalLogSpec.getAlertSeverity().getSeverityCode(), + appLogSpec.getServerIPAddress(), + metricLogSpec.getElapsedTime().toString(), + appLogSpec.getServerFQDN(), + metricLogSpec.getClientIPAddress(), + optionalLogSpec.getClassName(), + optionalLogSpec.getUnused(), + optionalLogSpec.getProcessId(), + metricLogSpec.getTargetVirtualEntity(), + optionalLogSpec.getCustomField1(), + optionalLogSpec.getCustomField2(), + optionalLogSpec.getCustomField3(), + optionalLogSpec.getCustomField4(), + event.getFormattedMessage() + }; + + return LogUtils.createLogMessageString(metricLogValues); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/listener/LogbackStartupListener.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/listener/LogbackStartupListener.java new file mode 100644 index 0000000..b02c471 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/listener/LogbackStartupListener.java @@ -0,0 +1,128 @@ +/* + * ================================================================================ + * 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.logback.listener; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.spi.LoggerContextListener; +import ch.qos.logback.core.Context; +import ch.qos.logback.core.spi.ContextAwareBase; +import ch.qos.logback.core.spi.LifeCycle; +import ch.qos.logback.core.status.InfoStatus; +import ch.qos.logback.core.status.WarnStatus; +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; +import org.onap.dcae.utils.eelf.logger.model.spec.AppLogSpecImpl; + + +import java.io.File; + +import static org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults.DEFAULT_APP_LOG_INFO; +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.APP_LOG_SPEC_KEY; +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.CUSTOM_MDC_MAP; + + +/** + * Logback Startup Listener is used to inject {@link AppLogInfo} + * + * @author Rajiv Singla + */ +public class LogbackStartupListener extends ContextAwareBase implements LoggerContextListener, LifeCycle { + + private static final String APP_LOG_INFO_KEY_IN_CONTEXT = "APP_LOG_INFO"; + private static final String CONTEXT_COMPONENT_NAME_PROPERTY_KEY = "componentName"; + private static final String CONTEXT_MODIFY_WINDOWS_LOG_PATH_PROPERTY_KEY = "modifyLogPathInWindows"; + private static final String CONTEXT_LOG_DIRECTORY_PROPERTY_KEY = "logDirectory"; + private static final String CONTEXT_DEBUG_LOG_DIRECTORY_PROPERTY_KEY = "debugLogDirectory"; + private static final String CONTEXT_APPEND_DIRECTORY_PROPERTY_KEY = "appendDirectory"; + + private boolean started = false; + + @Override + public boolean isResetResistant() { + return true; + } + + @Override + public void onStart(final LoggerContext context) { + + } + + @Override + public void onReset(final LoggerContext context) { + + } + + @Override + public void onStop(final LoggerContext context) { + + } + + @Override + public void onLevelChange(final Logger logger, final Level level) { + + } + + @Override + public void start() { + if (started) { + return; + } + + Context context = getContext(); + + CUSTOM_MDC_MAP.put(APP_LOG_SPEC_KEY, new AppLogSpecImpl(DEFAULT_APP_LOG_INFO)); + context.putObject(APP_LOG_INFO_KEY_IN_CONTEXT, DEFAULT_APP_LOG_INFO); + context.getStatusManager().add(new InfoStatus("Initialized APP LOG INFO", DEFAULT_APP_LOG_INFO)); + + // if Component name is not set derive from jar file name + if (context.getProperty(CONTEXT_COMPONENT_NAME_PROPERTY_KEY) == null) { + final String appName = + new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getName(); + context.putProperty(CONTEXT_COMPONENT_NAME_PROPERTY_KEY, appName); + context.getStatusManager().add(new WarnStatus( + "No componentName Property found. Deriving it from jar name", appName)); + } + + // if modify windows log path is enabled - then append target before log directories + if (context.getProperty(CONTEXT_MODIFY_WINDOWS_LOG_PATH_PROPERTY_KEY).equalsIgnoreCase("true")) { + final String os = System.getProperty("os.name"); + if (os != null && os.startsWith("Windows")) { + final String logDirectory = context.getProperty(CONTEXT_LOG_DIRECTORY_PROPERTY_KEY); + final String debugLogDirectory = context.getProperty(CONTEXT_DEBUG_LOG_DIRECTORY_PROPERTY_KEY); + final String appendDir = context.getProperty(CONTEXT_APPEND_DIRECTORY_PROPERTY_KEY); + context.putProperty(CONTEXT_LOG_DIRECTORY_PROPERTY_KEY, appendDir + "/" + logDirectory); + context.putProperty(CONTEXT_DEBUG_LOG_DIRECTORY_PROPERTY_KEY, appendDir + "/" + debugLogDirectory); + } + } + + started = true; + } + + @Override + public void stop() { + + } + + @Override + public boolean isStarted() { + return started; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImpl.java new file mode 100644 index 0000000..947b4c2 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImpl.java @@ -0,0 +1,119 @@ +/* + * ================================================================================ + * 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.logback.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.AuditLog; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Logger; + + +/** + * Audit Log Logback Implementation + * + * @author Rajiv Singla + */ +public class AuditLogImpl implements AuditLog { + + private final Logger logger; + private final Class<?> clazz; + + public AuditLogImpl(final Logger logger, final Class<?> clazz) { + this.logger = logger; + this.clazz = clazz; + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final AuditLogSpec + auditLogSpec, final OptionalLogSpec optionalLogSpec, final String... args) { + // if audit log spec or log level category is null throw an exception + if (auditLogSpec == null || logLevelCategory == null) { + throw new IllegalArgumentException("Audit Log Spec and Log level category must not be null"); + } + // required fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOG_LEVEL_CATEGORY_KEY, logLevelCategory); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.AUDIT_LOG_SPEC_KEY, auditLogSpec); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOGGER_CLASS_KEY, clazz); + // optional fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.OPTIONAL_LOG_SPEC_KEY, optionalLogSpec); + + // log with normalized log level category + LogUtils.logWithLogLevel(logLevelCategory, logger, LogUtils.AUDIT_LOG_MARKER, message, args); + + // clean up + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOG_LEVEL_CATEGORY_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.AUDIT_LOG_SPEC_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOGGER_CLASS_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.OPTIONAL_LOG_SPEC_KEY); + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final AuditLogSpec auditLogSpec, + final String... args) { + log(logLevelCategory, message, auditLogSpec, null, args); + } + + @Override + public void info(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.INFO, message, auditLogSpec, optionalLogSpec, args); + } + + @Override + public void info(final String message, final AuditLogSpec auditLogSpec, final String... args) { + info(message, auditLogSpec, null, args); + } + + @Override + public void warn(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.WARN, message, auditLogSpec, optionalLogSpec, args); + } + + @Override + public void warn(final String message, final AuditLogSpec auditLogSpec, final String... args) { + warn(message, auditLogSpec, null, args); + } + + @Override + public void error(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.ERROR, message, auditLogSpec, optionalLogSpec, args); + } + + @Override + public void error(final String message, final AuditLogSpec auditLogSpec, final String... args) { + error(message, auditLogSpec, null, args); + } + + @Override + public void fatal(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.FATAL, message, auditLogSpec, optionalLogSpec, args); + } + + @Override + public void fatal(final String message, final AuditLogSpec auditLogSpec, final String... args) { + fatal(message, auditLogSpec, null, args); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImpl.java new file mode 100644 index 0000000..1e17f3b --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImpl.java @@ -0,0 +1,88 @@ +/* + * ================================================================================ + * 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.logback.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.DebugLog; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Logger; + + +/** + * Debug Log Logback Implementation + * + * @author Rajiv Singla + */ +public class DebugLogImpl implements DebugLog { + + private final Logger logger; + private final Class<?> clazz; + + public DebugLogImpl(final Logger logger, final Class<?> clazz) { + this.logger = logger; + this.clazz = clazz; + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + + // if log level category is null throw an exception + if (logLevelCategory == null) { + throw new IllegalArgumentException("Log level category must not be null"); + } + + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOG_LEVEL_CATEGORY_KEY, logLevelCategory); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.DEBUG_LOG_SPEC_KEY, debugLogSpec); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOGGER_CLASS_KEY, clazz); + // optional fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.OPTIONAL_LOG_SPEC_KEY, optionalLogSpec); + + // log with normalized log level category + LogUtils.logWithLogLevel(logLevelCategory, logger, LogUtils.DEBUG_LOG_MARKER, message, args); + + // clean up + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOG_LEVEL_CATEGORY_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.DEBUG_LOG_SPEC_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOGGER_CLASS_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.OPTIONAL_LOG_SPEC_KEY); + + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec, + final String... args) { + log(logLevelCategory, message, debugLogSpec, null, args); + } + + @Override + public void debug(final String message, final DebugLogSpec debugLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.DEBUG, message, debugLogSpec, optionalLogSpec, args); + } + + @Override + public void debug(final String message, final DebugLogSpec debugLogSpec, final String... args) { + debug(message, debugLogSpec, null, args); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerContextImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerContextImpl.java new file mode 100644 index 0000000..e5be1d8 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerContextImpl.java @@ -0,0 +1,57 @@ +/* + * ================================================================================ + * 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.logback.log; + +import org.onap.dcae.utils.eelf.logger.api.log.EELFLoggerContext; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; +import org.onap.dcae.utils.eelf.logger.model.spec.AppLogSpecImpl; + +import static org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults.DEFAULT_APP_LOG_INFO; +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.APP_LOG_SPEC_KEY; +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.CUSTOM_MDC_MAP; + + +/** + * Default EELF Logger Context which contains EELF Specs which are usually constant for entire life cycle of the + * application + * + * @author Rajiv Singla + */ +public class EELFLoggerContextImpl implements EELFLoggerContext { + + @Override + public AppLogSpec getAppLogSpec() { + return CUSTOM_MDC_MAP.get(APP_LOG_SPEC_KEY) == null ? null : (AppLogSpec) CUSTOM_MDC_MAP.get(APP_LOG_SPEC_KEY); + } + + @Override + public void setAppLogSpec(final AppLogSpec appLogSpec) { + if (appLogSpec == null) { + CUSTOM_MDC_MAP.put(APP_LOG_SPEC_KEY, new AppLogSpecImpl(DEFAULT_APP_LOG_INFO)); + } else { + CUSTOM_MDC_MAP.put(APP_LOG_SPEC_KEY, appLogSpec); + } + } + + @Override + public boolean isInitialized() { + return CUSTOM_MDC_MAP.get(APP_LOG_SPEC_KEY) == null; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerImpl.java new file mode 100644 index 0000000..3f1e716 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerImpl.java @@ -0,0 +1,81 @@ +/* + * ================================================================================ + * 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.logback.log; + + +import org.onap.dcae.utils.eelf.logger.api.log.AuditLog; +import org.onap.dcae.utils.eelf.logger.api.log.DebugLog; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLoggerContext; +import org.onap.dcae.utils.eelf.logger.api.log.ErrorLog; +import org.onap.dcae.utils.eelf.logger.api.log.MetricLog; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * EELF Logger Logback Implementation + * + * @author Rajiv Singla + */ +public class EELFLoggerImpl implements EELFLogger { + + private Logger logger; + private Class<?> clazz; + + public EELFLoggerImpl() { + // no arg constructor required for Service Loader discovery + } + + public EELFLoggerImpl(final Class<?> clazz) { + logger = LoggerFactory.getLogger(clazz); + this.clazz = clazz; + } + + + @Override + public AuditLog auditLog() { + return new AuditLogImpl(logger, clazz); + } + + @Override + public MetricLog metricLog() { + return new MetricLogImpl(logger, clazz); + } + + @Override + public ErrorLog errorLog() { + return new ErrorLogImpl(logger, clazz); + } + + @Override + public DebugLog debugLog() { + return new DebugLogImpl(logger, clazz); + } + + @Override + public EELFLoggerContext loggingContext() { + return new EELFLoggerContextImpl(); + } + + @Override + public String toString() { + return "EELF LOGBACK IMP"; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImpl.java new file mode 100644 index 0000000..5d8f272 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImpl.java @@ -0,0 +1,98 @@ +/* + * ================================================================================ + * 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.logback.log; + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.ErrorLog; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Logger; + + +/** + * Error Log Logback Implementation + * + * @author Rajiv Singla + */ +public class ErrorLogImpl implements ErrorLog { + + private final Logger logger; + private final Class<?> clazz; + + public ErrorLogImpl(final Logger logger, final Class<?> clazz) { + this.logger = logger; + this.clazz = clazz; + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final ErrorLogSpec errorLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + + // if error log spec or log level category is null throw an exception + if (errorLogSpec == null || logLevelCategory == null) { + throw new IllegalArgumentException("Error Log Spec and Log level category must not be null"); + } + + // required fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOG_LEVEL_CATEGORY_KEY, logLevelCategory); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.ERROR_LOG_SPEC_KEY, errorLogSpec); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOGGER_CLASS_KEY, clazz); + // optional fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.OPTIONAL_LOG_SPEC_KEY, optionalLogSpec); + + // log with normalized log level category + LogUtils.logWithLogLevel(logLevelCategory, logger, LogUtils.ERROR_LOG_MARKER, message, args); + + // clean up + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOG_LEVEL_CATEGORY_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.ERROR_LOG_SPEC_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOGGER_CLASS_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.OPTIONAL_LOG_SPEC_KEY); + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final ErrorLogSpec errorLogSpec, + final String... args) { + log(logLevelCategory, message, errorLogSpec, null, args); + } + + @Override + public void error(final String message, final ErrorLogSpec errorLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.ERROR, message, errorLogSpec, null, args); + } + + @Override + public void error(final String message, final ErrorLogSpec errorLogSpec, final String... args) { + error(message, errorLogSpec, null, args); + } + + @Override + public void warn(final String message, final ErrorLogSpec errorLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.WARN, message, errorLogSpec, null, args); + } + + @Override + public void warn(final String message, final ErrorLogSpec errorLogSpec, final String... args) { + warn(message, errorLogSpec, null, args); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImpl.java new file mode 100644 index 0000000..5857835 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImpl.java @@ -0,0 +1,120 @@ +/* + * ================================================================================ + * 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.logback.log; + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.MetricLog; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Logger; + +/** + * Metric Log Logback Implementation + * + * @author Rajiv Singla + */ +public class MetricLogImpl implements MetricLog { + + private final Logger logger; + private final Class<?> clazz; + + public MetricLogImpl(final Logger logger, final Class<?> clazz) { + this.logger = logger; + this.clazz = clazz; + } + + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final MetricLogSpec metricLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + + // if metric log spec or log level category is null throw an exception + if (metricLogSpec == null || logLevelCategory == null) { + throw new IllegalArgumentException("Metric Log Spec and Log level category must not be null"); + } + + // required fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOG_LEVEL_CATEGORY_KEY, logLevelCategory); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.METRIC_LOG_SPEC_KEY, metricLogSpec); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOGGER_CLASS_KEY, clazz); + // optional fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.OPTIONAL_LOG_SPEC_KEY, optionalLogSpec); + + // log with normalized log level category + LogUtils.logWithLogLevel(logLevelCategory, logger, LogUtils.METRIC_LOG_MARKER, message, args); + + // clean up + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOG_LEVEL_CATEGORY_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.METRIC_LOG_SPEC_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOGGER_CLASS_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.OPTIONAL_LOG_SPEC_KEY); + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final MetricLogSpec metricLogSpec, + final String... args) { + log(logLevelCategory, message, metricLogSpec, null, args); + } + + @Override + public void info(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.INFO, message, metricLogSpec, optionalLogSpec, args); + } + + @Override + public void info(final String message, final MetricLogSpec metricLogSpec, final String... args) { + log(LogLevelCategory.INFO, message, metricLogSpec, args); + } + + @Override + public void warn(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.WARN, message, metricLogSpec, optionalLogSpec, args); + } + + @Override + public void warn(final String message, final MetricLogSpec metricLogSpec, final String... args) { + warn(message, metricLogSpec, null, args); + } + + @Override + public void error(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.ERROR, message, metricLogSpec, optionalLogSpec, args); + } + + @Override + public void error(final String message, final MetricLogSpec metricLogSpec, final String... args) { + error(message, metricLogSpec, null, args); + } + + @Override + public void fatal(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.FATAL, message, metricLogSpec, optionalLogSpec, args); + } + + @Override + public void fatal(final String message, final MetricLogSpec metricLogSpec, final String... args) { + fatal(message, metricLogSpec, null, args); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/CompositePropertyResolver.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/CompositePropertyResolver.java new file mode 100644 index 0000000..e5f1bc1 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/CompositePropertyResolver.java @@ -0,0 +1,53 @@ +/* + * ================================================================================ + * 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.logback.resolver; + +import java.util.Arrays; +import java.util.List; + +/** + * A composite property resolver can look under different resolvers in order of given property resolvers + * + * @author Rajiv Singla + */ +public class CompositePropertyResolver implements PropertyResolver { + + private static final long serialVersionUID = 1L; + + private final List<PropertyResolver> propertyResolvers; + + public CompositePropertyResolver(PropertyResolver... propertyResolvers) { + this.propertyResolvers = Arrays.asList(propertyResolvers); + } + + @Override + public String resolve(final List<String> propertyNames) { + // resolver property in given resolvers in the same order they are defined + for (PropertyResolver propertyResolver : propertyResolvers) { + final String propertyValue = propertyResolver.resolve(propertyNames); + if (propertyValue != null) { + return propertyValue; + } + } + + return null; + } + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/EnvironmentPropertyResolver.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/EnvironmentPropertyResolver.java new file mode 100644 index 0000000..8f3d59f --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/EnvironmentPropertyResolver.java @@ -0,0 +1,46 @@ +/* + * ================================================================================ + * 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.logback.resolver; + +import java.util.List; + +/** + * Looks up Property values inside HOST environment variables + * + * @author Rajiv Singla + */ +public class EnvironmentPropertyResolver implements PropertyResolver { + + private static final long serialVersionUID = 1L; + + @Override + public String resolve(final List<String> propertyNames) { + + // check if system environment variables have property names set + for (final String propertyName : propertyNames) { + final String propertyValue = System.getenv(propertyName); + if (propertyValue != null) { + return propertyValue; + } + } + + return null; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/PropertyResolver.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/PropertyResolver.java new file mode 100644 index 0000000..758de61 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/PropertyResolver.java @@ -0,0 +1,41 @@ +/* + * ================================================================================ + * 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.logback.resolver; + +import java.io.Serializable; +import java.util.List; + +/** + * A resolver is used to resolve properties + * + * @author Rajiv Singla + */ +public interface PropertyResolver extends Serializable { + + /** + * Returns resolved property value + * + * @param propertyNames names under which property can be found + * + * @return property value + */ + String resolve(List<String> propertyNames); + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/SystemPropertyResolver.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/SystemPropertyResolver.java new file mode 100644 index 0000000..674b00b --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/SystemPropertyResolver.java @@ -0,0 +1,59 @@ +/* + * ================================================================================ + * 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.logback.resolver; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * Resolve System Properties passed in by -DpropertyName=propertyValue when invoking + * via java command line arguments + * + * @author Rajiv Singla + */ +public class SystemPropertyResolver implements PropertyResolver { + + private static final long serialVersionUID = 1L; + + @Override + public String resolve(final List<String> propertyNames) { + + // Get all system Properties + final Properties systemProperties = System.getProperties(); + + for (Map.Entry<Object, Object> systemEntries : systemProperties.entrySet()) { + + if (systemEntries.getKey() instanceof String) { + final String systemKey = (String) systemEntries.getKey(); + + // if system properties contain any of the property names - ignoring case then return its value + for (String propertyName : propertyNames) { + if (propertyName.equalsIgnoreCase(systemKey)) { + return (String) systemEntries.getValue(); + } + } + + } + } + + return null; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/utils/LogUtils.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/utils/LogUtils.java new file mode 100644 index 0000000..f5c558b --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/utils/LogUtils.java @@ -0,0 +1,590 @@ +/* + * ================================================================================ + * 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.logback.utils; + +import ch.qos.logback.core.CoreConstants; +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.info.NagiosAlertLevel; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestStatusCode; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.logback.resolver.CompositePropertyResolver; +import org.onap.dcae.utils.eelf.logger.logback.resolver.EnvironmentPropertyResolver; +import org.onap.dcae.utils.eelf.logger.logback.resolver.SystemPropertyResolver; +import org.onap.dcae.utils.eelf.logger.model.info.AppLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.CodeLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.MessageLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.AppLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.OptionalLogSpecImpl; +import org.slf4j.Logger; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; +import java.util.UUID; + + + +/** + * Contains various logging utility methods + * + * @author Rajiv Singla + */ +public abstract class LogUtils { + + private static final String LOG_MESSAGE_DELIMITER = "|"; + private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; + private static final String DATE_TIMEZONE = "UTC"; + // property resolver which looks up system property and the environment properties + private static final CompositePropertyResolver COMPOSITE_PROPERTY_RESOLVER = + new CompositePropertyResolver(new SystemPropertyResolver(), new EnvironmentPropertyResolver()); + + // Custom MDC Map Keys + public static final String APP_LOG_SPEC_KEY = "APP_LOG_SPEC"; + public static final String AUDIT_LOG_SPEC_KEY = "AUDIT_LOG_SPEC"; + public static final String METRIC_LOG_SPEC_KEY = "METRIC_LOG_SPEC"; + public static final String ERROR_LOG_SPEC_KEY = "ERROR_LOG_SPEC"; + public static final String DEBUG_LOG_SPEC_KEY = "DEBUG_LOG_SPEC"; + public static final String OPTIONAL_LOG_SPEC_KEY = "OPTIONAL_LOG_SPEC"; + public static final String LOG_LEVEL_CATEGORY_KEY = "LOG_LEVEL_CATEGORY"; + public static final String LOGGER_CLASS_KEY = "LOGGER_CLASS_KEY"; + + // markers + public static final Marker AUDIT_LOG_MARKER = MarkerFactory.getMarker("AUDIT_LOG"); + public static final Marker METRIC_LOG_MARKER = MarkerFactory.getMarker("METRIC_LOG"); + public static final Marker ERROR_LOG_MARKER = MarkerFactory.getMarker("ERROR_LOG"); + public static final Marker DEBUG_LOG_MARKER = MarkerFactory.getMarker("DEBUG_LOG"); + + + public static final Map<String, Object> CUSTOM_MDC_MAP = new ThreadLocal<Map<String, Object>>() { + @Override + protected Map<String, Object> initialValue() { + return new HashMap<>(); + } + }.get(); + + public static final ThreadLocal<SimpleDateFormat> SIMPLE_DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() { + @Override + protected SimpleDateFormat initialValue() { + final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); + simpleDateFormat.setTimeZone(TimeZone.getTimeZone(DATE_TIMEZONE)); + return simpleDateFormat; + } + }; + + + private LogUtils() { + // private constructor + } + + + /** + * Logs eomp message with normalized log level category + * + * @param logLevelCategory ecomp log level category + * @param logger logback logger + * @param marker logback marker + * @param message log message + * @param args log message arguments for interpolation + */ + public static void logWithLogLevel(final LogLevelCategory logLevelCategory, + final Logger logger, final Marker marker, + final String message, final String... args) { + switch (logLevelCategory) { + case DEBUG: + logger.debug(marker, message, args); + break; + case INFO: + logger.info(marker, message, args); + break; + case WARN: + logger.warn(marker, message, args); + break; + default: + // fatal log level is treated as error also as logback does not have fatal level + logger.error(marker, message, args); + } + } + + + /** + * Returns value for {@link AppLogSpec}. If no {@link AppLogSpec} is defined a default app log spec is passed + * + * @return app log spec + */ + public static AppLogSpec getAppLogSpec() { + final AppLogSpec appLogSpec = getCustomMapValue(APP_LOG_SPEC_KEY, AppLogSpec.class); + return appLogSpec == null ? new AppLogSpecImpl(EELFLoggerDefaults.DEFAULT_APP_LOG_INFO) : appLogSpec; + } + + /** + * Populate default values of {@link OptionalLogSpec} if not present + * + * @param loggerClass logger class + * @param logLevelCategory log level category + * + * @return optional log spec with default values if not present + */ + public static OptionalLogSpec getOptionalLogSpec(final Class<?> loggerClass, final LogLevelCategory + logLevelCategory) { + + OptionalLogSpecImpl optionalLogSpec = + getCustomMapValue(OPTIONAL_LOG_SPEC_KEY, OptionalLogSpecImpl.class); + + if (optionalLogSpec != null) { + // if message log info is empty populate default values + if (optionalLogSpec.getMessageLogInfo() == null || + optionalLogSpec.getCreationTimestamp() == null && optionalLogSpec.getAlertSeverity() == null && + optionalLogSpec.getStatusCode() == null) { + optionalLogSpec = optionalLogSpec.withMessageLogInfo(createDefaultMessageLogInfo(logLevelCategory)); + } + // if code log info is empty populate default values + if (optionalLogSpec.getCodeLogInfo() == null || + optionalLogSpec.getClassName() == null && optionalLogSpec.getThreadId() == null) { + optionalLogSpec = optionalLogSpec.withCodeLogInfo(createDefaultCodeLogInfo(loggerClass)); + } + // if custom fields log info is empty populate default values + if (optionalLogSpec.getCustomFieldsLogInfo() == null) { + optionalLogSpec = + optionalLogSpec.withCustomFieldsLogInfo(EELFLoggerDefaults.DEFAULT_CUSTOM_FIELDS_LOG_INFO); + } + // if misc fields log info is empty populate default values + if (optionalLogSpec.getMiscLogInfo() == null) { + optionalLogSpec = optionalLogSpec.withMiscLogInfo(EELFLoggerDefaults.DEFAULT_MISC_LOG_INFO); + } + } else { + // optional log spec is null so create new optional log spec + optionalLogSpec = createDefaultOptionalLogSpec(loggerClass, logLevelCategory); + } + + return optionalLogSpec; + } + + + /** + * Formats given date in ISO 8601 format + * + * @param date Date object + * + * @return formatted date string + */ + public static String formatDate(final Date date) { + if (date == null) { + return ""; + } + return SIMPLE_DATE_FORMAT.get().format(date); + } + + /** + * Creates log message string + * + * @param logValues log message values + * + * @return log message string + */ + public static String createLogMessageString(final String[] logValues) { + final StringBuffer stringBuffer = new StringBuffer(512); + for (int i = 0; i < logValues.length; i++) { + final String logValue = logValues[i]; + stringBuffer.append(logValue != null ? logValue : ""); + if (i != logValues.length - 1) { + stringBuffer.append(LOG_MESSAGE_DELIMITER); + } + } + stringBuffer.append(CoreConstants.LINE_SEPARATOR); + return stringBuffer.toString(); + } + + /** + * Gets custom MDC value from Custom MDC Map for give key. Returns null if no value can be found + * + * @param key MDC Map key + * @param clazz expected value class type + * @param <T> class type + * + * @return value inside Custom MDC Map + */ + private static <T> T getCustomMapValue(final String key, final Class<T> clazz) { + final Object value = CUSTOM_MDC_MAP.get(key); + if (value != null) { + return clazz.cast(value); + } + return null; + } + + + /** + * Get current Metric log spec from the custom MDC map and populates default values if not present + * + * @return Metric log spec + */ + public static MetricLogSpec getMetricLogSpec() { + MetricLogSpecImpl metricLogSpec = getCustomMapValue(METRIC_LOG_SPEC_KEY, MetricLogSpecImpl.class); + + if (metricLogSpec != null) { + if (metricLogSpec.getRequestIdLogInfo() == null || metricLogSpec.getRequestId() == null) { + metricLogSpec = metricLogSpec.withRequestIdLogInfo(createNewRequestIdLogInfo()); + } + if (metricLogSpec.getServiceLogInfo() == null) { + metricLogSpec = metricLogSpec.withServiceLogInfo(EELFLoggerDefaults.DEFAULT_SERVICE_LOG_INFO); + } + if (metricLogSpec.getRequestTimingLogInfo() == null || metricLogSpec.getBeginTimestamp() == null || + metricLogSpec.getEndTimestamp() == null) { + metricLogSpec = + metricLogSpec.withRequestTimingLogInfo(EELFLoggerDefaults.DEFAULT_REQUEST_TIMING_LOG_INFO); + } + if (metricLogSpec.getResponseLogInfo() == null) { + metricLogSpec = metricLogSpec.withResponseLogInfo(EELFLoggerDefaults.DEFAULT_RESPONSE_LOG_INFO); + } + final Date beginTimestamp = metricLogSpec.getBeginTimestamp(); + final Date endTimestamp = metricLogSpec.getEndTimestamp(); + final Long elapsedTime = metricLogSpec.getElapsedTime(); + if (endTimestamp != null && beginTimestamp != null && elapsedTime == null) { + final RequestTimingLogInfoImpl requestTimingLogInfo = + new RequestTimingLogInfoImpl(beginTimestamp, endTimestamp, + endTimestamp.getTime() - beginTimestamp.getTime()); + metricLogSpec = metricLogSpec.withRequestTimingLogInfo(requestTimingLogInfo); + } + if (metricLogSpec.getTargetServiceLogInfo() == null) { + metricLogSpec = + metricLogSpec.withTargetServiceLogInfo(EELFLoggerDefaults.DEFAULT_TARGET_SERVICE_LOG_INFO); + } + } else { + throw new IllegalArgumentException("Metric Log Spec must not be null"); + } + + return metricLogSpec; + } + + /** + * Get current Debug log spec from the custom MDC map and populates default values if not present + * + * @return Debug log spec + */ + public static DebugLogSpec getDebugLogSpec() { + final DebugLogSpecImpl debugLogSpec = getCustomMapValue(DEBUG_LOG_SPEC_KEY, DebugLogSpecImpl.class); + if (debugLogSpec == null || debugLogSpec.getRequestIdLogInfo() == null || debugLogSpec.getRequestId() == null) { + return new DebugLogSpecImpl(createNewRequestIdLogInfo()); + } + return debugLogSpec; + } + + /** + * Get current Error log spec from the custom MDC map and populates default values if not present + * + * @return Error log spec + */ + public static ErrorLogSpec getErrorLogSpec() { + ErrorLogSpecImpl errorLogSpec = getCustomMapValue(ERROR_LOG_SPEC_KEY, ErrorLogSpecImpl.class); + if (errorLogSpec != null) { + + if (errorLogSpec.getRequestIdLogInfo() == null || errorLogSpec.getRequestId() == null) { + errorLogSpec = errorLogSpec.withRequestIdLogInfo(createNewRequestIdLogInfo()); + } + if (errorLogSpec.getServiceLogInfo() == null) { + errorLogSpec = errorLogSpec.withServiceLogInfo(EELFLoggerDefaults.DEFAULT_SERVICE_LOG_INFO); + } + if (errorLogSpec.getTargetServiceLogInfo() == null) { + errorLogSpec = + errorLogSpec.withTargetServiceLogInfo(EELFLoggerDefaults.DEFAULT_TARGET_SERVICE_LOG_INFO); + } + if (errorLogSpec.getErrorLogInfo() == null) { + errorLogSpec = errorLogSpec.withErrorLogInfo(EELFLoggerDefaults.DEFAULT_ERROR_LOG_INFO); + } + + } else { + throw new IllegalArgumentException("Error Log Spec cannot be null"); + } + return errorLogSpec; + } + + + /** + * Get current Audit log spec from the custom MDC map and populates default values if not present + * + * @return Audit log spec + */ + public static AuditLogSpec getAuditLogSpec() { + AuditLogSpecImpl auditLogSpec = getCustomMapValue(AUDIT_LOG_SPEC_KEY, AuditLogSpecImpl.class); + if (auditLogSpec != null) { + if (auditLogSpec.getServiceLogInfo() == null) { + auditLogSpec = auditLogSpec.withServiceLogInfo(EELFLoggerDefaults.DEFAULT_SERVICE_LOG_INFO); + } + if (auditLogSpec.getRequestIdLogInfo() == null || auditLogSpec.getRequestId() == null) { + auditLogSpec = auditLogSpec.withRequestIdLogInfo(createNewRequestIdLogInfo()); + } + if (auditLogSpec.getResponseLogInfo() == null) { + auditLogSpec = auditLogSpec.withResponseLogInfo(EELFLoggerDefaults.DEFAULT_RESPONSE_LOG_INFO); + } + + if (auditLogSpec.getRequestTimingLogInfo() == null || auditLogSpec.getBeginTimestamp() == null || + auditLogSpec.getEndTimestamp() == null) { + auditLogSpec = + auditLogSpec.withRequestTimingLogInfo(EELFLoggerDefaults.DEFAULT_REQUEST_TIMING_LOG_INFO); + } + final Date beginTimestamp = auditLogSpec.getBeginTimestamp(); + final Date endTimestamp = auditLogSpec.getEndTimestamp(); + final Long elapsedTime = auditLogSpec.getElapsedTime(); + if (endTimestamp != null && beginTimestamp != null && elapsedTime == null) { + final RequestTimingLogInfoImpl requestTimingLogInfo = + new RequestTimingLogInfoImpl(beginTimestamp, endTimestamp, + endTimestamp.getTime() - beginTimestamp.getTime()); + auditLogSpec = auditLogSpec.withRequestTimingLogInfo(requestTimingLogInfo); + } + + } else { + throw new IllegalArgumentException("Audit Log Spec cannot be null"); + } + + return auditLogSpec; + } + + + private static RequestIdLogInfo createNewRequestIdLogInfo() { + return new RequestIdLogInfoImpl(UUID.randomUUID().toString()); + } + + /** + * Return Log Level Category from MDC Map + * + * @return log level category + */ + public static Class<?> getLoggerClass() { + final Class<?> loggerClass = getCustomMapValue(LOGGER_CLASS_KEY, Class.class); + // logger class must always be non null + if (loggerClass != null) { + return loggerClass; + } + return LogUtils.class.getClass(); + } + + + /** + * Return Log Level Category from MDC Map + * + * @return log level category + */ + public static LogLevelCategory getLogLevelCategory() { + final LogLevelCategory logLevelCategory = getCustomMapValue(LOG_LEVEL_CATEGORY_KEY, LogLevelCategory.class); + if (logLevelCategory != null) { + return logLevelCategory; + } + return LogLevelCategory.ERROR; + } + + /** + * Creates Default Optional Log spec + * + * @param loggerClass logger class name + * @param logLevelCategory Log leve category + * + * @return default optional log spec + */ + private static OptionalLogSpecImpl createDefaultOptionalLogSpec(final Class<?> loggerClass, + final LogLevelCategory logLevelCategory) { + return new OptionalLogSpecImpl(createDefaultMessageLogInfo(logLevelCategory), + createDefaultCodeLogInfo(loggerClass), EELFLoggerDefaults.DEFAULT_CUSTOM_FIELDS_LOG_INFO, + EELFLoggerDefaults.DEFAULT_MISC_LOG_INFO); + } + + + /** + * Creates Default Code Log Info + * + * @param loggerClass logger class name + * + * @return default code log info + */ + private static CodeLogInfoImpl createDefaultCodeLogInfo(final Class<?> loggerClass) { + // thread id can be extracted from the framework + return new CodeLogInfoImpl(null, loggerClass != null ? loggerClass.getName() : ""); + } + + + /** + * Creates Default Message Log Info + * + * @param logLevelCategory Log leve category + * + * @return default message log info + */ + private static MessageLogInfoImpl createDefaultMessageLogInfo(final LogLevelCategory logLevelCategory) { + return new MessageLogInfoImpl(new Date(), + getStatusCode(logLevelCategory), + getNagiosAlertLevel(logLevelCategory)); + } + + + /** + * Creates Default App Log Spec + * + * @return default APP log Spec + */ + public static AppLogInfoImpl createDefaultAppLogInfo() { + final String serviceInstanceId = + resolveProperty(null, AppLogInfo.Defaults.DEFAULT_SERVICE_INSTANCE_ID, + "SERVICE_NAME", "ServiceInstanceId", "SERVICE_INSTANCE_ID"); + final String instanceUUID = + resolveProperty(null, AppLogInfo.Defaults.DEFAULT_INSTANCE_UUID, + "InstanceUUID", "INSTANCE_UUID"); + final String virtualServerName = + resolveProperty(null, AppLogInfo.Defaults.DEFAULT_VIRTUAL_SERVER_NAME, + "VirtualServerName", "VIRTUAL_SERVER_NAME"); + final String serverIPAddress = getHostIPAddress() != null ? + getHostIPAddress() : AppLogInfo.Defaults.DEFAULT_SERVER_IP_ADDRESS; + final String serverFQDN = getHostName() != null ? getHostName() : AppLogInfo.Defaults.DEFAULT_SERVER_FQDN; + return new AppLogInfoImpl(serviceInstanceId, instanceUUID, virtualServerName, serverIPAddress, serverFQDN); + } + + + /** + * Returns status code based on log level category + * + * @param logLevelCategory log level category + * + * @return request status code as string based on log level category + */ + private static RequestStatusCode getStatusCode(final LogLevelCategory logLevelCategory) { + if (logLevelCategory == LogLevelCategory.DEBUG || logLevelCategory == LogLevelCategory.INFO || + logLevelCategory == LogLevelCategory.WARN) { + return RequestStatusCode.COMPLETE; + } else { + return RequestStatusCode.ERROR; + } + } + + /** + * Returns nagios Alert level based on log level category + * + * @param logLevelCategory log level category + * + * @return nagios alert level + */ + private static NagiosAlertLevel getNagiosAlertLevel(final LogLevelCategory logLevelCategory) { + switch (logLevelCategory) { + case DEBUG: + return NagiosAlertLevel.OK; + case INFO: + return NagiosAlertLevel.OK; + case WARN: + return NagiosAlertLevel.WARNING; + case ERROR: + return NagiosAlertLevel.CRITICAL; + case FATAL: + return NagiosAlertLevel.CRITICAL; + default: + return NagiosAlertLevel.UNKNOWN; + } + } + + /** + * Resolves property value if not present + * + * @param userPassedValue user passed property value + * @param defaultValue default value if no value is found after resolving the property + * @param propertyNames property names + * + * @return resolved property value + */ + private static String resolveProperty( + final String userPassedValue, final String defaultValue, final String... propertyNames) { + // if user passed is present return that value + if (userPassedValue != null) { + return userPassedValue; + } + // resolve it using composite resolver + final String resolveProperty = resolveProperty(Arrays.asList(propertyNames)); + return resolveProperty != null ? resolveProperty : defaultValue; + } + + /** + * Resolves property values in different places + * + * @param propertyNames property Names + * + * @return property Value + */ + private static String resolveProperty(final List<String> propertyNames) { + return COMPOSITE_PROPERTY_RESOLVER.resolve(propertyNames); + } + + + /** + * Determine host IP Address + * + * @return host ip address + */ + private static String getHostIPAddress() { + final InetAddress inetAddress = getInetAddress(); + if (inetAddress != null) { + return inetAddress.getHostAddress(); + } + return null; + } + + /** + * Determines fully qualified host name + * + * @return fully qualified host name + */ + private static String getHostName() { + final InetAddress inetAddress = getInetAddress(); + if (inetAddress != null) { + return inetAddress.getCanonicalHostName(); + } + return null; + } + + /** + * Fetches Inet Address + * + * @return Inet Address + */ + private static InetAddress getInetAddress() { + try { + return InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + return null; + } + } + + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/META-INF/services/org.onap.dcae.utils.eelf.logger.api.log.EELFLogger b/eelf-logger/eelf-logger-logback-impl/src/main/resources/META-INF/services/org.onap.dcae.utils.eelf.logger.api.log.EELFLogger new file mode 100644 index 0000000..d7d5c71 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/META-INF/services/org.onap.dcae.utils.eelf.logger.api.log.EELFLogger @@ -0,0 +1,20 @@ +# +# ================================================================================ +# 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========================================================= +# +# + +org.onap.dcae.utils.eelf.logger.logback.log.EELFLoggerImpl diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-async-appenders.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-async-appenders.xml new file mode 100644 index 0000000..e2e93e4 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-async-appenders.xml @@ -0,0 +1,55 @@ +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> + +<included> + + <!-- + ASYNC APPENDERS CAN BE USED TO INCREASE THE PERFORMANCE OF ECOMP LOGGING, HOWEVER, ASYNC LOGGERS + CAN DROP MESSAGES IF QUEUE SIZE IF FULL AND DURING SHUT DOWN TIME. + + SO INCREASED PERFORMANCE AT THE COST OF LESS RELIABLE LOGGING + --> + + <appender name="asyncAuditLogAppender" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>${queueSize}</queueSize> + <maxFlushTime>${maxFlushTime}</maxFlushTime> + <appender-ref ref="auditLogAppender"/> + </appender> + + <appender name="asyncMetricLogAppender" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>${queueSize}</queueSize> + <maxFlushTime>${maxFlushTime}</maxFlushTime> + <appender-ref ref="metricLogAppender"/> + </appender> + + <appender name="asyncErrorLogAppender" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>${queueSize}</queueSize> + <maxFlushTime>${maxFlushTime}</maxFlushTime> + <appender-ref ref="errorLogAppender"/> + </appender> + + <appender name="asyncDebugLogAppender" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>${queueSize}</queueSize> + <maxFlushTime>${maxFlushTime}</maxFlushTime> + <appender-ref ref="debugLogAppender"/> + </appender> + +</included> + + diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-defaults.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-defaults.xml new file mode 100644 index 0000000..f9bb078 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-defaults.xml @@ -0,0 +1,51 @@ +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> + +<included> + + <!-- LOG DIRECTORIES --> + <property scope="context" name="logDir" value="logs"/> + <property scope="context" name="debugDir" value="debug-logs"/> + + <!-- SETUP LOG DIRECTORIES --> + <property scope="context" name="logDirectory" value="${logDir}/${componentName}"/> + <property scope="context" name="debugLogDirectory" value="${debugDir}/${componentName}"/> + + <!-- + MODIFY LOG DIR ON WINDOWS OS SO THAT TEST LOGS ARE UNDER TARGET DIR CAN BE CLEANED AFTER TESTS AUTOMATICALLY + --> + <property scope="context" name="modifyLogPathInWindows" value="true" /> + <property scope="context" name="appendDirectory" value="target" /> + + <!-- LOG FILE NAMES --> + <property scope="context" name="metricLogName" value="metrics"/> + <property scope="context" name="auditLogName" value="audit"/> + <property scope="context" name="errorLogName" value="error"/> + <property scope="context" name="debugLogName" value="debug"/> + + <!-- ROLLING FILE APPENDER DEFAULT SETTINGS --> + <property scope="context" name="minFileIndex" value="1"/> + <property scope="context" name="maxFileIndex" value="10"/> + <property scope="context" name="maxFileSize" value="2500KB"/> + + <!-- ASYNC APPENDER DEFAULT SETTINGS --> + <property scope="context" name="queueSize" value="1024"/> + <property scope="context" name="maxFlushTime" value="5000"/> + +</included> diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-logback.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-logback.xml new file mode 100644 index 0000000..7e08eb2 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-logback.xml @@ -0,0 +1,45 @@ +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> + +<included> + + <include resource="eelf-defaults.xml"/> + + <!-- CUSTOM STARTUP LISTENER REQUIRED TO SETUP DEFAULT APP LOG INFO DURING STARTUP TIME--> + <contextListener class="org.onap.dcae.utils.eelf.logger.logback.listener.LogbackStartupListener"/> + + <!-- ADD REQUIRED APPENDERS --> + <include resource="eelf-required-appenders.xml"/> + + <!-- ADD OPTIONAL APPENDERS: NOT ADDED BY DEFAULT --> + <!--<include resource="eelf-optional-appenders.xml"/>--> + + + <root level="DEBUG"> + <!-- required appenders --> + <appender-ref ref="auditLogAppender"/> + <appender-ref ref="metricLogAppender"/> + <appender-ref ref="errorLogAppender"/> + + <!-- optional appenders: not added by default --> + <!--<appender-ref ref="debugLogAppender"/>--> + <!--<appender-ref ref="STDOUT"/>--> + </root> + +</included> diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-optional-appenders.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-optional-appenders.xml new file mode 100644 index 0000000..fb7ec7f --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-optional-appenders.xml @@ -0,0 +1,68 @@ +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> + +<included> + + <!-- + ============================= DEBUG LOG APPENDER ================================ + --> + <appender name="debugLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + + <filter class="org.onap.dcae.utils.eelf.logger.logback.filter.MarkerFilter"> + <markers>DEBUG_LOG</markers> + <onMatch>ACCEPT</onMatch> + <onMismatch>DENY</onMismatch> + </filter> + + <file>${debugLogDirectory}/${debugLogName}.log</file> + + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${debugLogName}.%i.log.zip</fileNamePattern> + <minIndex>${minFileIndex}</minIndex> + <maxIndex>${maxFileIndex}</maxIndex> + </rollingPolicy> + + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>${maxFileSize}</maxFileSize> + </triggeringPolicy> + + <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> + <layout class="org.onap.dcae.utils.eelf.logger.logback.layout.DebugLogLayout"/> + </encoder> + + </appender> + + + <!-- + ============================= CONSOLE APPENDER ================================ + --> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + + <filter class="org.onap.dcae.utils.eelf.logger.logback.filter.MarkerFilter"> + <markers>METRIC_LOG,AUDIT_LOG,ERROR_LOG,DEBUG_LOG</markers> + <onMatch>ACCEPT</onMatch> + <onMismatch>DENY</onMismatch> + </filter> + + <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> + <layout class="org.onap.dcae.utils.eelf.logger.logback.layout.ConsoleLayout"/> + </encoder> + </appender> + +</included> diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-required-appenders.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-required-appenders.xml new file mode 100644 index 0000000..72f1a5d --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-required-appenders.xml @@ -0,0 +1,112 @@ +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> + +<included> + + <!-- + ============================= AUDIT LOG APPENDER ================================ + --> + <appender name="auditLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + + <filter class="org.onap.dcae.utils.eelf.logger.logback.filter.MarkerFilter"> + <markers>AUDIT_LOG</markers> + <onMatch>ACCEPT</onMatch> + <onMismatch>DENY</onMismatch> + </filter> + + <file>${logDirectory}/${auditLogName}.log</file> + + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${auditLogName}.%i.log.zip</fileNamePattern> + <minIndex>${minFileIndex}</minIndex> + <maxIndex>${maxFileIndex}</maxIndex> + </rollingPolicy> + + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>${maxFileSize}</maxFileSize> + </triggeringPolicy> + + <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> + <layout class="org.onap.dcae.utils.eelf.logger.logback.layout.AuditLogLayout"/> + </encoder> + + </appender> + + + <!-- + ============================= METRIC LOG APPENDER ================================ + --> + <appender name="metricLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + + <filter class="org.onap.dcae.utils.eelf.logger.logback.filter.MarkerFilter"> + <markers>METRIC_LOG</markers> + <onMatch>ACCEPT</onMatch> + <onMismatch>DENY</onMismatch> + </filter> + + <file>${logDirectory}/${metricLogName}.log</file> + + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${metricLogName}.%i.log.zip</fileNamePattern> + <minIndex>${minFileIndex}</minIndex> + <maxIndex>${maxFileIndex}</maxIndex> + </rollingPolicy> + + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>${maxFileSize}</maxFileSize> + </triggeringPolicy> + + <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> + <layout class="org.onap.dcae.utils.eelf.logger.logback.layout.MetricLogLayout"/> + </encoder> + + </appender> + + + <!-- + ============================= ERROR LOG APPENDER ================================ + --> + <appender name="errorLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + + <filter class="org.onap.dcae.utils.eelf.logger.logback.filter.MarkerFilter"> + <markers>ERROR_LOG</markers> + <onMatch>ACCEPT</onMatch> + <onMismatch>DENY</onMismatch> + </filter> + + <file>${logDirectory}/${errorLogName}.log</file> + + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${errorLogName}.%i.log.zip</fileNamePattern> + <minIndex>${minFileIndex}</minIndex> + <maxIndex>${maxFileIndex}</maxIndex> + </rollingPolicy> + + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>${maxFileSize}</maxFileSize> + </triggeringPolicy> + + <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> + <layout class="org.onap.dcae.utils.eelf.logger.logback.layout.ErrorLogLayout"/> + </encoder> + + </appender> + + +</included> diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java new file mode 100644 index 0000000..fda4355 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java @@ -0,0 +1,157 @@ +/* + * ================================================================================ + * 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.logback; + + +import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.NagiosAlertLevel; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestStatusCode; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.model.info.CodeLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.CustomFieldsLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ErrorLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.MessageLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.MiscLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ResponseLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.TargetServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.OptionalLogSpecImpl; + +import java.util.Date; + +/** + * Base Logback Unit Test. + * + * @author Rajiv Singla + */ +public abstract class BaseLogbackUnitTest { + + protected static final String TEST_SERVICE_INSTANCE_ID = "testServiceInstanceID"; + protected static final String TEST_INSTANCE_UUID = ""; + + static { + System.setProperty("ServiceInstanceId", TEST_SERVICE_INSTANCE_ID); + System.setProperty("InstanceUUID", TEST_INSTANCE_UUID); + } + + protected static final String TEST_REQUEST_ID = "403cdad8-4de7-450d-b441-561001decdd6"; + protected static final String TEST_SERVICE_NAME = "testServiceName"; + protected static final String TEST_PARTNER_NAME = "testPartnerName"; + protected static final String TEST_CLIENT_IP_ADDRESS = ""; + + protected static final Date START_DATE = new Date(); + protected static final Date END_DATE = new Date(new Date().getTime() + 30_000); + protected static final Long ELAPSED_TIME = END_DATE.getTime() - START_DATE.getTime(); + + protected static final Integer RESPONSE_CODE = 200; + protected static final String RESPONSE_DESCRIPTION = "TEST RESPONSE DESCRIPTION"; + + protected static final String TEST_TARGET_ENTITY = "testTargetEntity"; + protected static final String TEST_TARGET_SERVICE_NAME = "testTargetServiceName"; + protected static final String TEST_TARGET_VIRTUAL_ENTITY = "testTargetVirtualEntity"; + + + protected static final String TEST_THREAD_ID = "testThreadId"; + protected static final String TEST_CLASS_NAME = "testClassName"; + + protected static final String TEST_CUSTOM_FIELD1 = "testCustomField1"; + protected static final String TEST_CUSTOM_FIELD2 = "testCustomField2"; + protected static final String TEST_CUSTOM_FIELD3 = "testCustomField3"; + protected static final String TEST_CUSTOM_FIELD4 = "testCustomField4"; + + protected static final String TEST_PROCESS_KEY = "testProcessId"; + + protected static final Integer TEST_ERROR_CODE = 500; + protected static final String TEST_ERROR_CODE_DESCRIPTION = "TEST ERROR CODE DESCRIPTION"; + + + protected static RequestIdLogInfo getTestRequestIdLogInfo() { + return new RequestIdLogInfoImpl(TEST_REQUEST_ID); + } + + protected static ServiceLogInfo getTestServiceLogInfo() { + return new ServiceLogInfoImpl(TEST_SERVICE_NAME, TEST_PARTNER_NAME, TEST_CLIENT_IP_ADDRESS); + } + + protected static RequestTimingLogInfo getTestRequestTimingInfo() { + return new RequestTimingLogInfoImpl(START_DATE, END_DATE, ELAPSED_TIME); + } + + protected static ResponseLogInfo getTestResponseLogInfo() { + return new ResponseLogInfoImpl(RESPONSE_CODE, RESPONSE_DESCRIPTION); + } + + protected static AuditLogSpec getTestAuditLogSpec() { + return new AuditLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(), + getTestRequestTimingInfo(), getTestResponseLogInfo()); + } + + protected static DebugLogSpec getTestDebugLogSpec() { + return new DebugLogSpecImpl(getTestRequestIdLogInfo()); + } + + protected static TargetServiceLogInfo getTestTargetServiceLogInfo() { + return new TargetServiceLogInfoImpl(TEST_TARGET_ENTITY, TEST_TARGET_SERVICE_NAME, TEST_TARGET_VIRTUAL_ENTITY); + } + + protected static MetricLogSpec getTestMetricLogSpec() { + return new MetricLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(), + getTestRequestTimingInfo(), getTestResponseLogInfo(), getTestTargetServiceLogInfo()); + } + + protected static ErrorLogInfo getTestErrorLogInfo() { + return new ErrorLogInfoImpl(TEST_ERROR_CODE, TEST_ERROR_CODE_DESCRIPTION); + } + + protected static ErrorLogSpec getTestErrorLogSpec() { + return new ErrorLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(), getTestTargetServiceLogInfo() + , getTestErrorLogInfo()); + } + + protected static OptionalLogSpec getTestOptionalLogSpec() { + final MessageLogInfo messageLogInfo = new MessageLogInfoImpl(new Date(), RequestStatusCode.COMPLETE, + NagiosAlertLevel.OK); + final CodeLogInfo codeLogInfo = new CodeLogInfoImpl(TEST_THREAD_ID, TEST_CLASS_NAME); + final CustomFieldsLogInfo customFieldsLogInfo = new CustomFieldsLogInfoImpl(TEST_CUSTOM_FIELD1, + TEST_CUSTOM_FIELD2, TEST_CUSTOM_FIELD3, TEST_CUSTOM_FIELD4); + final MiscLogInfo miscLogInfo = new MiscLogInfoImpl(TEST_PROCESS_KEY, ""); + return new OptionalLogSpecImpl(messageLogInfo, codeLogInfo, customFieldsLogInfo, miscLogInfo); + } + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java new file mode 100644 index 0000000..02b377a --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java @@ -0,0 +1,66 @@ +/* + * ================================================================================ + * 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.logback.log; + +import org.junit.Test; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl; + +/** + * Tests for Audit log implementations. + * + * @author Rajiv Singla + */ +public class AuditLogImplTest extends BaseLogbackUnitTest { + + private static final EELFLogger LOG = EELFLogFactory.getLogger(AuditLogImplTest.class); + + @Test + public void auditLoggerTest() throws Exception { + + LOG.auditLog().info("Test Audit info message: {}", + getTestAuditLogSpec(), getTestOptionalLogSpec(), "infoArg"); + + final AuditLogSpec emptyAuditLog = new AuditLogSpecImpl(null, null, + null, null); + + LOG.auditLog().info("Test Empty Audit info message.", emptyAuditLog, + EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC); + + } + + + @Test + public void auditLoggerTestWithWarnLogLevel() throws Exception { + LOG.auditLog().warn("Test Audit warn message: {}", + getTestAuditLogSpec(), getTestOptionalLogSpec(), "warnArg"); + } + + @Test + public void auditLoggerTestWithErrorLogLevel() throws Exception { + LOG.auditLog().error("Test Audit error message: {}", + getTestAuditLogSpec(), getTestOptionalLogSpec(), "errorArg"); + + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java new file mode 100644 index 0000000..76d41f9 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java @@ -0,0 +1,53 @@ +/* + * ================================================================================ + * 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.logback.log; + +import org.junit.Test; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl; + + +/** + * Test for Debug log implementation. + * + * @author Rajiv Singla + */ +public class DebugLogImplTest extends BaseLogbackUnitTest { + + private static final EELFLogger LOG = EELFLogFactory.getLogger(DebugLogImplTest.class); + + @Test + public void debugLoggerTest() throws Exception { + + LOG.debugLog().debug("Test DebugLog debug message: {}", + getTestDebugLogSpec(), getTestOptionalLogSpec(), "debugArg"); + + final DebugLogSpec emptyDebugLog = new DebugLogSpecImpl(null); + + LOG.debugLog().debug("Test Empty DebugLog debug message.", emptyDebugLog, + EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC); + + } + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java new file mode 100644 index 0000000..0b96be5 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * 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.logback.log; + +import org.junit.Test; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl; + + +/** + * Tests for Error Log implementation. + * + * @author Rajiv Singla + */ +public class ErrorLogImplTest extends BaseLogbackUnitTest { + + private static final EELFLogger LOG = EELFLogFactory.getLogger(ErrorLogImplTest.class); + + @Test + public void errorLoggerTest() throws Exception { + LOG.errorLog().error("Test ErrorLog error message: {}", + getTestErrorLogSpec(), getTestOptionalLogSpec(), "errorArg"); + + final ErrorLogSpec emptyErrorLog = new ErrorLogSpecImpl(null, null, + null, null); + + LOG.errorLog().error("Test Empty ErrorLog error message", emptyErrorLog, + EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC); + + } + + @Test + public void errorLoggerTestWithWarnLogLevel() throws Exception { + LOG.errorLog().warn("Test errorLog warn message: {}", getTestErrorLogSpec(), getTestOptionalLogSpec(), + "warnArg"); + + } + + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java new file mode 100644 index 0000000..8df1e9c --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.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.logback.log; + +import org.junit.Test; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl; + + +/** + * Tests for Metric Log implementation. + * + * @author Rajiv Singla + */ +public class MetricLogImplTest extends BaseLogbackUnitTest { + + private static final EELFLogger LOG = EELFLogFactory.getLogger(MetricLogImplTest.class); + + @Test + public void metricLoggerTest() throws Exception { + + LOG.metricLog().info("test Metric info message: {}", getTestMetricLogSpec(), getTestOptionalLogSpec(), + "infoArg"); + + final MetricLogSpec emptyMetricLog = new MetricLogSpecImpl(null, null, null, null, null); + + LOG.metricLog().info("Test Empty Metric info message", emptyMetricLog, + EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC); + } + + @Test + public void metricLoggerTestWithWarnLogLevel() throws Exception { + LOG.metricLog().warn("test Metric warn message: {}", getTestMetricLogSpec(), getTestOptionalLogSpec(), + "warnArg"); + + } + + @Test + public void metricLoggerTestWithErrorLogLevel() throws Exception { + LOG.metricLog().warn("test Metric error message: {}", getTestMetricLogSpec(), getTestOptionalLogSpec(), + "errorArg"); + + + } + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/resources/logback.xml b/eelf-logger/eelf-logger-logback-impl/src/test/resources/logback.xml new file mode 100644 index 0000000..b1cffd6 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/resources/logback.xml @@ -0,0 +1,41 @@ +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> +<configuration> + + <!-- SET EELF COMPONENT NAME --> + <property scope="context" name="componentName" value="test-eelf-logger"/> + <contextName>${componentName}</contextName> + + <include resource="eelf-logback.xml"/> + + <include resource="eelf-optional-appenders.xml"/> + + <root level="DEBUG"> + <!-- required appenders --> + <appender-ref ref="auditLogAppender"/> + <appender-ref ref="metricLogAppender"/> + <appender-ref ref="errorLogAppender"/> + + <!-- optional appenders --> + <appender-ref ref="debugLogAppender"/> + <appender-ref ref="STDOUT"/> + </root> + + +</configuration> diff --git a/eelf-logger/eelf-logger-model/pom.xml b/eelf-logger/eelf-logger-model/pom.xml new file mode 100644 index 0000000..86f269a --- /dev/null +++ b/eelf-logger/eelf-logger-model/pom.xml @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.dcaegen2.utils</groupId> + <artifactId>eelf-logger</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>eelf-logger-model</artifactId> + <packaging>jar</packaging> + + + <!-- EELF LOGGER MODELS CONTAINS IMMUTABLE MODEL OBJECTS FOR VARIOUS EELF LOGGER INTERFACES --> + <name>dcaegen2-utils-eelf-logger-model</name> + <description>Contains immutable model objects for various EELF Logger interfaces</description> + + <properties> + <main.basedir>${project.parent.basedir}</main.basedir> + <!-- SONAR SETTINGS : EXCLUDE TEST COVERAGE AS MODEL ONLY CONTAINS POJOs AND NO BUSINESS LOGIC--> + <sonar.coverage.exclusions>**/model/**</sonar.coverage.exclusions> + </properties> + + <!-- NOTE: THIS MODULE MUST NOT HAVE ANY DEPENDENCY BESIDES ECOMP LOGGER API IN COMPILE SCOPE --> + <dependencies> + + <!-- ECOMP LOGGER API --> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>eelf-logger-api</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- LOMBOK IS USED FOR CODE GENERATION IN PROVIDED SCOPE (NOT IN COMPILE SCOPE) --> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + </dependency> + + </dependencies> + + <build> + <sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory> + <plugins> + <plugin> + <groupId>org.projectlombok</groupId> + <artifactId>lombok-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + + + +</project> diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/AppLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/AppLogInfoImpl.java new file mode 100644 index 0000000..689915c --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/AppLogInfoImpl.java @@ -0,0 +1,53 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; + +/** + * Concrete model implementation for {@link AppLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class AppLogInfoImpl implements AppLogInfo { + + private static final long serialVersionUID = 1L; + + private String serviceInstanceID; + + private String instanceUUID; + + private String virtualServerName; + + private String serverIPAddress; + + private String serverFQDN; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CodeLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CodeLogInfoImpl.java new file mode 100644 index 0000000..7f5eb2f --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CodeLogInfoImpl.java @@ -0,0 +1,48 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo; + +/** + * Concrete model implementation for {@link CodeLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class CodeLogInfoImpl implements CodeLogInfo { + + private static final long serialVersionUID = 1L; + + private String threadId; + + private String className; + + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CustomFieldsLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CustomFieldsLogInfoImpl.java new file mode 100644 index 0000000..151900d --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CustomFieldsLogInfoImpl.java @@ -0,0 +1,51 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo; + +/** + * Concrete model implementation for {@link CustomFieldsLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class CustomFieldsLogInfoImpl implements CustomFieldsLogInfo { + + private static final long serialVersionUID = 1L; + + private String customField1; + + private String customField2; + + private String customField3; + + private String customField4; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ErrorLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ErrorLogInfoImpl.java new file mode 100644 index 0000000..18c2e95 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ErrorLogInfoImpl.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; + +/** + * Concrete model implementation for {@link ErrorLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class ErrorLogInfoImpl implements ErrorLogInfo { + + private static final long serialVersionUID = 1L; + + private Integer errorCode; + + private String errorDescription; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MessageLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MessageLogInfoImpl.java new file mode 100644 index 0000000..65e722a --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MessageLogInfoImpl.java @@ -0,0 +1,54 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.NagiosAlertLevel; +import org.onap.dcae.utils.eelf.logger.api.info.RequestStatusCode; + + +import java.util.Date; + +/** + * Concrete model implementation for {@link MessageLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class MessageLogInfoImpl implements MessageLogInfo { + + private static final long serialVersionUID = 1L; + + private Date creationTimestamp; + + private RequestStatusCode statusCode; + + private NagiosAlertLevel alertSeverity; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MiscLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MiscLogInfoImpl.java new file mode 100644 index 0000000..f7e648b --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MiscLogInfoImpl.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo; + +/** + * Concrete model implementation for {@link MiscLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class MiscLogInfoImpl implements MiscLogInfo { + + private static final long serialVersionUID = 1L; + + private String processId; + + private String unused; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestIdLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestIdLogInfoImpl.java new file mode 100644 index 0000000..af939c4 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestIdLogInfoImpl.java @@ -0,0 +1,45 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; + +/** + * Concrete model implementation for {@link RequestIdLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class RequestIdLogInfoImpl implements RequestIdLogInfo { + + private static final long serialVersionUID = 1L; + + private String requestId; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestTimingLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestTimingLogInfoImpl.java new file mode 100644 index 0000000..19d860b --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestTimingLogInfoImpl.java @@ -0,0 +1,51 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; + +import java.util.Date; + +/** + * Concrete model implementation for {@link RequestTimingLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class RequestTimingLogInfoImpl implements RequestTimingLogInfo { + + private static final long serialVersionUID = 1L; + + private Date beginTimestamp; + + private Date endTimestamp; + + private Long elapsedTime; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ResponseLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ResponseLogInfoImpl.java new file mode 100644 index 0000000..1f0bfbf --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ResponseLogInfoImpl.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; + +/** + * Concrete model implementation for {@link ResponseLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class ResponseLogInfoImpl implements ResponseLogInfo { + + private static final long serialVersionUID = 1L; + + private Integer responseCode; + + private String responseDescription; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ServiceLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ServiceLogInfoImpl.java new file mode 100644 index 0000000..68d1f41 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ServiceLogInfoImpl.java @@ -0,0 +1,49 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; + +/** + * Concrete model implementation for {@link ServiceLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class ServiceLogInfoImpl implements ServiceLogInfo { + + private static final long serialVersionUID = 1L; + + private String serviceName; + + private String partnerName; + + private String clientIPAddress; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/TargetServiceLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/TargetServiceLogInfoImpl.java new file mode 100644 index 0000000..4a41e73 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/TargetServiceLogInfoImpl.java @@ -0,0 +1,48 @@ +/* + * ================================================================================ + * 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.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; + +/** + * Concrete model implementation for {@link TargetServiceLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class TargetServiceLogInfoImpl implements TargetServiceLogInfo { + + private static final long serialVersionUID = 1L; + + private String targetEntity; + + private String targetServiceName; + + private String targetVirtualEntity; +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/package-info.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/package-info.java new file mode 100644 index 0000000..ce0966e --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/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 immutable implementations for EELF Logging Information interfaces + */ +package org.onap.dcae.utils.eelf.logger.model.info; diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AppLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AppLogSpecImpl.java new file mode 100644 index 0000000..d1e40ad --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AppLogSpecImpl.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * 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.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; + + +/** + * Concrete model implementation for {@link AppLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +public class AppLogSpecImpl implements AppLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = AppLogSpec.class) + private AppLogInfo appLogInfo; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AuditLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AuditLogSpecImpl.java new file mode 100644 index 0000000..c217595 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AuditLogSpecImpl.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * 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.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; + + +/** + * Concrete model implementation for {@link AuditLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class AuditLogSpecImpl implements AuditLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = RequestIdLogInfo.class) + private RequestIdLogInfo requestIdLogInfo; + + @Delegate(types = ServiceLogInfo.class) + private ServiceLogInfo serviceLogInfo; + + @Delegate(types = RequestTimingLogInfo.class) + private RequestTimingLogInfo requestTimingLogInfo; + + @Delegate(types = ResponseLogInfo.class) + private ResponseLogInfo responseLogInfo; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/DebugLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/DebugLogSpecImpl.java new file mode 100644 index 0000000..53a1070 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/DebugLogSpecImpl.java @@ -0,0 +1,48 @@ +/* + * ================================================================================ + * 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.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; + + +/** + * Concrete model implementation for {@link DebugLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class DebugLogSpecImpl implements DebugLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = RequestIdLogInfo.class) + private RequestIdLogInfo requestIdLogInfo; +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/ErrorLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/ErrorLogSpecImpl.java new file mode 100644 index 0000000..6e73fcf --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/ErrorLogSpecImpl.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * 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.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; + + +/** + * Concrete model implementation for {@link ErrorLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class ErrorLogSpecImpl implements ErrorLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = RequestIdLogInfo.class) + private RequestIdLogInfo requestIdLogInfo; + + @Delegate(types = ServiceLogInfo.class) + private ServiceLogInfo serviceLogInfo; + + @Delegate(types = TargetServiceLogInfo.class) + private TargetServiceLogInfo targetServiceLogInfo; + + @Delegate(types = ErrorLogInfo.class) + private ErrorLogInfo errorLogInfo; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/MetricLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/MetricLogSpecImpl.java new file mode 100644 index 0000000..d910bc2 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/MetricLogSpecImpl.java @@ -0,0 +1,64 @@ +/* + * ================================================================================ + * 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.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; + + +/** + * Concrete model implementation for {@link MetricLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class MetricLogSpecImpl implements MetricLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = RequestIdLogInfo.class) + private RequestIdLogInfo requestIdLogInfo; + + @Delegate(types = ServiceLogInfo.class) + private ServiceLogInfo serviceLogInfo; + + @Delegate(types = RequestTimingLogInfo.class) + private RequestTimingLogInfo requestTimingLogInfo; + + @Delegate(types = ResponseLogInfo.class) + private ResponseLogInfo responseLogInfo; + + @Delegate(types = TargetServiceLogInfo.class) + private TargetServiceLogInfo targetServiceLogInfo; +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/OptionalLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/OptionalLogSpecImpl.java new file mode 100644 index 0000000..755b4bf --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/OptionalLogSpecImpl.java @@ -0,0 +1,60 @@ +/* + * ================================================================================ + * 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.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + + +/** + * Concrete model implementation for {@link OptionalLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class OptionalLogSpecImpl implements OptionalLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = MessageLogInfo.class) + private MessageLogInfo messageLogInfo; + + @Delegate(types = CodeLogInfo.class) + private CodeLogInfo codeLogInfo; + + @Delegate(types = CustomFieldsLogInfo.class) + private CustomFieldsLogInfo customFieldsLogInfo; + + @Delegate(types = MiscLogInfo.class) + private MiscLogInfo miscLogInfo; +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/package-info.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/package-info.java new file mode 100644 index 0000000..73aec41 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/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 immutable implementations for EELF Logging specification interfaces + */ +package org.onap.dcae.utils.eelf.logger.model.spec; diff --git a/eelf-logger/findbugs-exclude.xml b/eelf-logger/findbugs-exclude.xml new file mode 100644 index 0000000..9eac36d --- /dev/null +++ b/eelf-logger/findbugs-exclude.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> + +<FindBugsFilter> + + <Match> + <!-- MODEL OBJECTS ARE USING LOMBOK ANNOTATIONS SO SOME FINDBUGS ARE IGNORED--> + <Package name="~.*model.*"/> + <Bug pattern="ES_COMPARING_PARAMETER_STRING_WITH_EQ, RC_REF_COMPARISON, EI_EXPOSE_REP, EI_EXPOSE_REP2"/> + </Match> + +</FindBugsFilter> diff --git a/eelf-logger/pmd-exclude.properties b/eelf-logger/pmd-exclude.properties new file mode 100644 index 0000000..d325b88 --- /dev/null +++ b/eelf-logger/pmd-exclude.properties @@ -0,0 +1,22 @@ +#
+# ================================================================================
+# 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=========================================================
+#
+#
+
+# List fully qualified names of classes that can be excluded for PMD (PROGRAMMING-MISTAKE-DETECTOR)
+
+# IGNORE TOO MANY STATIC IMPORTS
diff --git a/eelf-logger/pom.xml b/eelf-logger/pom.xml new file mode 100644 index 0000000..acb5fda --- /dev/null +++ b/eelf-logger/pom.xml @@ -0,0 +1,476 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ================================================================================ + ~ 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========================================================= + ~ + --> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <modules> + <module>eelf-logger-api</module> + <module>eelf-logger-model</module> + <module>eelf-logger-logback-impl</module> + </modules> + + <parent> + <artifactId>utils</artifactId> + <groupId>org.onap.dcaegen2.utils</groupId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + + <artifactId>eelf-logger</artifactId> + <name>dcaegen2-utils-eelf-logger</name> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + <url>http://maven.apache.org</url> + + + <properties> + + <!-- PROJECT SETTINGS--> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <main.basedir>${project.basedir}</main.basedir> + + <!--TEST SETTINGS --> + <surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile> + + <!-- PROJECT DEPENDENCIES --> + <slf4j.version>1.7.5</slf4j.version> + <logback.version>1.2.3</logback.version> + <lombok.version>1.16.10</lombok.version> + + + <!--TESTING DEPENDENCIES --> + <junit.version>4.12</junit.version> + <mockito.version>2.2.11</mockito.version> + <assertj-core.version>2.6.0</assertj-core.version> + + + <!-- PLUGINS VERSIONS --> + <compiler.plugin.version>3.3</compiler.plugin.version> + <surefire.plugin.version>2.19.1</surefire.plugin.version> + <failsafe.plugin.version>2.19.1</failsafe.plugin.version> + <findbugs.plugin.version>3.0.2</findbugs.plugin.version> + + <pmd.plugin.version>3.5</pmd.plugin.version> + <javadoc.plugin.version>2.10.4</javadoc.plugin.version> + <source.plugin.version>2.4</source.plugin.version> + <jar.plugin.version>2.4</jar.plugin.version> + <deploy.plugin.version>2.8</deploy.plugin.version> + <lombok.plugin.version>1.16.10.0</lombok.plugin.version> + <maven.site.plugin>3.5.1</maven.site.plugin> + + <!--PLUGIN SETTINGS --> + <compiler.source.version>1.7</compiler.source.version> + <compiler.target.version>1.7</compiler.target.version> + <unit.test.pattern>**/*Test.java</unit.test.pattern> + <skip.unit.tests>false</skip.unit.tests> + <integration.test.pattern>**/*IT.java</integration.test.pattern> + <skip.integration.tests>true</skip.integration.tests> + <pmd.violation.buildfail>true</pmd.violation.buildfail> + <findbugs.failOnError>true</findbugs.failOnError> + + </properties> + + + <dependencyManagement> + + <dependencies> + + <!-- LOGGING --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>${slf4j.version}</version> + </dependency> + + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>${logback.version}</version> + </dependency> + + <!-- CODE GENERATION --> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>${lombok.version}</version> + <scope>provided</scope> + </dependency> + + + <!-- TEST DEPENDENCIES --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>${mockito.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>${assertj-core.version}</version> + <scope>test</scope> + </dependency> + + </dependencies> + + </dependencyManagement> + + + <!-- COMMON DEPENDENCIES FOR ALL SUB-PROJECTS --> + <dependencies> + <!-- TEST DEPENDENCIES --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> + </dependencies> + + + <build> + + <pluginManagement> + + <plugins> + <!-- COMPILER PLUGIN --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>${compiler.plugin.version}</version> + <configuration> + <source>${compiler.target.version}</source> + <target>${compiler.source.version}</target> + </configuration> + </plugin> + + <!-- MAVEN SOURCE PLUGIN --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <version>${source.plugin.version}</version> + <configuration> + <excludeResources>true</excludeResources> + </configuration> + <executions> + <execution> + <id>attach-sources</id> + <phase>verify</phase> + <goals> + <goal>jar-no-fork</goal> + </goals> + </execution> + </executions> + </plugin> + + + <!-- MAVEN JAVADOC PLUGIN --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>${javadoc.plugin.version}</version> + <configuration> + <!-- minimize console output messages --> + <quiet>true</quiet> + <verbose>false</verbose> + <useStandardDocletOptions>false</useStandardDocletOptions> + </configuration> + <executions> + <execution> + <id>aggregate</id> + <phase>site</phase> + <goals> + <goal>aggregate</goal> + </goals> + </execution> + <execution> + <id>attach-javadoc</id> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + </plugin> + + + <!-- SUREFIRE TEST PLUGIN --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${surefire.plugin.version}</version> + <configuration> + <skipTests>${skip.unit.tests}</skipTests> + <argLine>-Xmx2048m -Djava.awt.headless=true -XX:+UseConcMarkSweepGC + -XX:OnOutOfMemoryError="kill -9 %p" -XX:+HeapDumpOnOutOfMemoryError + </argLine> + <redirectTestOutputToFile>${surefire.redirectTestOutputToFile}</redirectTestOutputToFile> + <parallel>methods</parallel> + <threadCount>8</threadCount> + <forkCount>8</forkCount> + <reuseForks>true</reuseForks> + <reportFormat>xml</reportFormat> + <trimStackTrace>false</trimStackTrace> + <systemPropertyVariables> + <java.io.tmpdir>${project.build.directory}</java.io.tmpdir> + <logback.configurationFile> + ${basedir}/src/test/resources/logback-test.xml + </logback.configurationFile> + </systemPropertyVariables> + <includes> + <include>${unit.test.pattern}</include> + </includes> + <excludes> + <exclude>${integration.test.pattern}</exclude> + </excludes> + <!-- Sets the VM argument line used when unit tests are run. --> + <argLine>${surefireArgLine}</argLine> + </configuration> + <dependencies> + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-junit47</artifactId> + <version>${surefire.plugin.version}</version> + </dependency> + </dependencies> + </plugin> + + <!-- FAIL SAFE PLUGIN FOR INTEGRATION TEST --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>${failsafe.plugin.version}</version> + <executions> + <execution> + <id>integration-tests</id> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <skipTests>${skip.integration.tests}</skipTests> + <!-- Sets the VM argument line used when integration tests are run. --> + <!--suppress MavenModelInspection --> + <argLine>${failsafeArgLine}</argLine> + </configuration> + </execution> + </executions> + </plugin> + + + <!-- FIND BUGS (STATIC CODE ANALYSIS) PLUGIN --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>findbugs-maven-plugin</artifactId> + <version>${findbugs.plugin.version}</version> + <configuration> + <effort>Max</effort> + <threshold>Low</threshold> + <xmlOutput>true</xmlOutput> + <!-- BUILD FAIL ON FINDBUGS ERRORS --> + <failOnError>${findbugs.failOnError}</failOnError> + <excludeFilterFile>${main.basedir}/findbugs-exclude.xml</excludeFilterFile> + <outputDirectory>${project.reporting.outputDirectory}/findbugs</outputDirectory> + <findbugsXmlOutputDirectory>${project.reporting.outputDirectory}/findbugs + </findbugsXmlOutputDirectory> + </configuration> + <executions> + <execution> + <id>analyze-compile</id> + <phase>compile</phase> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + </plugin> + + <!-- PMD PLUGIN SETUP --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-pmd-plugin</artifactId> + <version>${pmd.plugin.version}</version> + <configuration> + <sourceEncoding>${project.build.sourceEncoding}</sourceEncoding> + <targetJdk>${compiler.target.version}</targetJdk> + <linkXRef>false</linkXRef> + <!-- BUILD FAIL ON PMD VIOLATION --> + <failOnViolation>${pmd.violation.buildfail}</failOnViolation> + <targetDirectory>${project.reporting.outputDirectory}/pmd</targetDirectory> + <minimumTokens>200</minimumTokens> + </configuration> + <executions> + <execution> + <id>pmd-check</id> + <goals> + <goal>check</goal> + </goals> + <configuration> + <printFailingErrors>true</printFailingErrors> + <excludeFromFailureFile>${main.basedir}/pmd-exclude.properties</excludeFromFailureFile> + </configuration> + </execution> + <execution> + <id>cpd-check</id> + <goals> + <goal>cpd-check</goal> + </goals> + <configuration> + <printFailingErrors>true</printFailingErrors> + <excludeFromFailureFile>${main.basedir}/cpd-exclude.properties</excludeFromFailureFile> + </configuration> + </execution> + </executions> + </plugin> + + + + + <!-- LOMBOK PLUGIN --> + <plugin> + <groupId>org.projectlombok</groupId> + <artifactId>lombok-maven-plugin</artifactId> + <version>${lombok.plugin.version}</version> + <executions> + <execution> + <id>delombok</id> + <phase>generate-sources</phase> + <goals> + <goal>delombok</goal> + </goals> + <configuration> + <addOutputDirectory>false</addOutputDirectory> + <sourceDirectory>src/main/java</sourceDirectory> + </configuration> + </execution> + </executions> + </plugin> + + <!-- JAR PLUGIN --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>${jar.plugin.version}</version> + <configuration> + <archive> + <manifest> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + </manifest> + <manifestEntries> + <Implementation-Build-Version>${project.version}</Implementation-Build-Version> + </manifestEntries> + </archive> + </configuration> + </plugin> + + <!-- DEPLOY PLUGIN --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <version>${deploy.plugin.version}</version> + <configuration> + <deployAtEnd>true</deployAtEnd> + </configuration> + </plugin> + + </plugins> + + </pluginManagement> + + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + </plugin> + + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-pmd-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>findbugs-maven-plugin</artifactId> + </plugin> + </plugins> + + </build> + + <profiles> + <profile> + <id>disable-java8-doclint</id> + <activation> + <jdk>[1.8,)</jdk> + </activation> + <properties> + <additionalparam>-Xdoclint:none</additionalparam> + </properties> + </profile> + </profiles> + +</project> diff --git a/eelf-logger/version.properties b/eelf-logger/version.properties new file mode 100644 index 0000000..907cdc4 --- /dev/null +++ b/eelf-logger/version.properties @@ -0,0 +1,25 @@ +# +# ================================================================================ +# 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========================================================= +# +# + +major=1 +minor=0 +patch=0 +base_version=${major}.${minor}.${patch} +release_version=${base_version} +snapshot_version=${base_version}-SNAPSHOT |