2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 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
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.aaf.auth.server;
23 import java.io.IOException;
24 import java.text.SimpleDateFormat;
26 import org.apache.log4j.Logger;
27 import org.onap.aaf.cadi.Access.Level;
28 import org.onap.aaf.cadi.PropAccess;
29 import org.onap.aaf.cadi.PropAccess.LogIt;
30 import org.onap.aaf.misc.env.APIException;
31 import org.onap.aaf.misc.env.log4j.LogFileNamer;
33 public class Log4JLogIt implements LogIt {
34 // Sonar says cannot be static... it's ok. not too many PropAccesses created.
35 private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
37 private final String service;
38 private final String audit;
39 private final String init;
40 private final String trace;
42 private final Logger lservice;
43 private final Logger laudit;
44 private final Logger linit;
45 private final Logger ltrace;
48 public Log4JLogIt(final String log_dir, final String log_level, final String propsFile, final String root) throws APIException {
49 LogFileNamer lfn = new LogFileNamer(log_dir,root);
51 service=lfn.setAppender("service"); // when name is split, i.e. authz|service, the Appender is "authz", and "service"
52 audit=lfn.setAppender("audit"); // is part of the log-file name
53 init=lfn.setAppender("init");
54 trace=lfn.setAppender("trace");
56 lservice = Logger.getLogger(service);
57 laudit = Logger.getLogger(audit);
58 linit = Logger.getLogger(init);
59 ltrace = Logger.getLogger(trace);
61 lfn.configure(propsFile, log_level);
62 } catch (IOException e) {
63 throw new APIException(e);
68 public void push(Level level, Object... elements) {
71 laudit.warn(PropAccess.buildMsg(audit, iso8601, level, elements));
74 linit.warn(PropAccess.buildMsg(init, iso8601, level, elements));
77 lservice.error(PropAccess.buildMsg(service, iso8601, level, elements));
80 lservice.warn(PropAccess.buildMsg(service, iso8601, level, elements));
83 lservice.info(PropAccess.buildMsg(service, iso8601, level, elements));
86 lservice.debug(PropAccess.buildMsg(service, iso8601, level, elements));
89 ltrace.trace(PropAccess.buildMsg(service, iso8601, level, elements));
94 lservice.info(PropAccess.buildMsg(service, iso8601, level, elements));