DebugConfigurationFromProperties.java revision ccf9d4a5c6453fa9f8b839baeee25147865fbb7d
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2015-2016 ForgeRock AS.
*/
/**
* Read debug configuration from a properties file.
*/
public class DebugConfigurationFromProperties implements DebugConfiguration {
private int rotationInterval = -1;
private long maxFileSizeInByte = -1;
/**
* initialize the properties
* It will reset the current properties for every Debug instance
*
* @param debugFilePropertiesPath path to the debug configuration file
*/
public DebugConfigurationFromProperties(String debugFilePropertiesPath) throws InvalidDebugConfigurationException {
try {
throw new InvalidDebugConfigurationException("Can't find the configuration file '" +
debugFilePropertiesPath + "'.");
}
try {
//Convert MaxFileSize to byte
maxFileSizeInByte <<= 20;
} catch (NumberFormatException e) {
//Can't parse the number
+ maxFileSizedInMb + "' cannot be parsed. Please check the configuration file '"
}
}
try {
} catch (NumberFormatException e) {
//Can't parse the number
String message = "'" + DebugConstants.CONFIG_DEBUG_LOGFILE_ROTATION + "' value can't be parsed: '" +
rotation + "'. Please check the configuration file '" +
rotationInterval = -1;
}
}
validate();
} catch (IOException ex) {
//it's possible, that we don't have the config file
debugFilePropertiesPath + "'.";
throw new InvalidDebugConfigurationException(message);
} finally {
}
}
public String getDebugPrefix() {
return debugPrefix;
}
public String getDebugSuffix() {
return debugSuffix;
}
public int getRotationInterval() {
return rotationInterval;
}
public long getRotationFileSizeInByte() {
return maxFileSizeInByte;
}
/**
* Check if the configuration properties is valid
*
* @throws InvalidDebugConfigurationException
*/
private void validate() throws InvalidDebugConfigurationException {
if (getRotationFileSizeInByte() != -1) {
if (getRotationFileSizeInByte() <= 0) {
throw new InvalidDebugConfigurationException("File size rotation needs to be greater than " +
}
if (getDebugSuffix().isEmpty()) {
throw new InvalidDebugConfigurationException("Log size rotation is enabled (File size rotation = " +
getRotationFileSizeInByte() + ") but the debug suffix is empty");
}
// Check the rotation and suffix consistency
try {
"compatible with the file size rotation enable.");
}
} catch (IllegalArgumentException e) {
}
}
if (getRotationInterval() != -1) {
if (getRotationInterval() <= 0) {
throw new InvalidDebugConfigurationException("Rotation interval needs to be greater than zero. " +
}
if (getDebugSuffix().isEmpty()) {
throw new InvalidDebugConfigurationException("Log time rotation is enabled (rotation interval = " +
getRotationInterval() + ") but the debug suffix is empty");
}
// Check the rotation and suffix consistency
try {
}
} catch (IllegalArgumentException e) {
}
}
}
/**
* Validate Suffix
* Suffix need to be parse. This function check that the suffix is compatible with the rotation period.
* @param field Calendar field
* @param amount number of unit
* @return true if the suffix generated are different
* @throws IllegalArgumentException
*/
// Check the rotation and suffix consistency
}
return "DebugConfigurationFromProperties{" +
", rotationInterval=" + rotationInterval +
'}';
}
}