lsc-project / lsc

LSC engine
http://lsc-project.org/wiki/documentation/latest/start
Other
105 stars 40 forks source link

Cleanup the CSV and LDIF layouts for logback feature #294

Open davidcoutadeur opened 3 days ago

davidcoutadeur commented 3 days ago

This issue is derived from #107

The goal is to fix the following issues, discovered in logback ldif and csv logging:

davidcoutadeur commented 3 days ago

Here are the details (copy-paste from issue #107):

Here is the status of my tests about the logback configuration. I have compiled LSC from master branch (https://github.com/lsc-project/lsc/commit/1b800cc780fb50ad9330a80cda73bc307d479334), with openjdk 17. I have tested on a simple use case OpenLDAP -> OpenLDAP with openjdk 17.

CSV layout

Most of the options described in the documentation are accurate:

uid=test,ou=people2,dc=my-domain,dc=com;test;test;;test1;;inetOrgPerson
uid=test,ou=people2,dc=my-domain,dc=com;;test;;;;
uid=test2,ou=people2,dc=my-domain,dc=com;test2;;;;;
diff --git a/src/main/java/org/lsc/utils/output/CsvLayout.java b/src/main/java/org/lsc/utils/output/CsvLayout.java
index fcfc8952..226b1b25 100644
--- a/src/main/java/org/lsc/utils/output/CsvLayout.java
+++ b/src/main/java/org/lsc/utils/output/CsvLayout.java
@@ -123,6 +123,7 @@ public class CsvLayout extends LayoutBase<ILoggingEvent> {
                                                        ( taskNamesList.size() == 0 ||
                                                          taskNamesList.contains(lm.getTaskName().toLowerCase()))) {
                                StringBuilder sb = new StringBuilder(1024);
+                               sb.append(this.getHeader());

                                Map<String, List<Object>> modifications = lm.getModificationsItemsByHash();

diff --git a/src/test/java/org/lsc/utils/output/CsvLayoutTest.java b/src/test/java/org/lsc/utils/output/CsvLayoutTest.java
index 65c27bbd..a9f81c35 100644
--- a/src/test/java/org/lsc/utils/output/CsvLayoutTest.java
+++ b/src/test/java/org/lsc/utils/output/CsvLayoutTest.java
@@ -178,10 +178,10 @@ public class CsvLayoutTest {
                // log one line to check that the outputHeader is prepended
                ILoggingEvent event = makeLoggingEvent(jm.toString(), jm);
                assertEquals("givenName%sn%dn%%cn\n", layout.getHeader());
-               assertEquals("Jon%%cn=test,o=testing%%Tester CN\n", layout.doLayout(event));
+               assertEquals("givenName%sn%dn%%cn\nJon%%cn=test,o=testing%%Tester CN\n", layout.doLayout(event));

                // log the same line again to check that the outputHeader is not logged again
                event = makeLoggingEvent(jm.toString(), jm);
-               assertEquals("Jon%%cn=test,o=testing%%Tester CN\n", layout.doLayout(event));
+               assertEquals("givenName%sn%dn%%cn\nJon%%cn=test,o=testing%%Tester CN\n", layout.doLayout(event));
        }
 }

Note: there is actually a test /src/test/java/org/lsc/utils/output/CsvLayoutTest.java, but it just verifies the method getHeader() is returning the corresponding header. But the getHeader() method does not seem to be called anywhere in our code. If we apply the fix above, we must also fix this test.

LDIF layout

Globally, the ldif output is working.