package de.thpeetz.kontor

import org.slf4j.LoggerFactory
import javax.servlet.Filter
import org.springframework.stereotype.Component
import javax.servlet.FilterChain
import javax.servlet.ServletRequest
import javax.servlet.ServletResponse

@Component
class RequestLoggingFilter: Filter {
    val loggerFactory = LoggerFactory.getLogger("Kontor Logger")

    override fun doFilter(
        request: ServletRequest,
        response: ServletResponse,
        filterChain: FilterChain
    ) {
        val requestString = request.servletContext.contextPath.toString()
        //val attributeNames = request.attributeNames
        //attributeNames.toList().forEach { loggerFactory.info("Attribute: ${it.toString()}") }
        loggerFactory.info("Logging request: $requestString")
        filterChain.doFilter(request, response)
    }
}