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====================================================
22 package org.onap.aaf.misc.env.log4j;
27 public class LogFileNamer {
28 public static final int pid = PIDAccess.INSTANCE.getpid();
29 public final String root;
30 private boolean printPID;
32 public LogFileNamer(String root) {
33 if(root==null || "".equals(root) || root.endsWith("/")) {
36 this.root = root + "-";
41 public LogFileNamer noPID() {
47 * If Separated by "|" then first part is the Appender name, and the second is used in the FileNaming
48 * (This is to allow for shortened Logger names, and more verbose file names)
52 * returns the String Appender
54 public String setAppender(String appender) {
55 int pipe = appender.indexOf('|');
59 "LOG4J_FILENAME_"+(rv=appender.substring(0,pipe)),
60 root + appender.substring(pipe+1) + (printPID?('-' + pid):"") + ".log");
64 "LOG4J_FILENAME_"+appender,
65 root + appender + (printPID?('-' + pid):"") + ".log");
71 public void configure(String props) {
73 if(new File(fname="etc/"+props).exists()) {
74 org.apache.log4j.PropertyConfigurator.configureAndWatch(fname,60*1000L);
76 URL rsrc = ClassLoader.getSystemResource(props);
77 if(rsrc==null) System.err.println("Neither File: " + fname + " or resource on Classpath " + props + " exist" );
78 org.apache.log4j.PropertyConfigurator.configure(rsrc);