@@ -6,53 +6,54 @@ import (
66 "github.com/DistributedClocks/GoVector/govec"
77)
88
9- func ExampleGoLog () {
9+ //Basic example of GoVectors key functions
10+ func ExampleGoLog_basic () {
11+ //Initialize logger with default configuration. This can be done in
12+ //a var block to ensure that GoVector is initialized at boot time.
1013 Logger := govec .InitGoVector ("MyProcess" , "LogFile" , govec .GetDefaultConfig ())
1114
12- //In Sending Process
13-
14- //Prepare a Message
15+ //An example message
1516 messagepayload := []byte ("samplepayload" )
16- finalsend := Logger .PrepareSend ("Sending Message" , messagepayload )
1717
18- //In Receiving Process
18+ //Prior to sending a message, call PrepareSend on the payload to
19+ //encode the payload and append this processes vector clock to the
20+ //payload
21+ encodedVCpayload := Logger .PrepareSend ("Sending Message" , messagepayload )
1922
20- //receive message
21- var incommingMessage []byte
22- Logger .UnpackReceive ("Received Message from server" , finalsend , & incommingMessage )
23- fmt .Printf ("Received Message: %s\n " , incommingMessage )
24- //Can be called at any point
25- Logger .LogLocalEvent ("Example Complete" )
23+ //encodedVCpayload is ready to be written to the network
24+ //ex) conn.Write(encodedVCpayload)
2625
27- // Output: Received Message: samplepayload
28- }
29-
30- func ExampleGoTSLog () {
31- config := govec .GetDefaultConfig ()
32- config .UseTimestamps = true
33- Logger := govec .InitGoVector ("MyProcess" , "LogFile" , config )
34-
35- //In Sending Process
26+ //Receiving Example
27+ //First allocate a buffer to receive a message into. This must be
28+ //the same type as the encoded message. Here incommingMessage and
29+ //messagepayload are the same type []byte.
30+ var incommingMessage []byte
3631
37- //Prepare a Message
38- messagepayload := []byte ("samplepayload" )
39- finalsend := Logger .PrepareSend ("Sending Message" , messagepayload )
40- //In Receiving Process
32+ //Prior to unpacking call a message must be received
33+ //ex) conn.Read(encodedVCPayload)
4134
42- //receive message
43- var incommingMessage [] byte
44- Logger .UnpackReceive ("Received Message from server" , finalsend , & incommingMessage )
35+ //Call UnpackReceive on received messages to update local vector
36+ //clock values, and decode the original message.
37+ Logger .UnpackReceive ("Received Message from server" , encodedVCpayload , & incommingMessage )
4538 fmt .Printf ("Received Message: %s\n " , incommingMessage )
46- //Can be called at any point
39+
40+ //Important local events can be timestamped with vector clocks
41+ //using LogLocalEvent, which also increments the local clock.
4742 Logger .LogLocalEvent ("Example Complete" )
4843
4944 // Output: Received Message: samplepayload
5045}
5146
52- func ExampleGoPriorityLog () {
47+ //Logging with priority trims all events which are lower from the
48+ //specified priority from the log. This functionality is useful for
49+ //isolating behaviour such as recovery protocols, from common
50+ //behaviour like heartbeats.
51+ func ExampleGoLog_priority () {
52+ //Access GoVectors default configureation, and set priority
5353 config := govec .GetDefaultConfig ()
5454 config .Priority = govec .DEBUG
5555 config .PrintOnScreen = true
56+ //Initialize GoVector
5657 Logger := govec .InitGoVector ("MyProcess" , "PrioritisedLogFile" , config )
5758
5859 Logger .LogLocalEventWithPriority ("Debug Priority Event" , govec .DEBUG )
@@ -69,3 +70,29 @@ func ExampleGoPriorityLog() {
6970 //Error Priority Event
7071 //Fatal Priority Event
7172}
73+
74+ //GoVector logs can be used to associate real time events for
75+ //visualization with TSViz
76+ func ExampleGoLog_tSVizCompatable () {
77+ //Access config and set timestamps (realtime) to true
78+ config := govec .GetDefaultConfig ()
79+ config .UseTimestamps = true
80+ //Initalize GoVector
81+ Logger := govec .InitGoVector ("MyProcess" , "LogFile" , config )
82+
83+ //In Sending Process
84+
85+ //Prepare a Message
86+ messagepayload := []byte ("samplepayload" )
87+ finalsend := Logger .PrepareSend ("Sending Message" , messagepayload )
88+ //In Receiving Process
89+
90+ //receive message
91+ var incommingMessage []byte
92+ Logger .UnpackReceive ("Received Message from server" , finalsend , & incommingMessage )
93+ fmt .Printf ("Received Message: %s\n " , incommingMessage )
94+ //Can be called at any point
95+ Logger .LogLocalEvent ("Example Complete" )
96+
97+ // Output: Received Message: samplepayload
98+ }
0 commit comments