2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.ccsdk.sli.core.sli.recording;
23 import java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.Date;
27 import java.util.TimeZone;
29 import org.onap.ccsdk.sli.core.sli.ConfigurationException;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class Slf4jRecorder implements SvcLogicRecorder {
47 public void record(Map<String, String> parmMap) throws SvcLogicException {
48 String loggerName = parmMap.get("logger");
49 if (loggerName == null) {
50 loggerName = "Log4jRecorder";
53 String lvl = parmMap.get("level");
58 Level level = Level.INFO;
61 level = Level.valueOf(lvl.toUpperCase());
62 } catch (Exception e) {}
66 String record = parmMap.get("record");
69 String delimiter = parmMap.get("delimiter");
70 if (delimiter == null)
76 boolean moreFields = true;
79 String curField = parmMap.get("field"+idx++);
90 record = record + curField + delimiter;
97 throw new ConfigurationException("No record/fields passed in record node");
100 Logger logger = LoggerFactory.getLogger(loggerName);
102 Date now = new Date();
103 TimeZone tz = TimeZone.getTimeZone("UTC");
104 DateFormat dateFmt = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss:SS'+00:00'");
105 dateFmt.setTimeZone(tz);
106 if (record.indexOf("__TIMESTAMP__") != -1)
108 record = record.replaceFirst("__TIMESTAMP__", dateFmt.format(now));
113 logger.error(record);
122 logger.debug(record);
125 logger.trace(record);