Search in sources :

Example 1 with Log

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;
}
Also used : Account(com.zimbra.cs.account.Account) Server(com.zimbra.cs.account.Server) Log(com.zimbra.common.util.Log) ZimbraLog(com.zimbra.common.util.ZimbraLog) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element)

Example 2 with Log

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;
}
Also used : Account(com.zimbra.cs.account.Account) Server(com.zimbra.cs.account.Server) Log(com.zimbra.common.util.Log) ZimbraLog(com.zimbra.common.util.ZimbraLog) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Level(com.zimbra.common.util.Log.Level)

Example 3 with Log

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;
}
Also used : Log(com.zimbra.common.util.Log)

Aggregations

Log (com.zimbra.common.util.Log)3 Element (com.zimbra.common.soap.Element)2 ZimbraLog (com.zimbra.common.util.ZimbraLog)2 Account (com.zimbra.cs.account.Account)2 Server (com.zimbra.cs.account.Server)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 Level (com.zimbra.common.util.Log.Level)1