Skip to content

Commit

Permalink
#98 better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Apr 2, 2018
1 parent 84246c7 commit 8a46b27
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/dynamo/AwsFrame.java
Expand Up @@ -140,7 +140,7 @@ public int size() {
);
} catch (final IOException ex) {
throw new IllegalStateException(
String.format("can't count items in \"%s\"", this.name),
String.format("Can't count items in \"%s\"", this.name),
ex
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jcabi/dynamo/AwsItem.java
Expand Up @@ -130,7 +130,7 @@ public boolean has(final String attr) throws IOException {
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to check existence of \"%s\" at \"%s\" by %s",
"Failed to check existence of \"%s\" at \"%s\" by %s",
attr, this.name, this.keys
),
ex
Expand Down Expand Up @@ -166,7 +166,7 @@ public AttributeValue get(final String attr) throws IOException {
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to get \"%s\" from \"%s\" by %s",
"Failed to get \"%s\" from \"%s\" by %s",
attr, this.name, this.keys
),
ex
Expand Down Expand Up @@ -216,7 +216,7 @@ public Map<String, AttributeValue> put(
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to put %s into \"%s\" with %s",
"Failed to put %s into \"%s\" with %s",
attrs, this.name, this.keys
),
ex
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/dynamo/AwsIterator.java
Expand Up @@ -164,7 +164,7 @@ public Item next() {
if (!this.hasNext()) {
throw new NoSuchElementException(
String.format(
"no more items in the frame, position=%d",
"No more items in the frame, position=%d",
this.position
)
);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jcabi/dynamo/AwsTable.java
Expand Up @@ -125,7 +125,7 @@ public Item put(final Map<String, AttributeValue> attributes)
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to put into \"%s\" with %s",
"Failed to put into \"%s\" with %s",
this.self, attributes
),
ex
Expand Down Expand Up @@ -176,7 +176,7 @@ public Collection<String> keys() throws IOException {
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to describe \"%s\"",
"Failed to describe \"%s\"",
this.self
),
ex
Expand Down Expand Up @@ -210,7 +210,7 @@ public void delete(final Map<String, AttributeValue> attributes)
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to delete at \"%s\" by keys %s",
"Failed to delete at \"%s\" by keys %s",
this.self, attributes
),
ex
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/com/jcabi/dynamo/QueryValve.java
Expand Up @@ -158,8 +158,11 @@ public Dosage fetch(final Credentials credentials, final String table,
final QueryResult result = aws.query(request);
Logger.info(
this,
"#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
result.getCount(), table, conditions,
// @checkstyle LineLength (1 line)
"#items(): loaded %d item(s) from '%s' and stopped at %s, using %s, %s, in %[ms]s",
result.getCount(), table,
result.getLastEvaluatedKey(),
conditions,
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
Expand All @@ -169,7 +172,7 @@ public Dosage fetch(final Credentials credentials, final String table,
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to fetch from \"%s\" by %s and %s",
"Failed to fetch from \"%s\" by %s and %s",
table, conditions, keys
),
ex
Expand Down Expand Up @@ -208,6 +211,14 @@ public int count(final Credentials credentials, final String table,
System.currentTimeMillis() - start
);
return count;
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"Failed to count from \"%s\" by %s",
table, conditions
),
ex
);
} finally {
aws.shutdown();
}
Expand Down Expand Up @@ -371,7 +382,7 @@ public boolean hasNext() {
public Dosage next() {
if (!this.hasNext()) {
throw new IllegalStateException(
"nothing left in the iterator"
"Nothing left in the iterator"
);
}
final AmazonDynamoDB aws = this.credentials.aws();
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/jcabi/dynamo/ScanValve.java
Expand Up @@ -115,8 +115,11 @@ public Dosage fetch(final Credentials credentials,
final ScanResult result = aws.scan(request);
Logger.info(
this,
"#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
result.getCount(), table, conditions,
// @checkstyle LineLength (1 line)
"#items(): loaded %d item(s) from '%s' and stooped at %s, using %s, %s, in %[ms]s",
result.getCount(), table,
result.getLastEvaluatedKey(),
conditions,
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
Expand All @@ -126,7 +129,7 @@ public Dosage fetch(final Credentials credentials,
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to fetch from \"%s\" by %s and %s",
"Failed to fetch from \"%s\" by %s and %s",
table, conditions, keys
),
ex
Expand Down Expand Up @@ -248,7 +251,7 @@ public boolean hasNext() {
public Dosage next() {
if (!this.hasNext()) {
throw new IllegalStateException(
"nothing left in the iterator"
"Nothing left in the iterator"
);
}
final AmazonDynamoDB aws = this.credentials.aws();
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/log4j.properties
Expand Up @@ -35,5 +35,5 @@ log4j.appender.CONSOLE.layout=com.jcabi.log.MulticolorLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%color{%p}] %t %c: %m%n

# Application-specific logging
log4j.logger.com.jcabi.dynamo=DEBUG
log4j.logger.com.jcabi.jdbc=DEBUG
log4j.logger.com.jcabi.dynamo=INFO
log4j.logger.com.jcabi.jdbc=INFO

0 comments on commit 8a46b27

Please sign in to comment.