Update cipher logging

This commit is contained in:
2024-04-28 15:26:40 -04:00
parent 1183cab5f1
commit cc0aa2986d
26 changed files with 94 additions and 45 deletions

View File

@@ -4,6 +4,7 @@ package com.mattrixwv.cipherstream.aspect;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.MDC;
import org.springframework.context.annotation.Configuration;
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -35,7 +36,17 @@ public class CipherStreamLoggingAspect{
@AfterReturning(pointcut = "cipherMethod() && postFunction()", returning = "returnedJson")
public void getCipherInfo(ObjectNode returnedJson){
//Extract JSON to MDC
returnedJson.fields().forEachRemaining(entry -> {
if(entry.getValue().isTextual()){
MDC.put(entry.getKey(), entry.getValue().asText());
}
else{
MDC.put(entry.getKey(), entry.getValue().toString());
}
});
//Print a log
log.info("CipherStream log {}", returnedJson);
log.info("CipherStream log");
}
}

View File

@@ -10,6 +10,8 @@
</Pattern>
</PatternLayout>
</Console>
<RollingRandomAccessFile name="file" fileName="cipherStreamAPI.log" filePattern="%d{MM-dd-yyyy}-cipherStreamAPI.log.gz" immediateFlush="true">
<JsonTemplateLayout eventTemplateUri="classpath:template.json"></JsonTemplateLayout>
<Policies>
@@ -17,6 +19,16 @@
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingRandomAccessFile>
<Console name="consoleJSON" target="SYSTEM_OUT">
<JsonTemplateLayout eventTemplateUri="classpath:template.json"/>
</Console>
<Socket name="graylog" host="loggingpi.mattrixwv.com" port="1502">
<JsonTemplateLayout eventTemplateUri="classpath:template.json"/>
</Socket>
</Appenders>
<Loggers>

View File

@@ -2,7 +2,7 @@
"timestamp": {
"$resolver": "timestamp",
"pattern": {
"format": "yyy-MM-dd HH:mm:ss.SSSZ"
"format": "yyyy-MM-dd HH:mm:ss.SSSZ"
}
},
"level": {
@@ -13,6 +13,15 @@
"$resolver": "mdc",
"key": "requestId"
},
"logger": {
"$resolver": "logger",
"field": "name"
},
"mdc":{
"$resolver": "mdc",
"flatten": false,
"stringified": false
},
"message": {
"$resolver": "message",
"stringified": true

View File

@@ -42,7 +42,7 @@ public class CipherStreamLoggingAspectTest{
jsonNode.put("something", "Something Important");
aspect.getCipherInfo(null);
aspect.getCipherInfo(jsonNode);
assertNotNull(aspect);

View File

@@ -53,4 +53,21 @@ public class CipherStreamControllerIntegrationTestBase{
verify(mdc, times(1)).put("url", url);
verify(mdc, times(1)).clear();
}
protected void verifyAspectLogging(ObjectNode jsonNode){
//Verify the MDC
jsonNode.fields().forEachRemaining(entry -> {
if(entry.getValue().isTextual()){
verify(mdc, times(1)).put(entry.getKey(), entry.getValue().asText());
}
else{
verify(mdc, times(1)).put(entry.getKey(), entry.getValue().toString());
}
});
verifyNoMoreInteractions(mdc);
//Verify the logger
verify(aspectLogger, times(1)).info("CipherStream log");
verifyNoMoreInteractions(aspectLogger);
}
}

View File

@@ -116,7 +116,7 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
verify(adfgvxLogger, times(1)).info("Encoding {}", adfgvxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -156,7 +156,7 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
verify(adfgvxLogger, times(1)).info("Decoding {}", adfgvxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -116,7 +116,7 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
verify(adfgxLogger, times(1)).info("Encoding {}", adfgxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -156,7 +156,7 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
verify(adfgxLogger, times(1)).info("Decoding {}", adfgxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -116,7 +116,7 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
verify(affineLogger, times(1)).info("Encoding {}", affineName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -156,7 +156,7 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
verify(affineLogger, times(1)).info("Decoding {}", affineName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -110,7 +110,7 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
verify(atbashLogger, times(1)).info("Encoding {}", atbashName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -150,7 +150,7 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
verify(atbashLogger, times(1)).info("Decoding {}", atbashName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
verify(autokeyLogger, times(1)).info("Encoding {}", autokeyName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
verify(autokeyLogger, times(1)).info("Decoding {}", autokeyName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -110,7 +110,7 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
verify(baconianLogger, times(1)).info("Encoding {}", baconianName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -150,7 +150,7 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
verify(baconianLogger, times(1)).info("Decoding {}", baconianName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
verify(baseXLogger, times(1)).info("Encoding {}", baseXName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
verify(baseXLogger, times(1)).info("Decoding {}", baseXName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
verify(beaufortLogger, times(1)).info("Encoding {}", beaufortName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
verify(beaufortLogger, times(1)).info("Decoding {}", beaufortName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
verify(caesarLogger, times(1)).info("Encoding {}", caesarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
verify(caesarLogger, times(1)).info("Decoding {}", caesarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
verify(oneTimePadLogger, times(1)).info("Encoding {}", oneTimePadName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
verify(oneTimePadLogger, times(1)).info("Decoding {}", oneTimePadName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -118,7 +118,7 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
verify(portaLogger, times(1)).info("Encoding {}", portaName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -162,7 +162,7 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
verify(portaLogger, times(1)).info("Decoding {}", portaName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
verify(substitutionLogger, times(1)).info("Encoding {}", substitutionName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
verify(substitutionLogger, times(1)).info("Decoding {}", substitutionName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
verify(vigenereLogger, times(1)).info("Encoding {}", vigenereName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
verify(vigenereLogger, times(1)).info("Decoding {}", vigenereName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
verify(bifidLogger, times(1)).info("Encoding {}", bifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
verify(bifidLogger, times(1)).info("Decoding {}", bifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
verify(columnarLogger, times(1)).info("Encoding {}", columnarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
verify(columnarLogger, times(1)).info("Decoding {}", columnarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
verify(hillLogger, times(1)).info("Encoding {}", hillName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
verify(hillLogger, times(1)).info("Decoding {}", hillName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -103,7 +103,7 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
verify(morseLogger, times(1)).info("Encoding {}", morseName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -143,7 +143,7 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
verify(morseLogger, times(1)).info("Decoding {}", morseName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -114,7 +114,7 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
verify(playfairLogger, times(1)).info("Encoding {}", playfairName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -154,7 +154,7 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
verify(playfairLogger, times(1)).info("Decoding {}", playfairName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
verify(polybiusLogger, times(1)).info("Encoding {}", polybiusName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
verify(polybiusLogger, times(1)).info("Decoding {}", polybiusName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -113,7 +113,7 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
verify(railFenceLogger, times(1)).info("Encoding {}", railFenceName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -153,7 +153,7 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
verify(railFenceLogger, times(1)).info("Decoding {}", railFenceName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test

View File

@@ -119,7 +119,7 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
verify(trifidLogger, times(1)).info("Encoding {}", trifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
verifyAspectLogging(decodedNode);
}
@Test
@@ -159,7 +159,7 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
verify(trifidLogger, times(1)).info("Decoding {}", trifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
//Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
verifyAspectLogging(encodedNode);
}
@Test