use of com.zimbra.common.util.Log in project zm-mailbox by Zimbra.
the class RemoveAccountLogger method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Server localServer = Provisioning.getInstance().getLocalServer();
checkRight(zsc, context, localServer, Admin.R_manageAccountLogger);
// Look up account, if specified.
Account account = null;
String accountName = null;
if (request.getOptionalElement(AdminConstants.E_ID) != null || request.getOptionalElement(AdminConstants.E_ACCOUNT) != null) {
account = AddAccountLogger.getAccountFromLoggerRequest(request);
accountName = account.getName();
}
// Look up log category, if specified.
Element eLogger = request.getOptionalElement(AdminConstants.E_LOGGER);
String category = null;
if (eLogger != null) {
category = eLogger.getAttribute(AdminConstants.A_CATEGORY);
if (category.equalsIgnoreCase(AddAccountLogger.CATEGORY_ALL)) {
category = null;
} else if (!LogFactory.logExists(category)) {
throw ServiceException.INVALID_REQUEST("Log category " + category + " does not exist.", null);
}
}
// Do the work.
for (Log log : LogFactory.getAllLoggers()) {
if (category == null || log.getCategory().equals(category)) {
if (accountName != null) {
boolean removed = log.removeAccountLogger(accountName);
if (removed) {
ZimbraLog.misc.info("Removed logger for account %s from category %s.", accountName, log.getCategory());
}
} else {
int count = log.removeAccountLoggers();
if (count > 0) {
ZimbraLog.misc.info("Removed %d custom loggers from category %s.", count, log.getCategory());
}
}
}
}
// Send response.
Element response = zsc.createElement(AdminConstants.REMOVE_ACCOUNT_LOGGER_RESPONSE);
return response;
}
use of com.zimbra.common.util.Log in project zm-mailbox by Zimbra.
the class AddAccountLogger method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Server localServer = Provisioning.getInstance().getLocalServer();
checkRight(zsc, context, localServer, Admin.R_manageAccountLogger);
// Look up account
Account account = getAccountFromLoggerRequest(request);
Element eLogger = request.getElement(AdminConstants.E_LOGGER);
String category = eLogger.getAttribute(AdminConstants.A_CATEGORY);
String sLevel = eLogger.getAttribute(AdminConstants.A_LEVEL);
// Handle level.
Level level = null;
try {
level = Level.valueOf(sLevel.toLowerCase());
} catch (IllegalArgumentException e) {
String error = String.format("Invalid level: %s. Valid values are %s.", sLevel, StringUtil.join(",", Level.values()));
throw ServiceException.INVALID_REQUEST(error, null);
}
// Handle category.
Collection<Log> loggers;
if (category.equalsIgnoreCase(CATEGORY_ALL)) {
loggers = LogFactory.getAllLoggers();
} else {
if (!LogFactory.logExists(category)) {
throw ServiceException.INVALID_REQUEST("Log category " + category + " does not exist.", null);
}
loggers = Arrays.asList(LogFactory.getLog(category));
}
// Add custom loggers.
Element response = zsc.createElement(AdminConstants.ADD_ACCOUNT_LOGGER_RESPONSE);
for (Log log : loggers) {
ZimbraLog.misc.info("Adding custom logger: account=%s, category=%s, level=%s", account.getName(), category, level);
log.addAccountLogger(account.getName(), level);
response.addElement(AdminConstants.E_LOGGER).addAttribute(AdminConstants.A_CATEGORY, log.getCategory()).addAttribute(AdminConstants.A_LEVEL, level.name());
}
return response;
}
use of com.zimbra.common.util.Log in project zm-mailbox by Zimbra.
the class SyncUtil method getTraceLogger.
public static Log getTraceLogger(Log parent, String id) {
String category = parent.getCategory();
Log log = LogFactory.getLog(category + '.' + id + '.' + category);
log.setLevel(Log.Level.trace);
return log;
}
Aggregations