[POLICY-72] replace openecomp for drools-pdp
[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 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 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                 if (System.getProperty(Configuration.PROPERTY_LOGGING_FILE_NAME) == null)
50                         System.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, 
51                                                    logbackPath.getFileName().toString());
52                 
53                 Logger logger = FlexLogger.getLogger(this.getClass(), true);
54                 
55                 if (logger.isInfoEnabled()) {
56                         logger.info("eelf-feature: Property " + Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY + "=" + 
57                                     System.getProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY));
58                         logger.info("eelf-feature: Property " + Configuration.PROPERTY_LOGGING_FILE_PATH + "=" + 
59                                 System.getProperty(Configuration.PROPERTY_LOGGING_FILE_PATH));
60                         logger.info("eelf-feature: Property " + Configuration.PROPERTY_LOGGING_FILE_NAME + "=" + 
61                             System.getProperty(Configuration.PROPERTY_LOGGING_FILE_NAME));
62                 }
63                 
64                 return false;
65         }
66         
67         @Override
68         public int getSequenceNumber() {
69                 return 0;
70         }
71
72 }