/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.core.logging.activity;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.olat.core.configuration.OLATModule;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import com.anthonyeden.lib.config.Configuration;
/**
* Initial Date: 01.12.2009 <br>
* @author bja
*/
public class LogModule implements OLATModule {
static final OLog log = Tracing.createLoggerFor(LogModule.class);
/**
* Anonymous logging is disabled by default.
*/
private static boolean logAnonymous = false;
/**
* List of operator keys like lt, le, ...
*/
private static List<String> operators = new ArrayList<String>();
private static final String CONFIG_LOG_ANONYMOUS = "anonym";
private static final String CONFIG_LOG_OPERATORS = "operators";
/**
* User properties like firstName, lastName, etc to be filled from ConfigurationManager.
*/
private static Set<String> userProperties;
@Override
public void destroy() {
// nothing to do
}
@Override
public void init(Configuration moduleConfig) {
// Set logAnonymous with value from olat_config.xml
String _logAnonymous = moduleConfig.getChildValue(CONFIG_LOG_ANONYMOUS);
logAnonymous = _logAnonymous.equalsIgnoreCase("true") ? true : false;
log.info("Log Module set logAnonymous to: " + new Boolean(logAnonymous));
// Set operators with values from olat_config.xml
Configuration operatorConfiguration = moduleConfig.getChild(CONFIG_LOG_OPERATORS);
if (operatorConfiguration != null) {
List operatorList = operatorConfiguration.getChildren();
for (Iterator iter = operatorList.iterator(); iter.hasNext();) {
Configuration operator = (Configuration) iter.next();
operators.add(operator.getValue());
}
}
}
/**
* is anonymous logging configured
* @return boolean
*/
public static boolean isLogAnonymous() {
return logAnonymous;
}
/**
* @param userProperties
*/
public static void setUserProperties(Set<String> userProperties) {
LogModule.userProperties = userProperties;
log.info("Log Module set userProperties to: " + userProperties);
}
/**
* @return
*/
public static Set<String> getUserProperties() {
return userProperties;
}
/**
* The position can be set to 1..n. The value 0 means that the list userProperties doesn't contain the value of attribute.
* @param attribute
* @return
*/
public static int getUserPropertyPosition(String attribute) {
int position = 0;
if (userProperties.contains(attribute)) {
int i = 0;
for (String userProperty : userProperties) {
if (userProperty.equals(attribute)) {
position = i + 1;
break;
}
i++;
}
}
return position;
}
public static List<String> getOperatorKeys() {
return operators;
}
}