001/* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2017 005 * Space Science and Engineering Center (SSEC) 006 * University of Wisconsin - Madison 007 * 1225 W. Dayton Street, Madison, WI 53706, USA 008 * https://www.ssec.wisc.edu/mcidas 009 * 010 * All Rights Reserved 011 * 012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and 013 * some McIDAS-V source code is based on IDV and VisAD source code. 014 * 015 * McIDAS-V is free software; you can redistribute it and/or modify 016 * it under the terms of the GNU Lesser Public License as published by 017 * the Free Software Foundation; either version 3 of the License, or 018 * (at your option) any later version. 019 * 020 * McIDAS-V is distributed in the hope that it will be useful, 021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 023 * GNU Lesser Public License for more details. 024 * 025 * You should have received a copy of the GNU Lesser Public License 026 * along with this program. If not, see http://www.gnu.org/licenses. 027 */ 028package edu.wisc.ssec.mcidasv.util; 029 030import ch.qos.logback.core.rolling.RollingFileAppender; 031 032import java.nio.file.Path; 033import java.nio.file.Paths; 034 035import java.util.Objects; 036 037/** 038 * Logback {@literal "file appender"} that uses some knowledge of McIDAS-V to 039 * infer a default path to {@code mcidasv.log} if the user has run McIDAS-V 040 * without setting the {@code mcv.logpath} property. 041 * 042 * <p>If {@code mcv.logpath} was not set, the default log path will be 043 * {@code MCVUSERPATH/mcidasv.log}.</p> 044 */ 045public class UserpathRollingFileAppender<E> extends RollingFileAppender<E> { 046 @Override public void setFile(String file) { 047 if (Objects.equals("mcv.logpath_IS_UNDEFINED", file)) { 048// Paths.get(System.getProperty("mcv.userpath"), "mcidasv.log"); 049// String logPath = System.getProperty("mcv.userpath") + File.separatorChar + "mcidasv.log"; 050 Path p = Paths.get(System.getProperty("mcv.userpath"), "mcidasv.log"); 051 String logPath = p.toAbsolutePath().toString(); 052 addInfo("using default logpath: '"+logPath+'\''); 053 super.setFile(logPath); 054 } else { 055 addInfo("using specified logpath: '"+file+'\''); 056 super.setFile(file); 057 } 058 } 059}