Skip to content

Commit

Permalink
* Added ConsistencyLevel enum to Timber protobuffer definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
borud committed Nov 1, 2011
1 parent 0d2a986 commit 6ce14f5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions log/src/main/java/org/cloudname/log/Converter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cloudname.log;

import org.cloudname.log.pb.Timber;
import static org.cloudname.log.pb.Timber.ConsistencyLevel;

import com.google.protobuf.ByteString;

Expand Down Expand Up @@ -55,6 +56,7 @@ public Converter(String serviceName) {
public Timber.LogEvent convertFrom(LogRecord rec) {
Timber.LogEvent.Builder eventBuilder = Timber.LogEvent.newBuilder()
.setTimestamp(rec.getMillis())
.setConsistencyLevel(ConsistencyLevel.BESTEFFORT)
.setLevel(rec.getLevel().intValue())
.setHost(hostName)
.setServiceName(serviceName)
Expand Down
2 changes: 2 additions & 0 deletions log/src/main/java/org/cloudname/log/LogUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cloudname.log;

import org.cloudname.log.pb.Timber;
import static org.cloudname.log.pb.Timber.ConsistencyLevel;

import java.net.InetAddress;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -41,6 +42,7 @@ public static Timber.LogEvent textEvent(int level,
{
return Timber.LogEvent.newBuilder()
.setTimestamp(System.currentTimeMillis())
.setConsistencyLevel(ConsistencyLevel.BESTEFFORT)
.setLevel(level)
.setHost(hostName)
.setServiceName(service)
Expand Down
38 changes: 30 additions & 8 deletions log/src/main/protobuf/timber.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
option java_package = "org.cloudname.log.pb";
option optimize_for = SPEED;

// Consistency levels indicating how we want the log message
// to be handled by the logging infrastructure.
enum ConsistencyLevel {
// Best effort. Prioritize speed over consistency.
BESTEFFORT = 0;

// At least guarantee that the log message is synced to local disk
// before returning from calls or assuming responsibility for the
// log message.
SYNC = 1;

// Require that the log message is not only persisted locally, but
// also replicated so it exists in more than one place.
REPLICATED = 2;
}

// This message represents the envelope of a log message. These are
// the only fields that the core log server framework should deal with
// minus the payload. In the interest of simplicity and performance
Expand All @@ -15,35 +31,41 @@ option optimize_for = SPEED;
message LogEvent {
// Timestamp is in milliseconds since epoch
required int64 timestamp = 1;

// The required consistency level of the log message
required ConsistencyLevel consistencyLevel = 2 [default = BESTEFFORT];

// The level of this event.
required int32 level = 2;
required int32 level = 3;

// Hostname of the machine where the log event originated.
required string host = 3;
required string host = 4;

// The name of the service or the application that emitted the
// event. If used in conjunction with cloudname this is where
// we put the primary service coordinate.
required string service_name = 4;
required string service_name = 5;

// For Java programs the class and method where the log event
// originated.
required string source = 5;
required string source = 6;

// The type of log event.
required string type = 6;
required string type = 7;

// Zero or more payloads associated with this log event.
repeated Payload payload = 7;
repeated Payload payload = 8;

// The process id of the originating program. If unknown this
// defaults to zero.
optional int32 pid = 8 [default = 0];
optional int32 pid = 9 [default = 0];

// The thread id of the originating program. If unknown this
// defaults to zero.
optional int32 tid = 9 [default = 0];
optional int32 tid = 10 [default = 0];

// Optional id of log message
optional string id = 11;
}

// This message represents the payload of a log message.
Expand Down
2 changes: 2 additions & 0 deletions log/src/test/java/org/cloudname/log/archiver/SlotTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cloudname.log.archiver;

import org.cloudname.log.pb.Timber;
import static org.cloudname.log.pb.Timber.ConsistencyLevel;
import org.cloudname.log.recordstore.RecordReader;

import com.google.protobuf.ByteString;
Expand Down Expand Up @@ -31,6 +32,7 @@ private Timber.LogEvent makeLogEvent(long time)
{
return Timber.LogEvent.newBuilder()
.setTimestamp(time)
.setConsistencyLevel(ConsistencyLevel.BESTEFFORT)
.setLevel(1)
.setHost("example.com")
.setServiceName("myservice")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.cloudname.log.recordstore;

import org.cloudname.log.pb.Timber;
import static org.cloudname.log.pb.Timber.ConsistencyLevel;

import com.google.protobuf.ByteString;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
Expand All @@ -24,6 +26,7 @@ public class RecordWriterTest {
public static Timber.LogEvent createMessage(String message) {
return Timber.LogEvent.newBuilder()
.setTimestamp(1000000)
.setConsistencyLevel(ConsistencyLevel.BESTEFFORT)
.setLevel(1)
.setHost("example.com")
.setServiceName("myservice")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cloudname.timber.server;

import org.cloudname.log.pb.Timber;
import static org.cloudname.log.pb.Timber.ConsistencyLevel;

import org.cloudname.timber.server.handler.LogEventHandler;
import org.cloudname.timber.server.handler.LogEventHandlerException;
Expand Down Expand Up @@ -46,6 +47,7 @@ public void handle(Timber.LogEvent logEvent)
public static Timber.LogEvent createMessage(String message) {
return Timber.LogEvent.newBuilder()
.setTimestamp(System.currentTimeMillis())
.setConsistencyLevel(ConsistencyLevel.BESTEFFORT)
.setLevel(1)
.setHost("example.com")
.setServiceName("myservice")
Expand Down

0 comments on commit 6ce14f5

Please sign in to comment.