Skip to content

Commit bd29612

Browse files
committed
Merge pull request #36 from rpmoore/master
Updating how Logging is Implemented
2 parents 1293480 + c01fb27 commit bd29612

File tree

13 files changed

+90
-127
lines changed

13 files changed

+90
-127
lines changed

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ apply plugin: 'maven'
2525
apply plugin: 'idea'
2626
apply plugin: 'application'
2727

28-
version = '1.1.3'
28+
version = '1.1.4'
2929
group = 'com.spectralogic'
3030

3131
mainClassName = 'com.spectralogic.ds3cli.Main'
@@ -44,7 +44,9 @@ dependencies {
4444
compile 'commons-cli:commons-cli:1.2'
4545
compile 'com.google.guava:guava:18.0'
4646
compile 'joda-time:joda-time:2.7'
47-
compile 'com.spectralogic.ds3:ds3-sdk:1.1.0-RC3'
47+
compile 'ch.qos.logback:logback-core:1.0.13'
48+
compile 'ch.qos.logback:logback-classic:1.0.13'
49+
compile 'com.spectralogic.ds3:ds3-sdk:1.1.0-RC4'
4850
compile (
4951
[group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.2.3'],
5052
[group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.2.3'],
@@ -70,5 +72,5 @@ task genConfigProperties << {
7072
jar.dependsOn genConfigProperties
7173

7274
task wrapper(type: Wrapper) {
73-
gradleVersion = '2.3'
75+
gradleVersion = '2.4'
7476
}

src/main/java/com/spectralogic/ds3cli/Arguments.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515

1616
package com.spectralogic.ds3cli;
1717

18-
import com.spectralogic.ds3cli.logging.Logging;
18+
import ch.qos.logback.classic.Level;
1919
import com.spectralogic.ds3client.models.bulk.Priority;
2020
import com.spectralogic.ds3client.models.bulk.WriteOptimization;
2121
import org.apache.commons.cli.*;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
2224

2325
import java.io.IOException;
2426
import java.io.InputStream;
@@ -28,6 +30,8 @@
2830

2931
public class Arguments {
3032

33+
private final static Logger LOG = LoggerFactory.getLogger(Arguments.class);
34+
3135
private final static String PROPERTY_FILE = "config.properties";
3236

3337
private final Options options;
@@ -120,6 +124,8 @@ public class Arguments {
120124
version.setLongOpt("version");
121125
final Option verbose = new Option(null, "Verbose output");
122126
verbose.setLongOpt("verbose");
127+
final Option debug = new Option(null, "Debug output. If set takes presidence over the 'verbose' option");
128+
debug.setLongOpt("debug");
123129
final Option viewType = new Option(null, true, "Configure how the output should be displayed. Possible values: ["+ ViewType.valuesString() +"]");
124130
viewType.setLongOpt("output-format");
125131
options.addOption(ds3Endpoint);
@@ -144,6 +150,7 @@ public class Arguments {
144150
options.addOption(http);
145151
options.addOption(version);
146152
options.addOption(verbose);
153+
options.addOption(debug);
147154
options.addOption(viewType);
148155

149156
// Disabled until they are enabled in DS3.
@@ -159,12 +166,21 @@ private void processCommandLine() throws ParseException, BadArgumentException {
159166
final CommandLine cmd = parser.parse(options, args);
160167

161168
final List<String> missingArgs = new ArrayList<>();
162-
if (cmd.hasOption("verbose")) {
163-
Logging.setVerbose(true);
164-
Logging.log("Verbose output has been enabled");
165-
Logging.logf("Version: %s", this.version);
169+
170+
final ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
171+
172+
if (cmd.hasOption("debug")) {
173+
rootLogger.setLevel(Level.DEBUG);
174+
rootLogger.info("Debug output enabled");
175+
} else if (cmd.hasOption("verbose")) {
176+
rootLogger.setLevel(Level.INFO);
177+
rootLogger.info("Verbose output enabled");
178+
} else {
179+
rootLogger.setLevel(Level.OFF);
166180
}
167181

182+
rootLogger.info("Version: " + this.version);
183+
168184
if (cmd.hasOption('h')) {
169185
printHelp();
170186
System.exit(0);
@@ -283,13 +299,13 @@ private void processCommandLine() throws ParseException, BadArgumentException {
283299
final String proxy = System.getenv("http_proxy");
284300
if (proxy != null) {
285301
setProxy(proxy);
286-
Logging.logf("Proxy: %s", getProxy());
302+
LOG.info("Proxy: %s", getProxy());
287303
}
288304

289305
if (!missingArgs.isEmpty()) {
290306
throw new MissingOptionException(missingArgs);
291307
}
292-
Logging.logf("Access Key: %s | Secret Key: %s | Endpoint: %s", getAccessKey(), getSecretKey(), getEndpoint());
308+
LOG.info("Access Key: " + getAccessKey() +" | Secret Key: " + getSecretKey() + " | Endpoint: " + getEndpoint());
293309
}
294310

295311
private WriteOptimization processWriteOptimization(final CommandLine cmd, final String writeOptimization) throws BadArgumentException {
@@ -341,7 +357,7 @@ private void loadProperties() {
341357
this.buildDate = (String) props.get("build.date");
342358
} catch (final IOException e) {
343359
System.err.println("Failed to load version property file.");
344-
if (Logging.isVerbose()) {
360+
if (LOG.isInfoEnabled()) {
345361
e.printStackTrace();
346362
}
347363

src/main/java/com/spectralogic/ds3cli/Main.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515

1616
package com.spectralogic.ds3cli;
1717

18-
import com.spectralogic.ds3cli.logging.Logging;
1918
import com.spectralogic.ds3cli.util.Ds3Provider;
2019
import com.spectralogic.ds3cli.util.FileUtils;
2120
import com.spectralogic.ds3client.Ds3Client;
2221
import com.spectralogic.ds3client.Ds3ClientBuilder;
2322
import com.spectralogic.ds3client.helpers.Ds3ClientHelpers;
2423
import com.spectralogic.ds3client.models.Credentials;
2524
import com.spectralogic.ds3client.networking.FailedRequestException;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2627

2728
public class Main {
2829

30+
private final static Logger LOG = LoggerFactory.getLogger(Main.class);
31+
2932
public static void main(final String[] args) {
3033
try {
3134
final Arguments arguments = new Arguments(args);
@@ -38,11 +41,11 @@ public static void main(final String[] args) {
3841
System.exit(response.getReturnCode());
3942
} catch (final Exception e) {
4043
System.out.println("ERROR: " + e.getMessage());
41-
if (Logging.isVerbose()) {
44+
if (LOG.isInfoEnabled()) {
4245
e.printStackTrace();
4346
if (e instanceof FailedRequestException) {
44-
Logging.log("Printing out the response from the server:");
45-
Logging.log(((FailedRequestException) e).getResponseString());
47+
LOG.info("Printing out the response from the server:");
48+
LOG.info(((FailedRequestException) e).getResponseString());
4649
}
4750
}
4851
System.exit(2);

src/main/java/com/spectralogic/ds3cli/command/DeleteBucket.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.spectralogic.ds3cli.Arguments;
1919
import com.spectralogic.ds3cli.CommandException;
20-
import com.spectralogic.ds3cli.logging.Logging;
2120
import com.spectralogic.ds3cli.models.DeleteResult;
2221
import com.spectralogic.ds3cli.util.Ds3Provider;
2322
import com.spectralogic.ds3cli.util.FileUtils;
@@ -28,12 +27,16 @@
2827
import com.spectralogic.ds3client.models.Contents;
2928
import com.spectralogic.ds3client.utils.SSLSetupException;
3029
import org.apache.commons.cli.MissingOptionException;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3132

3233
import java.io.IOException;
3334
import java.security.SignatureException;
3435

3536
public class DeleteBucket extends CliCommand<DeleteResult> {
36-
37+
38+
private static final Logger LOG = LoggerFactory.getLogger(DeleteBucket.class);
39+
3740
private String bucketName;
3841
private boolean clearBucket;
3942
public DeleteBucket(final Ds3Provider provider, final FileUtils fileUtils) {
@@ -74,7 +77,7 @@ private String deleteBucket() throws SignatureException, SSLSetupException, Comm
7477
private String clearObjects() throws SignatureException, SSLSetupException, CommandException {
7578
// TODO when the multi object delete command has been added to DS3
7679
// Get the list of objects from the bucket
77-
Logging.log("Deleting objects in bucket first");
80+
LOG.debug("Deleting objects in bucket first");
7881
final Ds3Client client = getClient();
7982
final Ds3ClientHelpers helper = Ds3ClientHelpers.wrap(client);
8083

@@ -83,7 +86,7 @@ private String clearObjects() throws SignatureException, SSLSetupException, Comm
8386
for (final Contents content : fileList) {
8487
client.deleteObject(new DeleteObjectRequest(bucketName, content.getKey()));
8588
}
86-
Logging.log("Deleting bucket");
89+
LOG.debug("Deleting bucket");
8790
getClient().deleteBucket(new DeleteBucketRequest(bucketName));
8891

8992
} catch (final IOException e) {

src/main/java/com/spectralogic/ds3cli/command/GetBulk.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
import com.google.common.base.Function;
1919
import com.google.common.collect.Iterables;
2020
import com.spectralogic.ds3cli.Arguments;
21-
import com.spectralogic.ds3cli.logging.Logging;
2221
import com.spectralogic.ds3cli.models.GetBulkResult;
2322
import com.spectralogic.ds3cli.util.Ds3Provider;
2423
import com.spectralogic.ds3cli.util.FileUtils;
25-
import com.spectralogic.ds3client.Ds3Client;
2624
import com.spectralogic.ds3client.helpers.Ds3ClientHelpers;
2725
import com.spectralogic.ds3client.helpers.FileObjectGetter;
2826
import com.spectralogic.ds3client.helpers.options.ReadJobOptions;
@@ -32,6 +30,8 @@
3230
import com.spectralogic.ds3client.serializer.XmlProcessingException;
3331
import com.spectralogic.ds3client.utils.SSLSetupException;
3432
import org.apache.commons.cli.MissingOptionException;
33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
3535

3636
import java.io.IOException;
3737
import java.nio.channels.SeekableByteChannel;
@@ -40,6 +40,9 @@
4040
import java.security.SignatureException;
4141

4242
public class GetBulk extends CliCommand<GetBulkResult> {
43+
44+
private final static Logger LOG = LoggerFactory.getLogger(GetBulk.class);
45+
4346
private String bucketName;
4447
private Path outputPath;
4548
private String prefix;
@@ -89,11 +92,11 @@ public GetBulkResult call() throws Exception {
8992
}
9093

9194
if (this.prefix == null) {
92-
Logging.log("Getting all objects from " + this.bucketName);
95+
LOG.info("Getting all objects from " + this.bucketName);
9396
return new GetBulkResult(restoreAll(getter));
9497
}
9598
else {
96-
Logging.log("Getting only those objects that start with " + this.prefix);
99+
LOG.info("Getting only those objects that start with " + this.prefix);
97100
return new GetBulkResult(restoreSome(getter));
98101
}
99102
}
@@ -139,7 +142,7 @@ public LoggingFileObjectGetter(final Ds3ClientHelpers.ObjectChannelBuilder gette
139142

140143
@Override
141144
public SeekableByteChannel buildChannel(final String s) throws IOException {
142-
Logging.logf("Getting object %s", s);
145+
LOG.info("Getting object %s", s);
143146
return this.objectGetter.buildChannel(s);
144147
}
145148
}

src/main/java/com/spectralogic/ds3cli/command/GetObject.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.common.collect.Lists;
1919
import com.spectralogic.ds3cli.Arguments;
2020
import com.spectralogic.ds3cli.CommandException;
21-
import com.spectralogic.ds3cli.logging.Logging;
2221
import com.spectralogic.ds3cli.models.GetObjectResult;
2322
import com.spectralogic.ds3cli.util.Ds3Provider;
2423
import com.spectralogic.ds3cli.util.FileUtils;
@@ -28,12 +27,15 @@
2827
import com.spectralogic.ds3client.models.bulk.Ds3Object;
2928
import com.spectralogic.ds3client.networking.FailedRequestException;
3029
import org.apache.commons.cli.MissingOptionException;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3132

3233
import java.nio.file.*;
3334
import java.util.List;
3435

3536
public class GetObject extends CliCommand<GetObjectResult> {
3637

38+
private Logger LOG = LoggerFactory.getLogger(GetObject.class);
3739
private String bucketName;
3840
private String objectName;
3941
private String prefix;
@@ -67,7 +69,7 @@ public CliCommand init(final Arguments args) throws Exception {
6769
public GetObjectResult call() throws Exception {
6870
try {
6971
final Path filePath = Paths.get(prefix, objectName);
70-
Logging.log("Output path: " + filePath.toString());
72+
LOG.info("Output path: " + filePath.toString());
7173

7274
getFileUtils().createDirectories(filePath.getParent());
7375

@@ -82,20 +84,20 @@ public GetObjectResult call() throws Exception {
8284
}
8385
catch(final FailedRequestException e) {
8486
if(e.getStatusCode() == 500) {
85-
Logging.log(e.getMessage());
86-
if (Logging.isVerbose()) {
87+
LOG.info(e.getMessage());
88+
if (LOG.isInfoEnabled()) {
8789
e.printStackTrace();
8890
}
8991
throw new CommandException( "Error: Cannot communicate with the remote DS3 appliance.", e);
9092
}
9193
else if(e.getStatusCode() == 404) {
92-
if (Logging.isVerbose()) {
94+
if (LOG.isInfoEnabled()) {
9395
e.printStackTrace();
9496
}
9597
throw new CommandException( "Error: " + e.getMessage(), e);
9698
}
9799
else {
98-
if (Logging.isVerbose()) {
100+
if (LOG.isInfoEnabled()) {
99101
e.printStackTrace();
100102
}
101103
throw new CommandException( "Error: Encountered an unknown error of ("+ e.getStatusCode() +") while accessing the remote DS3 appliance.", e);

src/main/java/com/spectralogic/ds3cli/command/PutBucket.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@
1717

1818
import com.spectralogic.ds3cli.Arguments;
1919
import com.spectralogic.ds3cli.CommandException;
20-
import com.spectralogic.ds3cli.logging.Logging;
2120
import com.spectralogic.ds3cli.models.PutBucketResult;
2221
import com.spectralogic.ds3cli.util.Ds3Provider;
2322
import com.spectralogic.ds3cli.util.FileUtils;
24-
import com.spectralogic.ds3client.Ds3Client;
2523
import com.spectralogic.ds3client.commands.PutBucketRequest;
2624
import com.spectralogic.ds3client.models.bulk.Priority;
2725
import com.spectralogic.ds3client.models.bulk.WriteOptimization;
2826
import com.spectralogic.ds3client.networking.FailedRequestException;
2927
import org.apache.commons.cli.MissingOptionException;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
3030

3131
import java.io.IOException;
3232

3333
public class PutBucket extends CliCommand<PutBucketResult> {
3434

35+
private static final Logger LOG = LoggerFactory.getLogger(PutBucket.class);
36+
3537
private String bucketName;
3638
private Priority defaultPutPriority;
3739
private Priority defaultGetPriority;
@@ -61,15 +63,15 @@ public PutBucketResult call() throws Exception {
6163
final PutBucketRequest request = new PutBucketRequest(bucketName);
6264

6365
if (this.defaultGetPriority != null) {
64-
Logging.logf("Adding a default get priority (%s) to the create bucket", this.defaultGetPriority.toString());
66+
LOG.info("Adding a default get priority (" + this.defaultGetPriority.toString() + ") to the create bucket");
6567
request.withDefaultGetJobPriority(defaultGetPriority);
6668
}
6769
if (this.defaultPutPriority != null) {
68-
Logging.logf("Adding a default put priority (%s) to the create bucket", this.defaultPutPriority.toString());
70+
LOG.info("Adding a default put priority (" + this.defaultPutPriority.toString() + ") to the create bucket");
6971
request.withDefaultPutJobPriority(defaultPutPriority);
7072
}
7173
if (this.defaultWriteOptimization != null) {
72-
Logging.logf("Adding a default write optimization (%s) to the create bucket", this.defaultWriteOptimization.toString());
74+
LOG.info("Adding a default write optimization (" + this.defaultWriteOptimization.toString() + ") to the create bucket");
7375
request.withDefaultWriteOptimization(defaultWriteOptimization);
7476
}
7577

0 commit comments

Comments
 (0)