Search in sources :

Example 1 with Level

use of com.zimbra.common.util.Log.Level in project zm-mailbox by Zimbra.

the class AttributeMigrationUtil method initEphemeralBackendExtension.

private static void initEphemeralBackendExtension(String backendName) throws ServiceException {
    Level savedExten = ZimbraLog.extensions.getLevel();
    try {
        if (!ZimbraLog.ephemeral.isDebugEnabled()) {
            // cut down on noise unless enabled debug
            ZimbraLog.extensions.setLevel(Level.error);
        }
        ExtensionUtil.initAllMatching(new EphemeralStore.EphemeralStoreMatcher(backendName));
    } finally {
        ZimbraLog.extensions.setLevel(savedExten);
    }
    Factory factory = EphemeralStore.getFactory(backendName);
    if (factory == null) {
        Zimbra.halt(String.format("no extension class name found for backend '%s', aborting attribute migration", backendName));
        // keep Eclipse happy
        return;
    }
    EphemeralStore store = factory.getStore();
    if (store == null) {
        Zimbra.halt(String.format("no store found for backend '%s', aborting attribute migration", backendName));
        // keep Eclipse happy
        return;
    }
    ZimbraLog.ephemeral.info("Using ephemeral backend %s (%s) for attribute migration", backendName, store.getClass().getName());
}
Also used : Factory(com.zimbra.cs.ephemeral.EphemeralStore.Factory) Level(com.zimbra.common.util.Log.Level) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore)

Example 2 with Level

use of com.zimbra.common.util.Log.Level in project zm-mailbox by Zimbra.

the class EphemeralBackendCheck method preModify.

@Override
public void preModify(CallbackContext context, String attrName, Object attrValue, Map attrsToModify, Entry entry) throws ServiceException {
    if (attrName.equalsIgnoreCase(Provisioning.A_zimbraEphemeralBackendURL)) {
        String url = (String) attrValue;
        String[] tokens = url.split(":");
        if (tokens != null && tokens.length > 0) {
            String backend = tokens[0];
            if (backend.equalsIgnoreCase("ldap")) {
                EphemeralStore.clearFactory();
                return;
            }
            Factory factory = EphemeralStore.getFactory(backend);
            if (factory == null) {
                // Probably called from zmprov in LDAP mode, so need to setup any Ephemeral Store extensions
                Level savedEphem = ZimbraLog.ephemeral.getLevel();
                Level savedExten = ZimbraLog.extensions.getLevel();
                try {
                    // suppress logging in zmprov output
                    ZimbraLog.ephemeral.setLevel(Level.error);
                    ZimbraLog.extensions.setLevel(Level.error);
                    ExtensionUtil.initAllMatching(new EphemeralStore.EphemeralStoreMatcher(backend));
                } finally {
                    ZimbraLog.ephemeral.setLevel(savedEphem);
                    ZimbraLog.extensions.setLevel(savedExten);
                }
                factory = EphemeralStore.getFactory(backend);
            }
            if (factory == null) {
                throw ServiceException.FAILURE(String.format("unable to modify %s; no factory found for backend '%s'", attrName, backend), null);
            }
            try {
                factory.test(url);
                EphemeralStore.clearFactory();
            } catch (ServiceException e) {
                throw ServiceException.FAILURE(String.format("cannot set zimbraEphemeralBackendURL to %s", url), e);
            }
        } else {
            throw ServiceException.FAILURE(String.format("unable to modify %s; no ephemeral backend specified", attrName), null);
        }
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) Factory(com.zimbra.cs.ephemeral.EphemeralStore.Factory) Level(com.zimbra.common.util.Log.Level) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore)

Example 3 with Level

use of com.zimbra.common.util.Log.Level 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)

Aggregations

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