Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.2.x] Remove line breaks from logs #41827

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ public void registerService(ObjectValue service) {
basePath + errorMessage);
}
servicesByBasePath.put(basePath, httpService);
String errLog = String.format("Service deployed : %s with context %s", service.getType().getName(),
basePath);
String errLog = String.format("Service deployed : %s with context %s",
sanitizeText(service.getType().getName()),
sanitizeText(basePath));
logger.info(errLog);

//basePath will get cached after registering service
Expand Down Expand Up @@ -226,10 +227,22 @@ public void unRegisterService(ObjectValue service) {
servicesByBasePath.remove(basePath);
sortedServiceURIs.remove(basePath);
if (logger.isDebugEnabled()) {
logger.debug(String.format("Service detached : %s with context %s", service.getType().getName(),
basePath));
logger.debug(String.format("Service detached : %s with context %s",
sanitizeText(service.getType().getName()),
sanitizeText(basePath)));
}
sortedServiceURIs.sort((basePath1, basePath2) -> basePath2.length() - basePath1.length());
}
}

/**
* Sanitize a given text by removing CRLF characters.
*
* @param text text to be sanitized
* @return text after removing line break characters
*/
private static String sanitizeText(String text) {
return text.replace("\r", " ").replace("\n", " ");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.ballerinalang.stdlib.io.channels.base;

import org.ballerinalang.stdlib.io.utils.BallerinaIOException;
import org.ballerinalang.stdlib.io.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -129,7 +130,7 @@ private void appendCharsToString(StringBuilder content, int characterCount) {
charBuffer.get(remainingChars, indexCharacterOffset, characterCount);
content.append(remainingChars);
if (log.isTraceEnabled()) {
log.trace(String.format("characters appended to the string,%s", content));
log.trace(String.format("characters appended to the string,%s", Utils.sanitizeText(content.toString())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.ballerinalang.stdlib.io.csv.Format;
import org.ballerinalang.stdlib.io.utils.BallerinaIOException;
import org.ballerinalang.stdlib.io.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -180,7 +181,8 @@ private String readRecord() throws BallerinaIOException {
final int numberOfSplits = 2;
do {
if (log.isTraceEnabled()) {
log.trace(String.format("char[] remaining in memory %s", persistentCharSequence));
log.trace(String.format("char[] remaining in memory %s", Utils.sanitizeText(
persistentCharSequence.toString())));
}
//We need to split the string into 2
String[] delimitedRecord = persistentCharSequence.toString().
Expand Down Expand Up @@ -232,7 +234,8 @@ record = persistentCharSequence.toString();
//Once the final record is processed there will be no chars left
persistentCharSequence.setLength(minimumRemainingLength);
if (log.isTraceEnabled()) {
log.trace(String.format("char [] remaining in memory, will be marked as the last record %s", record));
log.trace(String.format("char [] remaining in memory, will be marked as the last record %s",
Utils.sanitizeText(record)));
}
}
if (log.isDebugEnabled()) {
Expand All @@ -253,11 +256,13 @@ private String readRecordFromChannel() throws BallerinaIOException {
String readCharacters;
readCharacters = channel.read(recordCharacterCount);
if (log.isTraceEnabled()) {
log.trace(String.format("char [] get from channel,%d=%s", channel.hashCode(), readCharacters));
log.trace(String.format("char [] get from channel,%d=%s", channel.hashCode(),
Utils.sanitizeText(readCharacters)));
}
persistentCharSequence.append(readCharacters);
if (log.isTraceEnabled()) {
log.trace(String.format("char [] appended to the memory %s", persistentCharSequence));
log.trace(String.format("char [] appended to the memory %s", Utils.sanitizeText(
persistentCharSequence.toString())));
}
return readCharacters;
}
Expand All @@ -283,8 +288,10 @@ record = delimitedRecords[delimitedRecordIndex];
persistentCharSequence.setLength(minimumRemainingLength);
persistentCharSequence.append(recordContent);
if (log.isTraceEnabled()) {
log.trace(String.format("Record identified from remaining char[] in memory %s", record));
log.trace(String.format("The char[] left after split %s", persistentCharSequence));
log.trace(String.format("Record identified from remaining char[] in memory %s",
Utils.sanitizeText(record)));
log.trace(String.format("The char[] left after split %s",
Utils.sanitizeText(persistentCharSequence.toString())));
}
return record;
}
Expand Down Expand Up @@ -362,7 +369,7 @@ public String[] read() throws BallerinaIOException {
}
if (log.isTraceEnabled()) {
log.trace("The list of fields identified in record " + numberOfRecordsReadThroughChannel + "from " +
"channel " + channel.hashCode() + "," + Arrays.toString(fields));
"channel " + channel.hashCode() + "," + Utils.sanitizeText(Arrays.toString(fields)));
}
}
} else {
Expand Down Expand Up @@ -428,7 +435,8 @@ public void write(String[] fields) throws IOException {
String record = composeRecord(fields);
record = record + getRecordSeparatorForWriting();
if (log.isTraceEnabled()) {
log.trace(String.format("The record %d composed for writing, %s", numberOfRecordsWrittenToChannel, record));
log.trace(String.format("The record %d composed for writing, %s", numberOfRecordsWrittenToChannel,
Utils.sanitizeText(record)));
}
channel.write(record, writeOffset);
if (log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,14 @@ public static ArrayValue decodeBlob(byte[] encodedContent, boolean isMimeSpecifi
}
return new ArrayValueImpl(decodedContent);
}

/**
* Sanitize a given text by removing CRLF characters.
*
* @param text text to be sanitized
* @return text after removing line break characters
*/
public static String sanitizeText(String text) {
return text.replace("\r", " ").replace("\n", " ");
}
}
Loading