################################################################################
#
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
################################################################################

# Colors for log level rendering
color.fatal = bright red
color.error = bright red
color.warn = bright yellow
color.info = bright green
color.debug = cyan
color.trace = cyan

# Common pattern layout for appenders
log4j2.pattern = %d{ISO8601} | %-5p | %-16t | %-32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
log4j2.outpattern = \u001b[90m%d{HH:mm:ss\.SSS}\u001b[0m %highlight{%-5level}{FATAL=${color.fatal}, ERROR=${color.error}, WARN=${color.warn}, INFO=${color.info}, DEBUG=${color.debug}, TRACE=${color.trace}} \u001b[90m[%t]\u001b[0m %msg%n%throwable
# Chained replacement patterns to mask sensitive information
# Filter out UUIDs as these are used as session cookies (keycloak+oidc)
bpc.maskuuids.pattern = %replace{${log4j2.pattern}}{(?i)([a-f0-9]{4})[a-f0-9]{4}(-[a-f0-9]{4}){3}-[a-f0-9]{8}(([a-f0-9]{4}))(?-i)}{$1****-****-****-****-********$3}
# Filter out JWT Tokens that might contain session ids
bpc.maskjwt.pattern = %replace{${bpc.maskuuids.pattern}}{ey[\\w-]+\\.ey[\\w-]+\\.[\\w-]+}{***(JWT)***}
bpc.maskunsecuredjwt.pattern = %replace{${bpc.maskjwt.pattern}}{ey[\\w-]+\\.ey[\\w-]+\\.}{***(JWT)***}
# Filter out 256bit (64 hex digits) UUIDs used for karaf session cookies and API keys
bpc.maskkarafsessioncookie.pattern = %replace{${bpc.maskunsecuredjwt.pattern}}{[0-9a-fA-F]{64}}{******}
# Filter out passwords
bpc.maskpasswords.pattern = %replace{${bpc.maskkarafsessioncookie.pattern}}{(password=[^\\s,]+)|("password"\\s*:\\s*"\\w+")}{******}

# Root logger
log4j2.rootLogger.level = INFO
# uncomment to use asynchronous loggers, which require mvn:com.lmax/disruptor/3.3.2 and mvn:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.4 libraries
#log4j2.rootLogger.type = asyncRoot
#log4j2.rootLogger.includeLocation = false
log4j2.rootLogger.appenderRef.KarafRollingFile.ref = KarafRollingFile
log4j2.rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi
log4j2.rootLogger.appenderRef.Console.ref = Console
log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter
log4j2.rootLogger.appenderRef.Console.filter.threshold.level = ${karaf.log.console:-OFF}
#log4j2.rootLogger.appenderRef.Sift.ref = Routing

# Loggers configuration

# CXF
log4j2.logger.org_apache_cxf.name = org.apache.cxf
log4j2.logger.org_apache_cxf.level = ERROR

# SSHD logger
log4j2.logger.sshd.name = org.apache.sshd
log4j2.logger.sshd.level = INFO

# Spifly logger
log4j2.logger.spifly.name = org.apache.aries.spifly
log4j2.logger.spifly.level = WARN

# Security audit logger
log4j2.logger.audit.name = audit
log4j2.logger.audit.level = TRACE
log4j2.logger.audit.additivity = false
log4j2.logger.audit.appenderRef.AuditRollingFile.ref = AuditRollingFile

# Appenders configuration

# Console appender not used by default (see log4j2.rootLogger.appenderRefs)
log4j2.appender.console.type = Console
log4j2.appender.console.name = Console
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = ${log4j2.outpattern}

# Karaf Rolling file appender
log4j2.appender.rolling.type = RollingFile
log4j2.appender.rolling.name = KarafRollingFile
log4j2.appender.rolling.fileName = ${karaf.log}/karaf.log
log4j2.appender.rolling.filePattern = ${karaf.log}/karaf-log/karaf-%d{yyyy-MM-dd}-%i.log.gz
log4j2.appender.rolling.append = true
log4j2.appender.rolling.layout.type = PatternLayout
log4j2.appender.rolling.layout.pattern = ${bpc.maskpasswords.pattern}
log4j2.appender.rolling.policies.type = Policies
# change log file after 50MB size
log4j2.appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.rolling.policies.size.size = 50MB
# change log file every day
log4j2.appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
log4j2.appender.rolling.policies.time.interval = 1
log4j2.appender.rolling.policies.time.modulate = true
# delete log files older than 7 days (gets executed on next rollover)
log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy
log4j2.appender.rolling.strategy.max = 50
log4j2.appender.rolling.strategy.action.type = Delete
log4j2.appender.rolling.strategy.action.basepath = ${karaf.log}/karaf-log
log4j2.appender.rolling.strategy.action.maxdepth = 1
log4j2.appender.rolling.strategy.action.condition.type = IfFileName
log4j2.appender.rolling.strategy.action.condition.glob = karaf-*.log.gz
log4j2.appender.rolling.strategy.action.ifLastModified.type = IfLastModified
log4j2.appender.rolling.strategy.action.ifLastModified.age = 7D

# Audit file appender
log4j2.appender.audit.type = RollingRandomAccessFile
log4j2.appender.audit.name = AuditRollingFile
log4j2.appender.audit.fileName = ${karaf.log}/security.log
log4j2.appender.audit.filePattern = ${karaf.log}/security-%i.log
log4j2.appender.audit.append = true
log4j2.appender.audit.layout.type = PatternLayout
log4j2.appender.audit.layout.pattern = %m%n
log4j2.appender.audit.policies.type = Policies
log4j2.appender.audit.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.audit.policies.size.size = 1MB
log4j2.appender.audit.strategy.type = DefaultRolloverStrategy
log4j2.appender.audit.strategy.max = 10

# OSGi appender
log4j2.appender.osgi.type = PaxOsgi
log4j2.appender.osgi.name = PaxOsgi
log4j2.appender.osgi.filter = *

# help with identification of maven-related problems with pax-url-aether
#log4j2.logger.aether.name = shaded.org.eclipse.aether
#log4j2.logger.aether.level = TRACE
#log4j2.logger.http-headers.name = shaded.org.apache.http.headers
#log4j2.logger.http-headers.level = DEBUG
#log4j2.logger.maven.name = org.ops4j.pax.url.mvn
#log4j2.logger.maven.level = TRACE

# Sift - MDC routing
#log4j2.appender.routing.type = Routing
#log4j2.appender.routing.name = Routing
#log4j2.appender.routing.routes.type = Routes
#log4j2.appender.routing.routes.pattern = \$\$\\\{ctx:bundle.name\}
#log4j2.appender.routing.routes.bundle.type = Route
#log4j2.appender.routing.routes.bundle.appender.type = RollingRandomAccessFile
#log4j2.appender.routing.routes.bundle.appender.name = Bundle-\$\\\{ctx:bundle.name\}
#log4j2.appender.routing.routes.bundle.appender.fileName = ${karaf.log}/bundle-\$\\\{ctx:bundle.name\}.log
#log4j2.appender.routing.routes.bundle.appender.filePattern = ${karaf.log}/bundle-\$\\\{ctx:bundle.name\}.log.%i
#log4j2.appender.routing.routes.bundle.appender.append = true
#log4j2.appender.routing.routes.bundle.appender.layout.type = PatternLayout
#log4j2.appender.routing.routes.bundle.appender.layout.pattern = ${log4j2.pattern}
#log4j2.appender.routing.routes.bundle.appender.policies.type = Policies
#log4j2.appender.routing.routes.bundle.appender.policies.size.type = SizeBasedTriggeringPolicy
#log4j2.appender.routing.routes.bundle.appender.policies.size.size = 8MB


# ----------------------------------------------------------------------------------------------
# Virtimo related loggers and appenders
# ----------------------------------------------------------------------------------------------

# BPC logger
log4j2.logger.bpc.name = de.virtimo.bpc
log4j2.logger.bpc.level = WARN
log4j2.logger.bpc.additivity = true
log4j2.logger.bpc.appenderRef.BpcRollingFile.ref = BpcRollingFile

# FileInstall logger
log4j2.logger.FileInstall.name = org.apache.felix.fileinstall
log4j2.logger.FileInstall.level = INFO
log4j2.logger.FileInstall.additivity = true
log4j2.logger.FileInstall.appenderRef.FileInstallRollingFile.ref = FileInstallRollingFile

# BPC authentication logger
log4j2.logger.Authentication.name = authentication
log4j2.logger.Authentication.level = WARN
log4j2.logger.Authentication.additivity = true
log4j2.logger.Authentication.appenderRef.AuthenticationRollingFile.ref = AuthenticationRollingFile

# BPC appender
log4j2.appender.bpc.type = RollingRandomAccessFile
log4j2.appender.bpc.name = BpcRollingFile
log4j2.appender.bpc.fileName = ${karaf.log}/bpc.log
log4j2.appender.bpc.filePattern = ${karaf.log}/bpc.log.%i
log4j2.appender.bpc.append = true
log4j2.appender.bpc.layout.type = PatternLayout
log4j2.appender.bpc.layout.pattern = ${bpc.maskpasswords.pattern}
log4j2.appender.bpc.policies.type = Policies
log4j2.appender.bpc.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.bpc.policies.size.size = 20MB
log4j2.appender.bpc.strategy.type = DefaultRolloverStrategy
log4j2.appender.bpc.strategy.max = 5

# FileInstall appender
log4j2.appender.FileInstall.type = RollingRandomAccessFile
log4j2.appender.FileInstall.name = FileInstallRollingFile
log4j2.appender.FileInstall.fileName = ${karaf.log}/fileInstall.log
log4j2.appender.FileInstall.filePattern = ${karaf.log}/fileInstall.log.%i
log4j2.appender.FileInstall.append = true
log4j2.appender.FileInstall.layout.type = PatternLayout
log4j2.appender.FileInstall.layout.pattern = ${bpc.maskpasswords.pattern}
log4j2.appender.FileInstall.policies.type = Policies
log4j2.appender.FileInstall.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.FileInstall.policies.size.size = 2MB
log4j2.appender.FileInstall.strategy.type = DefaultRolloverStrategy
log4j2.appender.FileInstall.strategy.max = 5

# Authentication appender
log4j2.appender.Authentication.type = RollingRandomAccessFile
log4j2.appender.Authentication.name = AuthenticationRollingFile
log4j2.appender.Authentication.fileName = ${karaf.log}/authentication.log
log4j2.appender.Authentication.filePattern = ${karaf.log}/authentication.log.%i
log4j2.appender.Authentication.append = true
log4j2.appender.Authentication.layout.type = PatternLayout
log4j2.appender.Authentication.layout.pattern = ${bpc.maskpasswords.pattern}
log4j2.appender.Authentication.policies.type = Policies
log4j2.appender.Authentication.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.Authentication.policies.size.size = 2MB
log4j2.appender.Authentication.strategy.type = DefaultRolloverStrategy
log4j2.appender.Authentication.strategy.max = 5
