AccessLog.java 2.66 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.util.callbacks.Prox2
 *  javax.servlet.http.HttpServletRequest
 *  javax.servlet.http.HttpServletResponse
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Deactivate
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.settings.SlingSettingsService
 *  org.osgi.service.component.ComponentContext
 */
package com.adobe.cq.dam.s7imaging.impl.ps.access_log;

import com.adobe.cq.dam.s7imaging.impl.ps.access_log.AccessLogger;
import com.scene7.is.util.callbacks.Prox2;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.settings.SlingSettingsService;
import org.osgi.service.component.ComponentContext;

@Service(value={AccessLog.class})
@Component(immediate=1)
public class AccessLog {
    @Reference
    private final SlingSettingsService slingSettings = null;
    private final AccessLogger logger = new AccessLogger();

    @Activate
    protected void activate(ComponentContext ctx) {
        String logPath = this.slingSettings.getSlingHomePath() + '/' + "logs";
        this.logger.setDirectory(logPath);
        this.logger.setPrefix("s7access-");
        this.logger.setPattern("%G %a %s %{ProcessingStatus}r %{Size}r %D %{ParseTime}r %{FetchTime}r %O %{ReqType}r '%{RootId}r' %{CacheUse}r %R [%I] '%{Referer}i' %{Host}i %{X-Forwarded-For}i %{If-None-Match}i %{If-Match}i %{If-Modified-Since}i %{Digest}r %{ContentType}r %p %{Exception}r %{CacheKey}r %{PeerServer}r %{SendTime}r %{Context}r %{TransformedUrl}r %{PathBasedAccess}r %{VirtualPathAccess}r %{RequestSize}r");
        this.logger.start();
    }

    @Deactivate
    protected void deactivate(ComponentContext ctx) {
        this.logger.stop();
    }

    public void invoke(Prox2<HttpServletRequest, HttpServletResponse, Exception> forward, HttpServletRequest req, HttpServletResponse res) throws Exception {
        this.logger.invoke(forward, req, res);
    }

    protected void bindSlingSettings(SlingSettingsService slingSettingsService) {
        this.slingSettings = slingSettingsService;
    }

    protected void unbindSlingSettings(SlingSettingsService slingSettingsService) {
        if (this.slingSettings == slingSettingsService) {
            this.slingSettings = null;
        }
    }
}