001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.apps.logfile; 029 030import org.opencms.main.CmsLog; 031import org.opencms.main.OpenCms; 032 033import java.io.File; 034import java.util.List; 035import java.util.TreeSet; 036 037import org.apache.commons.logging.Log; 038 039/** 040 * Provides log files which should be available as options in the OpenCms log file viewer.<p> 041 * 042 */ 043public final class CmsLogFileOptionProvider { 044 045 /** Environment variable used to configure additional log files. */ 046 public static final String ENV_LOGFILES = "OCCO_ADDITIONAL_LOG_DIRS"; 047 048 /** Logger for this class. */ 049 private static final Log LOG = CmsLog.getLog(CmsLogFileOptionProvider.class); 050 051 /** 052 * Hidden default constructor.<p> 053 */ 054 private CmsLogFileOptionProvider() { 055 // hidden default constructor 056 } 057 058 /** 059 * Gets the additional configured log folders.<p> 060 * 061 * @return the additional configured log folders 062 */ 063 public static List<String> getAdditionalLogDirectories() { 064 065 return OpenCms.getWorkplaceManager().getAdditionalLogFolderConfiguration().getLogFolders(); 066 067 } 068 069 /** 070 * Gets the log file options.<p> 071 * 072 * @return the log file options 073 */ 074 public static TreeSet<File> getLogFiles() { 075 076 TreeSet<File> result = new TreeSet<>(); 077 for (File file : new File(CmsLogFileApp.LOG_FOLDER).listFiles()) { 078 result.add(file); 079 } 080 for (String dir : getAdditionalLogDirectories()) { 081 File file = new File(dir); 082 if (file.exists()) { 083 if (file.isDirectory()) { 084 for (File child : file.listFiles()) { 085 if (child.canRead()) { 086 result.add(child); 087 } else { 088 LOG.error("Can not read " + child.getAbsolutePath()); 089 } 090 } 091 } 092 } 093 } 094 return result; 095 } 096 097}