Skip to content

Commit

Permalink
Fixed code styles warns related to the couchbase appender.
Browse files Browse the repository at this point in the history
  • Loading branch information
Acarus committed Oct 6, 2016
1 parent fb3de14 commit cfc3a0e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Expand Up @@ -40,6 +40,13 @@ public CouchbaseLogAppender() {
super(CouchbaseConfig.class); super(CouchbaseConfig.class);
} }


/**
* Saves logs into a couchbase database.
*
* @param logEventPack logs
* @param header header
* @param listener log delivery listener
*/
@Override @Override
public void doAppend(LogEventPack logEventPack, RecordHeader header, LogDeliveryCallback listener) { public void doAppend(LogEventPack logEventPack, RecordHeader header, LogDeliveryCallback listener) {
if (!closed) { if (!closed) {
Expand All @@ -52,8 +59,8 @@ public void doAppend(LogEventPack logEventPack, RecordHeader header, LogDelivery
LOG.debug("[{}] appended {} logs to couchbase bucket", getApplicationToken(), logEventPack.getEvents().size()); LOG.debug("[{}] appended {} logs to couchbase bucket", getApplicationToken(), logEventPack.getEvents().size());
} }
listener.onSuccess(); listener.onSuccess();
} catch (Exception e) { } catch (Exception ex) {
LOG.error(MessageFormat.format("[{0}] Attempted to append logs failed due to internal error", getName()), e); LOG.error(MessageFormat.format("[{0}] Attempted to append logs failed due to internal error", getName()), ex);
listener.onInternalError(); listener.onInternalError();
} }
} else { } else {
Expand All @@ -67,8 +74,8 @@ protected void initFromConfiguration(LogAppenderDto appender, CouchbaseConfig co
LOG.debug("Initializing new instance of Couchbase log appender"); LOG.debug("Initializing new instance of Couchbase log appender");
try { try {
logEventDao = new LogEventCouchbaseDao(configuration); logEventDao = new LogEventCouchbaseDao(configuration);
} catch (Exception e) { } catch (Exception ex) {
LOG.error("Failed to init Couchbase log appender: ", e); LOG.error("Failed to init Couchbase log appender: ", ex);
} }
} }


Expand Down
Expand Up @@ -44,6 +44,9 @@ public final class LogEvent implements Serializable {
public LogEvent() { public LogEvent() {
} }


/**
* All-args constructor.
*/
public LogEvent(RecordHeader header, LogEventDto dto) { public LogEvent(RecordHeader header, LogEventDto dto) {
this.id = dto.getId(); this.id = dto.getId();
this.header = header; this.header = header;
Expand Down
Expand Up @@ -37,11 +37,14 @@ public class LogEventCouchbaseDao implements LogEventDao {


private static final Logger LOG = LoggerFactory.getLogger(LogEventCouchbaseDao.class); private static final Logger LOG = LoggerFactory.getLogger(LogEventCouchbaseDao.class);


private final Random RANDOM = new Random(); private final Random random = new Random();


private CouchbaseClient couchbaseClient; private CouchbaseClient couchbaseClient;
private CouchbaseTemplate couchbaseTemplate; private CouchbaseTemplate couchbaseTemplate;


/**
* Instantiates the LogEventCouchbaseDao.
*/
public LogEventCouchbaseDao(CouchbaseConfig configuration) throws Exception { public LogEventCouchbaseDao(CouchbaseConfig configuration) throws Exception {


List<CouchbaseServerUri> couchbaseUris = configuration.getCouchbaseServerUris(); List<CouchbaseServerUri> couchbaseUris = configuration.getCouchbaseServerUris();
Expand Down Expand Up @@ -81,7 +84,7 @@ public void close() {


private String getId(String id) { private String getId(String id) {
if (id == null || id.length() == 0) { if (id == null || id.length() == 0) {
id = new UUID(System.currentTimeMillis(), RANDOM.nextLong()).toString(); id = new UUID(System.currentTimeMillis(), random.nextLong()).toString();
} }
return id; return id;
} }
Expand Down

0 comments on commit cfc3a0e

Please sign in to comment.