Fix checkstyle for features submodules.
[policy/drools-pdp.git] / feature-eelf / src / main / java / org / onap / policy / drools / eelf / EelfFeature.java
1 /*
2  * ============LICENSE_START=======================================================
3  * feature-eelf
4  * ================================================================================
5  * Copyright (C) 2017-2018 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.onap.policy.drools.eelf;
22
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25
26 import org.onap.policy.common.logging.eelf.Configuration;
27 import org.onap.policy.common.logging.flexlogger.FlexLogger;
28 import org.onap.policy.common.logging.flexlogger.Logger;
29 import org.onap.policy.drools.features.PolicyEngineFeatureAPI;
30 import org.onap.policy.drools.system.Main;
31 import org.onap.policy.drools.system.PolicyEngine;
32
33 /**
34  * Feature EELF : Enables EELF Logging Libraries .
35  */
36 public class EelfFeature implements PolicyEngineFeatureAPI {
37
38     @Override
39     public final boolean beforeBoot(PolicyEngine engine, String[] cliArgs) {
40
41         String logback = System.getProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY, 
42                 Main.LOGBACK_CONFIGURATION_FILE_DEFAULT);
43         Path logbackPath = Paths.get(logback);
44
45         if (System.getProperty(Configuration.PROPERTY_LOGGING_FILE_PATH) == null) {
46             System.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, 
47                     logbackPath.toAbsolutePath().getParent().toString());
48         }
49
50         if (System.getProperty(Configuration.PROPERTY_LOGGING_FILE_NAME) == null) {
51             System.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, 
52                     logbackPath.getFileName().toString());
53         }
54
55         Logger logger = FlexLogger.getLogger(this.getClass(), true);
56
57         if (logger.isInfoEnabled()) {
58             logProperty(logger, Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY);
59             logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_PATH);
60             logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_NAME);
61         }
62
63         return false;
64     }
65
66     private void logProperty(Logger logger, String propnm) {
67         logger.info("eelf-feature: Property " + propnm + "=" + System.getProperty(propnm));
68     }
69
70     @Override
71     public int getSequenceNumber() {
72         return 0;
73     }
74
75 }