func init() { Logger = log.NewSimple(log.WriterSink(os.Stdout, "%s: %s[%d] %s\n", []string{"priority", "executable", "pid", "message"})) if interfaces, err := net.Interfaces(); err == nil { for _, i := range interfaces { if i.Flags&net.FlagLoopback == 0 && len(i.HardwareAddr) > 0 { hardwareAddr = i.HardwareAddr break } } } if hardwareAddr == nil { // If we failed to obtain the MAC address of the current computer, // we will use a randomly generated 6 byte sequence instead and set // the multicast bit as recommended in RFC 4122. hardwareAddr = make([]byte, 6) _, err := io.ReadFull(rand.Reader, hardwareAddr) if err != nil { panic(err) } hardwareAddr[0] = hardwareAddr[0] | 0x01 } // initialize the clock sequence with a random number var clockSeqRand [2]byte io.ReadFull(rand.Reader, clockSeqRand[:]) clockSeq = uint32(clockSeqRand[1])<<8 | uint32(clockSeqRand[0]) }
func setLogger(priority log.Priority) { logger = log.NewSimple( log.PriorityFilter( priority, log.WriterSink(os.Stdout, log.BasicFormat, log.BasicFields))) }