1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.inno.env.log4j;
\r
25 import java.io.File;
\r
26 import java.net.URL;
\r
28 public class LogFileNamer {
\r
29 public static final int pid = PIDAccess.INSTANCE.getpid();
\r
30 public final String root;
\r
31 private boolean printPID;
\r
33 public LogFileNamer(String root) {
\r
34 if(root==null || "".equals(root) || root.endsWith("/")) {
\r
37 this.root = root + "-";
\r
42 public LogFileNamer noPID() {
\r
48 * If Separated by "|" then first part is the Appender name, and the second is used in the FileNaming
\r
49 * (This is to allow for shortened Logger names, and more verbose file names)
\r
53 * returns the String Appender
\r
55 public String setAppender(String appender) {
\r
56 int pipe = appender.indexOf('|');
\r
60 "LOG4J_FILENAME_"+(rv=appender.substring(0,pipe)),
\r
61 root + appender.substring(pipe+1) + (printPID?('-' + pid):"") + ".log");
\r
65 "LOG4J_FILENAME_"+appender,
\r
66 root + appender + (printPID?('-' + pid):"") + ".log");
\r
72 public void configure(String props) {
\r
74 if(new File(fname="etc/"+props).exists()) {
\r
75 org.apache.log4j.PropertyConfigurator.configureAndWatch(fname,60*1000);
\r
77 URL rsrc = ClassLoader.getSystemResource(props);
\r
78 if(rsrc==null) System.err.println("Neither File: " + fname + " or resource on Classpath " + props + " exist" );
\r
79 org.apache.log4j.PropertyConfigurator.configure(rsrc);
\r