2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli.recording;
24 import java.text.DateFormat;
25 import java.text.SimpleDateFormat;
26 import java.util.Date;
28 import java.util.TimeZone;
30 import org.openecomp.sdnc.sli.ConfigurationException;
31 import org.openecomp.sdnc.sli.SvcLogicException;
32 import org.openecomp.sdnc.sli.SvcLogicRecorder;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class Slf4jRecorder implements SvcLogicRecorder {
48 public void record(Map<String, String> parmMap) throws SvcLogicException {
49 String loggerName = parmMap.get("logger");
50 if (loggerName == null) {
51 loggerName = "Log4jRecorder";
54 String lvl = parmMap.get("level");
59 Level level = Level.INFO;
62 level = Level.valueOf(lvl.toUpperCase());
63 } catch (Exception e) {}
67 String record = parmMap.get("record");
70 String delimiter = parmMap.get("delimiter");
71 if (delimiter == null)
77 boolean moreFields = true;
80 String curField = parmMap.get("field"+idx++);
91 record = record + curField + delimiter;
98 throw new ConfigurationException("No record/fields passed in record node");
101 Logger logger = LoggerFactory.getLogger(loggerName);
103 Date now = new Date();
104 TimeZone tz = TimeZone.getTimeZone("UTC");
105 DateFormat dateFmt = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss:SS'+00:00'");
106 dateFmt.setTimeZone(tz);
107 if (record.indexOf("__TIMESTAMP__") != -1)
109 record = record.replaceFirst("__TIMESTAMP__", dateFmt.format(now));
114 logger.error(record);
123 logger.debug(record);
126 logger.trace(record);