[NETCONF-766] Logging al RESTCONF requests and responses Created: 09/Mar/21  Updated: 07/Sep/23

Status: In Review
Project: netconf
Component/s: restconf-nb
Affects Version/s: None
Fix Version/s: 7.0.0

Type: New Feature Priority: Medium
Reporter: Jaroslav Tóth Assignee: Peter Puškár
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

There should be an option to log whole RESTCONF traffic - requests and responses - without external dependency.

Customer-based requirements about the contents of logs (user ID is probably one of the most important fields - native Jetty logger/LoggingFeature from Jersey will not help much):

  • timestamp (human-readable format & unix format - milliseconds)
  • log level
  • logging filter name
  • remote address
  • controller user ID (resolved using AAA)
  • request method
  • request URI
  • request body size
  • response code
  • response payload size
  • duration in milliseconds
  • request/response body
  • http headers
  • query parameters

Next requirements:

  • option to enable/disable logging at runtime + providing a configuration using cfg file in etc
  • option to configure whether HTTP headers, query parameters, and bodies should be part of output logs
  • option to hide selected headers - Authorization/Cookie
  • option to redirect logs to separate file - logs should be generated from separate classes, so it will be possible to easily configure log4j2 appender
  • simple column-based format (using ' | ' for separation of fields)

Requests and responses can be logged separately.

Note: we can inspire by LoggingFeature or LoggingFilter (jersey).



 Comments   
Comment by Jaroslav Tóth [ 09/Mar/21 ]

proposal: https://git.opendaylight.org/gerrit/c/netconf/+/95439

available configuration in org.opendaylight.restconf.nb.rfc8040.cfg (logging is disabled by default):

#restconf-logging-enabled=true
#logging-headers-enabled=true
#logging-query-parameters-enabled=true
#logging-body-enabled=true
#hidden-http-headers=Authorization,Cookie

all logs are generated from single class - if user wants to append them to separate file, the following section can be added to org.ops4j.pax.logging.cfg:

# RESTCONF
log4j2.appender.restconf.type = RollingRandomAccessFile
log4j2.appender.restconf.name = Restconf
log4j2.appender.restconf.fileName = ${karaf.data}/log/restconf.log
log4j2.appender.restconf.filePattern = ${karaf.data}/log/restconf.log.%i
log4j2.appender.restconf.append = true
log4j2.appender.restconf.layout.type = PatternLayout
log4j2.appender.restconf.layout.pattern = %d{ISO8601} | %-5p | %d{UNIX_MILLIS} | %c{1} | %m%n
log4j2.appender.restconf.policies.type = Policies
log4j2.appender.restconf.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.restconf.policies.size.size = 64MB
log4j2.appender.restconf.strategy.type = DefaultRolloverStrategy
log4j2.appender.restconf.strategy.max = 7log4j2.logger.restconf.name = org.opendaylight.restconf.nb.rfc8040.jersey.providers.logging.RestconfLoggingBroker
log4j2.logger.restconf.level = TRACE
log4j2.logger.restconf.additivity = false
log4j2.logger.restconf.appenderRef.Restconf.ref = Restconf
Comment by Martin Skorupski [ 10/Mar/21 ]

+1

Generated at Wed Feb 07 20:15:50 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.