本文整理汇总了Golang中log.SetFlags函数的典型用法代码示例。如果您正苦于以下问题:Golang SetFlags函数的具体用法?Golang SetFlags怎么用?Golang SetFlags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetFlags函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleStatusUpdate
func handleStatusUpdate(displaycount int) {
elapsed := float64(UnixNow() - start)
// print status bar
log.Printf("\n")
log.SetFlags(log.Ldate | log.Ltime)
log.Printf("%d total queries, %0.2f per second", querycount, float64(querycount)/elapsed)
log.SetFlags(0)
// we cheat so badly here...
var tmp sort.StringSlice = make([]string, 0, len(qbuf))
for q, c := range qbuf {
tmp = append(tmp, fmt.Sprintf("%6d %0.2f/s %s", c, float64(c)/elapsed, q))
}
sort.Sort(tmp)
// now print top to bottom, since our sorted list is sorted backwards
// from what we want
if len(tmp) < displaycount {
displaycount = len(tmp)
}
for i := 1; i <= displaycount; i++ {
log.Printf(tmp[len(tmp)-i])
}
}
示例2: main
func main() {
var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)")
var showTime = flag.Bool("t", false, "Display timestamps")
log.SetFlags(0)
flag.Usage = usage
flag.Parse()
args := flag.Args()
if len(args) < 2 {
usage()
}
nc, err := nats.Connect(*urls)
if err != nil {
log.Fatalf("Can't connect: %v\n", err)
}
subj, reply, i := args[0], args[1], 0
nc.Subscribe(subj, func(msg *nats.Msg) {
i++
printMsg(msg, i)
nc.Publish(msg.Reply, []byte(reply))
})
log.Printf("Listening on [%s]\n", subj)
if *showTime {
log.SetFlags(log.LstdFlags)
}
runtime.Goexit()
}
示例3: handleStatusUpdate
func handleStatusUpdate(displaycount int, sortby string, cutoff int) {
elapsed := float64(UnixNow() - start)
// print status bar
log.Printf("\n")
log.SetFlags(log.Ldate | log.Ltime)
log.Printf("%s%d total queries, %0.2f per second%s", COLOR_RED, querycount,
float64(querycount)/elapsed, COLOR_DEFAULT)
log.SetFlags(0)
log.Printf("%d packets (%0.2f%% on synchronized streams) / %d desyncs / %d streams",
stats.packets.rcvd, float64(stats.packets.rcvd_sync)/float64(stats.packets.rcvd)*100,
stats.desyncs, stats.streams)
// global timing values
gmin, gavg, gmax := calculateTimes(×)
log.Printf("%0.2fms min / %0.2fms avg / %0.2fms max query times", gmin, gavg, gmax)
log.Printf("%d unique results in this filter", len(qbuf))
log.Printf(" ")
log.Printf("%s count %sqps %s min avg max %sbytes per qry%s",
COLOR_YELLOW, COLOR_CYAN, COLOR_YELLOW, COLOR_GREEN, COLOR_DEFAULT)
// we cheat so badly here...
var tmp sortableSlice = make(sortableSlice, 0, len(qbuf))
for q, c := range qbuf {
qps := float64(c.count) / elapsed
if qps < float64(cutoff) {
continue
}
qmin, qavg, qmax := calculateTimes(&c.times)
bavg := uint64(float64(c.bytes) / float64(c.count))
sorted := float64(c.count)
if sortby == "avg" {
sorted = qavg
} else if sortby == "max" {
sorted = qmax
} else if sortby == "maxbytes" {
sorted = float64(c.bytes)
} else if sortby == "avgbytes" {
sorted = float64(bavg)
}
tmp = append(tmp, sortable{sorted, fmt.Sprintf(
"%s%6d %s%7.2f/s %s%6.2f %6.2f %6.2f %s%9db %6db %s%s%s",
COLOR_YELLOW, c.count, COLOR_CYAN, qps, COLOR_YELLOW, qmin, qavg, qmax,
COLOR_GREEN, c.bytes, bavg, COLOR_WHITE, q, COLOR_DEFAULT)})
}
sort.Sort(tmp)
// now print top to bottom, since our sorted list is sorted backwards
// from what we want
if len(tmp) < displaycount {
displaycount = len(tmp)
}
for i := 1; i <= displaycount; i++ {
log.Printf(tmp[len(tmp)-i].line)
}
}
示例4: init
func init() {
if os.Getenv("DEBUG") == "true" {
log.SetFlags(log.Llongfile)
} else {
log.SetFlags(0)
}
}
示例5: main
func main() {
log.SetFlags(0)
flag.Parse()
if version {
fmt.Println(VERSION)
os.Exit(0)
}
rand.Seed(time.Now().UnixNano())
log.SetFlags(log.LstdFlags)
log.Printf("Docker Hive %s\n", VERSION)
// connect to redis
pool := utils.NewRedisPool(redisHost, redisPort, redisPass)
// set node name
if nodeName == "" {
name, err := os.Hostname()
if err != nil {
log.Printf("Error getting hostname: %s", err)
nodeName = "localhost"
}
nodeName = name
}
// start node
engine := hive.NewEngine(host, port, dockerPath, VERSION, nodeName, zone, pool, runPolicy)
waiter, err := engine.Start()
if err != nil {
log.Fatal(err)
return
}
waiter.Wait()
}
示例6: main
func main() {
var urls = flag.String("nats", nats.DefaultURL, "The nats server URLs (separated by comma)")
var mgoDB = flag.String("db", "localhost:27017", "Mongo databast URL")
var showTime = flag.Bool("t", false, "Display timestamps")
log.SetFlags(0)
flag.Usage = usage
flag.Parse()
args := flag.Args()
if len(args) < 1 {
usage()
fmt.Println("mgoDB", mgoDB)
}
opts := nats.DefaultOptions
opts.Servers = strings.Split(*urls, ",")
for i, s := range opts.Servers {
opts.Servers[i] = strings.Trim(s, " ")
}
nc, err := opts.Connect()
if err != nil {
log.Fatalf("Can't connect: %v\n", err)
}
subj, i := args[0], 0
nc.Subscribe(subj, func(msg *nats.Msg) {
// ok we need to write this to a mgo database and assume that it's mostly valid ;)
// we will use the last part of the subj as the collection and the first part as the db.
// First we convert the Msg into a json obj.
// then we dump the json into Bson and into mongo.
var jsonObj map[string]interface{}
err := json.Unmarshal([]byte(msg.Data), &jsonObj)
if err != nil {
// Bad json.
log.Fatalf("Bad json passed: (%s)\n", msg.Data)
}
// ok let's split the msg subject and use part 1 for db and part 2 for collection. throwing away the rest
foo := strings.Split(subj, ".")
// Create mgo session
session, err := mgo.Dial(*mgoDB)
c := session.Copy().DB(foo[0]).C(foo[1]) // Add the mongo db stuff
c.Insert(jsonObj)
printMsg(msg, i)
})
log.Printf("Listening on [%s]\n", subj)
if *showTime {
log.SetFlags(log.LstdFlags)
}
runtime.Goexit()
}
示例7: main
func main() {
log.SetFlags(0)
flag.Parse()
path := flag.Arg(0)
if path == "" {
log.Fatal("usage: copy-bench PATH")
}
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
runtime.GOMAXPROCS(2)
// Check if this is a new data file.
_, err := os.Stat(path)
isNew := os.IsNotExist(err)
// Open database.
db, err := bolt.Open(path, 0600)
if err != nil {
log.Fatal(err)
}
// Populate the initial database.
if isNew {
if err := seed(db); err != nil {
log.Fatal(err)
}
}
// Print stats of the db.
if err := stat(db); err != nil {
log.Fatal(err)
}
// Iterate once to push pages into memory.
c := make(chan bool)
fmt.Println("first run (ignore)")
go func() { iterate(db, c) }()
c <- true
fmt.Println("")
// Time iteration without copy.
fmt.Println("iterate only")
go iterate(db, c)
time.Sleep(2 * time.Second)
c <- true
fmt.Println("")
// Start iterator thread.
fmt.Println("iterate during copy")
go iterate(db, c)
// Begin copy of the database.
if err := dbcopy(db); err != nil {
log.Fatal(err)
}
// Notify iterator of db copy completion.
c <- true
time.Sleep(100 * time.Millisecond)
}
示例8: main
func main() {
log.SetFlags(0)
var (
addr = flag.String("addr", ":9000", "bind address")
)
flag.Parse()
// Validate parameters.
var path = flag.Arg(0)
if path == "" {
log.Fatal("path required")
}
// Open the database.
db, err := bolt.Open(path, 0600, nil)
if err != nil {
log.Fatal(err)
}
// Enable logging.
log.SetFlags(log.LstdFlags)
// Setup the HTTP handlers.
http.Handle("/", boltd.NewHandler(db))
// Start the HTTP server.
go func() { log.Fatal(http.ListenAndServe(*addr, nil)) }()
fmt.Printf("Listening on http://localhost%s\n", *addr)
select {}
}
示例9: main
func main() {
log.SetFlags(0)
flag.Parse()
if verbose {
log.Print("Verbose logging enabled.")
}
if trace {
raft.SetLogLevel(raft.Trace)
log.Print("Raft trace debugging enabled.")
} else if debug {
raft.SetLogLevel(raft.Debug)
log.Print("Raft debugging enabled.")
}
rand.Seed(time.Now().UnixNano())
// Setup commands.
raft.RegisterCommand(&command.WriteCommand{})
// Set the data directory.
if flag.NArg() == 0 {
log.Fatal("Data path argument required")
}
path := flag.Arg(0)
if err := os.MkdirAll(path, 0744); err != nil {
log.Fatalf("Unable to create path: %v", err)
}
log.SetFlags(log.LstdFlags)
s := server.New(path, host, port)
log.Fatal(s.ListenAndServe(join))
}
示例10: setSystemLogger
func setSystemLogger(name string, w io.Writer) {
log.SetOutput(w)
if name != "" {
log.SetPrefix(name + " ")
log.SetFlags(log.LstdFlags)
} else {
log.SetFlags(log.LstdFlags &^ (log.Ldate | log.Ltime))
}
}
示例11: WarnErr
func WarnErr(err error, msg ...interface{}) error {
if err != nil {
f := log.Flags()
log.SetFlags(0)
log.Println(makeErr(err, msg...))
log.SetFlags(f)
}
return err
}
示例12: logMsg
func logMsg(format, msg string, a ...interface{}) {
defer log.SetFlags(log.Flags())
defer log.SetPrefix(log.Prefix())
log.SetFlags(0)
log.SetPrefix("")
msg = fmt.Sprintf(format+"\n", msg)
log.Printf(msg, a...)
}
示例13: setupLogging
func setupLogging(env Env) {
log.SetFlags(0)
log.SetPrefix("")
if val, ok := env[DIRENV_DEBUG]; ok == true && val == "1" {
debugging = true
log.SetFlags(log.Ltime)
log.SetPrefix("direnv: ")
}
}
示例14: log_debug
func log_debug(msg string, a ...interface{}) {
if !debugging {
return
}
defer log.SetFlags(log.Flags())
log.SetFlags(log.Flags() | log.Lshortfile)
msg = fmt.Sprintf(msg, a...)
log.Output(2, msg)
}
示例15: InitDebug
func InitDebug() {
if Option.Debug {
log.SetFlags(log.Ltime)
log.SetOutput(os.Stdout)
} else {
log.SetFlags(0)
log.SetOutput(ioutil.Discard)
}
}