fixing warnings from checkstyle in common-app-api
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / common / jsongraph / util / CommonUtility.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.common.jsongraph.util;
22
23 import org.openecomp.sdc.common.log.wrappers.Logger;
24
25 /**
26  * Provides common utility: functionality, common fields and enumerations
27  */
28 public class CommonUtility {
29     /**
30      * Provides list of logging level names
31      */
32     public enum LogLevelEnum {
33         ERROR,
34         WARNING,
35         INFO,
36         DEBUG,
37         TRACE,
38     }
39
40     /**
41      * Adds received message to log according to level in case if specified level is enabled
42      *
43      * @param logger
44      * @param logLevel
45      * @param format
46      * @param arguments
47      */
48     public static void addRecordToLog(Logger logger, LogLevelEnum logLevel, String format, Object... arguments) {
49         switch (logLevel) {
50             case ERROR:
51                 if (logger.isErrorEnabled()) {
52                     logger.error(format, arguments);
53                 }
54                 break;
55             case WARNING:
56                 if (logger.isWarnEnabled()) {
57                     logger.warn(format, arguments);
58                 }
59                 break;
60             case INFO:
61                 if (logger.isInfoEnabled()) {
62                     logger.info(format, arguments);
63                 }
64                 break;
65             case DEBUG:
66                 if (logger.isDebugEnabled()) {
67                     logger.debug(format, arguments);
68                 }
69                 break;
70             case TRACE:
71                 if (logger.isTraceEnabled()) {
72                     logger.trace(format, arguments);
73                 }
74                 break;
75             default:
76                 break;
77         }
78     }
79
80 }