001/*
002 * Copyright 2012-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.actuate.audit.listener;
018
019import org.apache.commons.logging.Log;
020import org.apache.commons.logging.LogFactory;
021
022import org.springframework.boot.actuate.audit.AuditEvent;
023import org.springframework.boot.actuate.audit.AuditEventRepository;
024
025/**
026 * The default {@link AbstractAuditListener} implementation. Listens for
027 * {@link AuditApplicationEvent}s and stores them in a {@link AuditEventRepository}.
028 *
029 * @author Dave Syer
030 * @author Stephane Nicoll
031 * @author Vedran Pavic
032 */
033public class AuditListener extends AbstractAuditListener {
034
035        private static final Log logger = LogFactory.getLog(AuditListener.class);
036
037        private final AuditEventRepository auditEventRepository;
038
039        public AuditListener(AuditEventRepository auditEventRepository) {
040                this.auditEventRepository = auditEventRepository;
041        }
042
043        @Override
044        protected void onAuditEvent(AuditEvent event) {
045                if (logger.isDebugEnabled()) {
046                        logger.debug(event);
047                }
048                this.auditEventRepository.add(event);
049        }
050
051}