Skip to content

Commit

Permalink
Merge pull request #1098 from harshalkh/patch-1
Browse files Browse the repository at this point in the history
Remove Error logger in module-ballerina-io
  • Loading branch information
sahanHe authored Nov 3, 2023
2 parents a6cc9ed + c90964f commit 4337dda
Show file tree
Hide file tree
Showing 16 changed files with 7 additions and 171 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Fixed the fileReadCsv and fileReadCsvAsStream APIs to maintain the order while reading CSV records](https://github.com/ballerina-platform/ballerina-standard-library/issues/3780)
- [Fixed the issue related to expected type in CSV data mapping](https://github.com/ballerina-platform/ballerina-standard-library/issues/3669)
- [Make some of the Java classes proper utility classes](https://github.com/ballerina-platform/ballerina-standard-library/issues/4901)
- [Remove Error logger in module-ballerina-io](https://github.com/ballerina-platform/ballerina-standard-library/issues/3083)

## [1.3.1] - 2022-11-29
### Changed
Expand Down
1 change: 0 additions & 1 deletion native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies {
implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'ballerina-rt', version: "${ballerinaLangVersion}"
implementation group: 'org.slf4j', name: 'slf4j-jdk14', version: "${slf4jVersion}"
implementation group: 'commons-codec', name: 'commons-codec', version: '1.9'
implementation 'org.testng:testng:7.6.1'
checkstyle project(":checkstyle")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package io.ballerina.stdlib.io.channels.base;

import io.ballerina.stdlib.io.utils.BallerinaIOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -51,10 +49,9 @@ public class Buffer {
*/
private int minimumSizeOfBuffer;

private static final Logger log = LoggerFactory.getLogger(Buffer.class);

public Buffer(int minimumSizeOfBuffer) {
this.minimumSizeOfBuffer = minimumSizeOfBuffer;
this.byteBuffer = null;
}

/**
Expand All @@ -69,18 +66,12 @@ public Buffer(int minimumSizeOfBuffer) {
* The operation will return null if none of the bytes are remaining in the buffer.
* </p>
*
* @param totalNumberOfBytesRequired number of bytes required.
* @return new ByteBuffer which will contain bytes which are remaining.
*/
private ByteBuffer remainingContent(int totalNumberOfBytesRequired) {
private ByteBuffer remainingContent() {
ByteBuffer remainingContent = null;
if (null != byteBuffer) {
remainingContent = byteBuffer.slice();
} else {
if (log.isDebugEnabled()) {
log.debug("ByteBuffer has not being initialized, buffer will be initialized while reading the " +
"requested amount of " + totalNumberOfBytesRequired + " of bytes");
}
}
return remainingContent;
}
Expand Down Expand Up @@ -226,7 +217,7 @@ private ByteBuffer copyRemainingContent(int numberOfBytesRequested, ByteBuffer c
* @throws IOException errors which occur while reading from the channel.
*/
public ByteBuffer get(int numberOfBytesRequested, Channel channel) throws IOException {
ByteBuffer remainingContent = remainingContent(numberOfBytesRequested);
ByteBuffer remainingContent = remainingContent();
if (null != remainingContent && remainingContent.capacity() >= numberOfBytesRequested) {
return copyRemainingContent(numberOfBytesRequested, remainingContent);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

package io.ballerina.stdlib.io.channels.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -55,8 +52,6 @@ public abstract class Channel implements IOChannel {
*/
private boolean readable;

private static final Logger log = LoggerFactory.getLogger(Channel.class);

/**
* <p>
* Will read/write bytes from the provided channel
Expand Down Expand Up @@ -173,8 +168,6 @@ public boolean isReadable() {
public void close() throws IOException {
if (null != byteChannel) {
byteChannel.close();
} else {
log.error("The channel has already being closed");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package io.ballerina.stdlib.io.channels.base;

import io.ballerina.stdlib.io.utils.BallerinaIOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand All @@ -41,8 +39,6 @@
*/
public class CharacterChannel implements IOChannel {

private static final Logger log = LoggerFactory.getLogger(CharacterChannel.class);

/**
* Channel implementation to read/write characters.
*/
Expand Down Expand Up @@ -134,9 +130,6 @@ private void appendCharsToString(StringBuilder content, int characterCount) {
char[] remainingChars = new char[characterCount];
charBuffer.get(remainingChars, indexCharacterOffset, characterCount);
content.append(remainingChars);
if (log.isTraceEnabled()) {
log.trace(String.format("characters appended to the string,%s", content));
}
}

/**
Expand All @@ -161,25 +154,13 @@ private void appendRemainingCharacters(StringBuilder content) {
//The length of the string builder
int numberOfCharsRequired = content.capacity();
final int minimumCharacterCount = 0;
if (log.isDebugEnabled()) {
log.debug("number of characters requested = " + numberOfCharsRequired + ",characters remaining in " +
"buffer= " + numberOfCharactersRemaining);
}
if (numberOfCharsRequired < numberOfCharactersRemaining) {
//If the remaining character count is < we need to reduce the required number of chars
numberOfCharactersRemaining = numberOfCharsRequired;
}
if (numberOfCharactersRemaining > minimumCharacterCount) {
if (log.isDebugEnabled()) {
log.debug(String.format("appending %d to the string.", numberOfCharactersRemaining));
}
appendCharsToString(content, numberOfCharactersRemaining);
}
} else {
if (log.isDebugEnabled()) {
log.debug(String.format("character buffer has not being initialized yet for channel %d",
channel.hashCode()));
}
}
}

Expand Down Expand Up @@ -314,10 +295,6 @@ public String read(int numberOfCharacters) throws BallerinaIOException {
//This means there's no requirement to get the characters from channel
return content.toString();
}
if (log.isDebugEnabled()) {
log.debug(String.format("number of chars required to be get from the channel %d",
charsRequiredToBeReadFromChannel));
}
asyncReadBytesFromChannel(numberOfBytesRequired, numberOfCharacters);
//Ensure that the required amount of characters are available in the buffer
if (charBuffer.limit() < charsRequiredToBeReadFromChannel) {
Expand Down Expand Up @@ -359,8 +336,6 @@ public int write(String content, int offset) throws IOException {
do {
numberOfBytesWritten = numberOfBytesWritten + channel.write(encodedBuffer);
} while (encodedBuffer.hasRemaining());
} else {
log.warn("channel has already being closed");
}
return numberOfBytesWritten;
} catch (CharacterCodingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@

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

import java.io.IOException;
import java.util.Arrays;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -94,8 +91,6 @@ public class DelimitedRecordChannel implements IOChannel {

private static final String DOUBLE_QUOTE_REGEX = "\"([^\"]*)\"";

private static final Logger log = LoggerFactory.getLogger(DelimitedRecordChannel.class);

public DelimitedRecordChannel(CharacterChannel channel, Format format) {
this.channel = channel;
this.format = format;
Expand Down Expand Up @@ -179,9 +174,6 @@ private String readRecord() throws BallerinaIOException {
final int minimumRecordCount = 1;
final int numberOfSplits = 2;
do {
if (log.isTraceEnabled()) {
log.trace(String.format("char[] remaining in memory %s", persistentCharSequence));
}
//We need to split the string into 2
String[] delimitedRecord = persistentCharSequence.toString().
split(getRecordSeparatorForReading(), numberOfSplits);
Expand Down Expand Up @@ -220,24 +212,13 @@ record = readFinalRecord();
private String readFinalRecord() {
final int minimumRemainingLength = 0;
String record = "";
//This means there's no more to be get as records
if (log.isDebugEnabled()) {
log.debug(String.format("The content returned from the channel %d is <void>", channel.hashCode()));
}
//This means this will be the last record which could be get
this.remaining = false;
//If there're any remaining characters left we provide it as the last record
if (persistentCharSequence.length() > minimumRemainingLength) {
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));
}
}
if (log.isDebugEnabled()) {
log.debug("Final record is get from channel " + channel.hashCode() + " number of records get " +
"from channel " + (numberOfRecordsReadThroughChannel + 1));
}
return record;
}
Expand All @@ -252,13 +233,7 @@ record = persistentCharSequence.toString();
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));
}
persistentCharSequence.append(readCharacters);
if (log.isTraceEnabled()) {
log.trace(String.format("char [] appended to the memory %s", persistentCharSequence));
}
return readCharacters;
}

Expand All @@ -282,10 +257,6 @@ private String processIdentifiedRecord(String[] delimitedRecords) {
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));
}
return record;
}

Expand Down Expand Up @@ -348,32 +319,12 @@ public String[] read() throws BallerinaIOException {
final int emptyArrayIndex = 0;
String[] fields = new String[emptyArrayIndex];
if (remaining) {
if (log.isDebugEnabled()) {
log.debug(String.format("Reading record %d from %d", numberOfRecordsReadThroughChannel,
channel.hashCode()));
}
String record = readRecord();
if (!record.isEmpty() || remaining) {
fields = getFields(record);
numberOfRecordsReadThroughChannel++;
if (log.isDebugEnabled()) {
log.debug("Record " + numberOfRecordsReadThroughChannel + " returned " + fields.length + " from " +
"channel " + channel.hashCode());
}
if (log.isTraceEnabled()) {
log.trace("The list of fields identified in record " + numberOfRecordsReadThroughChannel + "from " +
"channel " + channel.hashCode() + "," + Arrays.toString(fields));
}
}
} else {
//The channel could be null if it's being closed by a different source
if (null != channel) {
log.warn(String.format("The final record has already being processed through the channel %d",
channel.hashCode()));
} else {
log.warn("The requested channel has already being closed");
}
}
}
return fields;
}

Expand All @@ -399,9 +350,6 @@ private String composeRecord(String[] fields) {
long numberOfFields = fields.length;
final int fieldStartIndex = 0;
final long secondLastFieldIndex = numberOfFields - 1;
if (log.isDebugEnabled()) {
log.debug(String.format("Number of fields to be composed %d", numberOfFields));
}
for (int fieldCount = fieldStartIndex; fieldCount < numberOfFields; fieldCount++) {
String currentFieldString = fields[fieldCount];
if (currentFieldString.contains(getFieldSeparatorForWriting())) {
Expand All @@ -427,14 +375,7 @@ public void write(String[] fields) throws IOException {
final int writeOffset = 0;
String record = composeRecord(fields);
record = record + getRecordSeparatorForWriting();
if (log.isTraceEnabled()) {
log.trace(String.format("The record %d composed for writing, %s", numberOfRecordsWrittenToChannel, record));
}
channel.write(record, writeOffset);
if (log.isDebugEnabled()) {
log.debug(String.format("Record %d written to the channel %d", numberOfRecordsReadThroughChannel,
channel.hashCode()));
}
numberOfRecordsWrittenToChannel++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import io.ballerina.stdlib.io.utils.IOConstants;
import io.ballerina.stdlib.io.utils.IOUtils;
import io.ballerina.stdlib.io.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
Expand All @@ -57,7 +55,6 @@
*/
public class ByteChannelUtils extends AbstractNativeChannel {

private static final Logger log = LoggerFactory.getLogger(ByteChannelUtils.class);
private static final String STREAM_BLOCK_ENTRY = "value";
private static final String IS_CLOSED = "isClosed";

Expand All @@ -80,7 +77,6 @@ public static Object read(BObject channel, long nBytes) {
return IOUtils.createError("Byte channel is already closed.");
} catch (Exception e) {
String msg = "error occurred while reading bytes from the channel. " + e.getMessage();
log.error(msg, e);
return IOUtils.createError(msg);
}
}
Expand Down Expand Up @@ -194,7 +190,6 @@ public static Object write(BObject channel, BArray content, long offset) {
return IOUtils.createError(IOConstants.ErrorCode.GenericError,
"Byte channel is already closed.");
} catch (IOException e) {
log.error("Error occurred while writing to the channel.", e);
return IOUtils.createError(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import io.ballerina.stdlib.io.utils.IOConstants;
import io.ballerina.stdlib.io.utils.IOUtils;
import io.ballerina.stdlib.io.utils.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -52,7 +50,6 @@
*/
public class CharacterChannelUtils {

private static final Logger log = LoggerFactory.getLogger(CharacterChannelUtils.class);
private static final String BUFFERED_READER_ENTRY = "bufferedReader";
private static final String NEW_LINE = "\n";
private static final String IS_CLOSED = "isClosed";
Expand All @@ -75,7 +72,6 @@ public static void initCharacterChannel(BObject characterChannel, BObject byteCh
throw IOUtils.createError("Unsupported encoding type " + encoding.getValue());
} catch (Exception e) {
String message = "error occurred while converting byte channel to character channel: " + e.getMessage();
log.error(message, e);
throw IOUtils.createError(message);
}
}
Expand All @@ -92,7 +88,6 @@ public static Object read(BObject channel, long numberOfCharacters) {
try {
return StringUtils.fromString(characterChannel.read((int) numberOfCharacters));
} catch (BallerinaIOException e) {
log.error("error occurred while reading characters.", e);
return IOUtils.createError(e);
}
}
Expand Down Expand Up @@ -169,7 +164,6 @@ public static Object readJson(BObject channel) {
}
return returnValue;
} catch (BError e) {
log.error("unable to read json from character channel", e);
return IOUtils.createError(e);
}
}
Expand Down
Loading

0 comments on commit 4337dda

Please sign in to comment.