Skip to content

Commit b994c1a

Browse files
committed
Some documentation notes from @jeremiahjstacey on the (relatively) new logging design.
1 parent 08152d5 commit b994c1a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(Gleaned from an email from Jeremiah J. Stacey to Kevin W. Wall on 2021-03-21. Some minor alterations were made for contextual understanding by Kevin Wall because the original email thread was not included.)
2+
3+
The testing (for SLF4J logging at least) is tested with Mockito and Powermock. For the SLF4J logging, the tests are in Slf4JLoggerTest. It uses mocks to assert that the slf4j logging implementation gets the data we expect in the calls we support.
4+
5+
I was very deliberate in the breakout of the classes to isolate specific functionality to enable this type of testing. At a high level, there are four classes that make up the logging structure.
6+
I tried to encapsulate a subset of functionality into each one:
7+
8+
**LogFactory** - Constructs Loggers to be used by clients. Responsible for building the LogBridge and the LevelHandler.
9+
10+
**Logger** - The ESAPI interface implementation which uses the LogBridge and a delegate Logger to forward events to the underlying log implementation.
11+
12+
**LogBridge** - Logical handler for determining the delegate handler for a known ESAPI log event, and forwarding the Log event to that handler. Also responsible for prefixing the client/server info content and applying the newline replacement behavior.
13+
14+
**LogLevelHander** - This is actually where the log event gets sent to SLF4J! The Handler enumeration is assembled as part of a map in the static block of the LogFactory, and is used by the LogBridge to route a log event at a defined ESAPI log level to the correct API of the delegate Logger.
15+
16+
17+
The general workflow is:
18+
19+
LogFactory static block creates the LogPrefixAppender, LogScrubber, and LogBridge.
20+
21+
LogFactory.getLogger(...) Creates Logger with the delegate slf4j logger implementation and the LogBridge.
22+
23+
Logger.info/warn/etc(message) -> forwards to LogBridgelog(logger, esapiLevel, type, message) -> forwards to LogHandler.log(...) -> forwards to slf4j Logger implementation with appropriate level and composed message.
24+
25+
So each of the tests for each of the classes verifies data in -> data out based on the Logging API. The structure for JUL, Log4J, and SLF4J are almost identical. There are a few differences in the interaction with the underlying Logger interactions and expectations. As a result, the tests are also almost full duplications (again accounting for differences in the underlying logging API).
26+
27+
-J

0 commit comments

Comments
 (0)