@@ -89,6 +89,28 @@ func GetDefaultConfig() GoLogConfig {
8989 return config
9090}
9191
92+ //GoLogOptions provides logging parameters for individual logging statements
93+ type GoLogOptions struct {
94+ // The Log priority for this event
95+ Priority LogPriority
96+ }
97+
98+ //GetDefaultLogOptions returns the default GoLogOptions with default values
99+ //for the fields
100+ func GetDefaultLogOptions () GoLogOptions {
101+ o := GoLogOptions {Priority : INFO }
102+ return o
103+ }
104+
105+ //SetPriority returns a new GoLogOptions object with its priority field
106+ //set to Priority. Follows the builder pattern.
107+ // Priority : (GoLogPriority) The Priority that the new GoLogOptions object must have
108+ func (o * GoLogOptions ) SetPriority (Priority LogPriority ) GoLogOptions {
109+ opts := * o
110+ opts .Priority = Priority
111+ return opts
112+ }
113+
92114//VClockPayload is the data structure that is actually end on the wire
93115type VClockPayload struct {
94116 Pid string
@@ -450,32 +472,26 @@ func (gv *GoLog) tickClock() {
450472 gv .currentVC .Tick (gv .pid )
451473}
452474
453- //LogLocalEvent Increments current vector timestamp and logs it into
454- //Log File. * LogMessage (string) : Message to be logged
455- func (gv * GoLog ) LogLocalEvent (Message string ) (logSuccess bool ) {
456- return gv .LogLocalEventWithPriority (Message , gv .priority )
457- }
458-
459475//LogLocalEventWithPriority implements LogLocalEvent with priority
460476//levels. If the priority of the logger is lower than or equal to the
461477//priority of this event then the current vector timestamp is
462478//incremented and the message is logged it into the Log File. A color
463479//coded string is also printed on the console.
464480//* LogMessage (string) : Message to be logged
465481//* Priority (LogPriority) : Priority at which the message is to be logged
466- func (gv * GoLog ) LogLocalEventWithPriority (LogMessage string , Priority LogPriority ) (logSuccess bool ) {
482+ func (gv * GoLog ) LogLocalEvent (LogMessage string , opts GoLogOptions ) (logSuccess bool ) {
467483 logSuccess = true
468484 gv .mutex .Lock ()
469- if Priority >= gv .priority {
470- prefix := prefixLookup [Priority ]
485+ if opts . Priority >= gv .priority {
486+ prefix := prefixLookup [opts . Priority ]
471487 gv .tickClock ()
472- logSuccess = gv .logWriteWrapper (prefix + LogMessage , "Something went Wrong, Could not Log LocalEvent!" , Priority )
488+ logSuccess = gv .logWriteWrapper (prefix + LogMessage , "Something went Wrong, Could not Log LocalEvent!" , opts . Priority )
473489 }
474490 gv .mutex .Unlock ()
475491 return
476492}
477493
478- //PrepareSendWithPriority is meant to be used immediately before sending.
494+ //PrepareSend is meant to be used immediately before sending.
479495//LogMessage will be logged along with the time of the send
480496//buf is encode-able data (structure or basic type)
481497//Returned is an encoded byte array with logging information.
@@ -484,14 +500,14 @@ func (gv *GoLog) LogLocalEventWithPriority(LogMessage string, Priority LogPriori
484500//it should Update the Vector Clock for its own process, package with
485501//the clock using gob support and return the new byte array that should
486502//be sent onwards using the Send Command
487- func (gv * GoLog ) PrepareSendWithPriority (mesg string , buf interface {}, Priority LogPriority ) (encodedBytes []byte ) {
503+ func (gv * GoLog ) PrepareSend (mesg string , buf interface {}, opts GoLogOptions ) (encodedBytes []byte ) {
488504
489505 //Converting Vector Clock from Bytes and Updating the gv clock
490506 gv .mutex .Lock ()
491- if Priority >= gv .priority {
507+ if opts . Priority >= gv .priority {
492508 gv .tickClock ()
493509
494- gv .logWriteWrapper (mesg , "Something went wrong, could not log prepare send" , Priority )
510+ gv .logWriteWrapper (mesg , "Something went wrong, could not log prepare send" , opts . Priority )
495511
496512 d := VClockPayload {Pid : gv .pid , VcMap : gv .currentVC .GetMap (), Payload : buf }
497513
@@ -508,19 +524,6 @@ func (gv *GoLog) PrepareSendWithPriority(mesg string, buf interface{}, Priority
508524 return
509525}
510526
511- //PrepareSend is meant to be used immediately before sending.
512- //LogMessage will be logged along with the time of the send
513- //buf is encode-able data (structure or basic type)
514- //Returned is an encoded byte array with logging information.
515- //
516- //This function is meant to be called before sending a packet. Usually,
517- //it should Update the Vector Clock for its own process, package with
518- //the clock using gob support and return the new byte array that should
519- //be sent onwards using the Send Command
520- func (gv * GoLog ) PrepareSend (mesg string , buf interface {}) []byte {
521- return gv .PrepareSendWithPriority (mesg , buf , gv .priority )
522- }
523-
524527func (gv * GoLog ) mergeIncomingClock (mesg string , e VClockPayload , Priority LogPriority ) {
525528
526529 // First, tick the local clock
@@ -530,19 +533,19 @@ func (gv *GoLog) mergeIncomingClock(mesg string, e VClockPayload, Priority LogPr
530533 gv .logWriteWrapper (mesg , "Something went Wrong, Could not Log!" , Priority )
531534}
532535
533- //UnpackReceiveWithPriority is used to unmarshall network data into local structures.
536+ //UnpackReceive is used to unmarshall network data into local structures.
534537//LogMessage will be logged along with the vector time the receive happened
535538//buf is the network data, previously packaged by PrepareSend unpack is
536539//a pointer to a structure, the same as was packed by PrepareSend
537540//
538541//This function is meant to be called immediately after receiving
539542//a packet. It unpacks the data by the program, the vector clock. It
540543//updates vector clock and logs it. and returns the user data
541- func (gv * GoLog ) UnpackReceiveWithPriority (mesg string , buf []byte , unpack interface {}, Priority LogPriority ) {
544+ func (gv * GoLog ) UnpackReceive (mesg string , buf []byte , unpack interface {}, opts GoLogOptions ) {
542545
543546 gv .mutex .Lock ()
544547
545- if Priority >= gv .priority {
548+ if opts . Priority >= gv .priority {
546549 e := VClockPayload {}
547550 e .Payload = unpack
548551
@@ -553,22 +556,9 @@ func (gv *GoLog) UnpackReceiveWithPriority(mesg string, buf []byte, unpack inter
553556 }
554557
555558 // Increment and merge the incoming clock
556- gv .mergeIncomingClock (mesg , e , Priority )
559+ gv .mergeIncomingClock (mesg , e , opts . Priority )
557560 }
558561 gv .mutex .Unlock ()
559562
560563}
561564
562- /*
563- UnpackReceive is used to unmarshall network data into local structures.
564- LogMessage will be logged along with the vector time the receive happened
565- buf is the network data, previously packaged by PrepareSend unpack is
566- a pointer to a structure, the same as was packed by PrepareSend
567-
568- This function is meant to be called immediately after receiving
569- a packet. It unpacks the data by the program, the vector clock. It
570- updates vector clock and logs it. and returns the user data
571- */
572- func (gv * GoLog ) UnpackReceive (mesg string , buf []byte , unpack interface {}) {
573- gv .UnpackReceiveWithPriority (mesg , buf , unpack , gv .priority )
574- }
0 commit comments