Fix special character encoding in json logging
Problem
As shown in https://gitlab.cern.ch/cta/operations/-/issues/1409#note_7992226, the rmcd logs contain a few newline characters.
When these lines are ingested by the cta-taped logging, they end up splitting the JSON logs across different lines, which make parsing unnecessarly complicated.
{"epoch_time":1715747147.331473395,"local_time":"2024-05-15T06:25:47+0200","hostname":"tpsrv610","program":"cta-taped","log_level":"ERROR","pid":"1647083","tid":"1651492","message":"Tape thread complete for writing","drive_name":"SPECTRALIB2-LTO9-F05B4S2","instance":"ctaproduction","sched_backend":"cephProductionUser","thread":"TapeWrite","tapeDrive":"SPECTRALIB2-LTO9-F05B4S2","tapeVid":"L83377","mountId":"1301732","vo":"CMS","tapePool":"r_cms_2024","ErrorMessage":"Failed to mount tape for read/write access: vid=L83377 slot=smc9: Failed to mount tape in SCSI tape-library for read/write access: vid=L83377 librarySlot=smc9: Received error from rmcd: rmcRc=2204 rmcErrorStream=smc_mount: Asked for L83377, got reply for L83377
smc_mount: Location: data transfer element (0x4)
smc_mount: SR018 - mount of L83377 on drive 9 failed : volume in use
","type":"write","mountTime":0.0,"positionTime":0.0,"waitInstructionsTime":0.190275,"checksumingTime":0.0,"readWriteTime":0.0,"waitDataTime":0.0,"waitReportingTime":0.732597,"flushTime":0.0,"unloadTime":0.0,"unmountTime":0.0,"encryptionControlTime":0.002911,"transferTime":0.922872,"totalTime":300.926947,"dataVolume":0,"headerVolume":0,"files":0,"payloadTransferSpeedMBps":0.0,"driveTransferSpeedMBps":0.0,"status":"error"}
Solution
Remove newline characters from rmcd logs.
Edit:
- Instead of doing any changes to rmcd -- for now -- we will fix the JSON logging to be able to handle escape characters correctly.
- In this case the logging of the C++ string
"ABC\nDEF"
will be converted to the JSON"key": "ABC\nDEF"
, which is properly escaped and valid, instead of actually printing a new line.
Edited by Joao Afonso