All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bonitasoft.engine.services.impl.SyncQueriableLoggerServiceImpl Maven / Gradle / Ivy

/**
 * Copyright (C) 2011-2013 BonitaSoft S.A.
 * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation
 * version 2.1 of the License.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301, USA.
 **/
package org.bonitasoft.engine.services.impl;

import java.util.List;

import org.bonitasoft.engine.log.technical.TechnicalLogSeverity;
import org.bonitasoft.engine.log.technical.TechnicalLoggerService;
import org.bonitasoft.engine.queriablelogger.model.SQueriableLog;
import org.bonitasoft.engine.queriablelogger.model.builder.SQueriableLogModelBuilder;
import org.bonitasoft.engine.services.PersistenceService;
import org.bonitasoft.engine.services.QueriableLogSessionProvider;
import org.bonitasoft.engine.services.QueriableLoggerStrategy;
import org.bonitasoft.engine.services.SPersistenceException;

/**
 * @author Elias Ricken de Medeiros
 * @author Matthieu Chaffotte
 */
public class SyncQueriableLoggerServiceImpl extends AbstractQueriableLoggerImpl {

    private final TechnicalLoggerService logger;

    public SyncQueriableLoggerServiceImpl(final PersistenceService persistenceService, final SQueriableLogModelBuilder builder,
            final QueriableLoggerStrategy loggerStrategy, final QueriableLogSessionProvider sessionProvider,
            final TechnicalLoggerService logger) {
        super(persistenceService, builder, loggerStrategy, sessionProvider);
        this.logger = logger;
    }

    // the method log is considered to already be in a transaction.
    @Override
    protected void log(final List loggableLogs) {
        try {
            if (logger != null && logger.isLoggable(this.getClass(), TechnicalLogSeverity.DEBUG)) {
                logger.log(this.getClass(), TechnicalLogSeverity.DEBUG, "persisting log");
            }
            for (final SQueriableLog log : loggableLogs) {
                getPersitenceService().insert(log);
            }
            if (logger != null && logger.isLoggable(this.getClass(), TechnicalLogSeverity.DEBUG)) {
                logger.log(this.getClass(), TechnicalLogSeverity.DEBUG, "log persisted");
            }

        } catch (final SPersistenceException e) {
            final String message = "Error while persisting logs transaction: \n Logs" + loggableLogs;
            if (logger != null && logger.isLoggable(this.getClass(), TechnicalLogSeverity.ERROR)) {
                logger.log(this.getClass(), TechnicalLogSeverity.ERROR, message, e);
            }
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy