本文整理汇总了Golang中log.Flags函数的典型用法代码示例。如果您正苦于以下问题:Golang Flags函数的具体用法?Golang Flags怎么用?Golang Flags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Flags函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setupLogger
func setupLogger(logDir string) *log.Logger {
var logger *log.Logger
log.SetFlags(log.Ldate | log.Lmicroseconds)
if logDir != "" {
logFile := filepath.Join(logDir, "host.log")
if err := os.MkdirAll(filepath.Dir(logFile), 0755); err != nil {
log.Fatalf("could not not mkdir for logs: %s", err)
}
hostlog, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatal(err)
}
defer hostlog.Close()
log.Printf("Logging to %s\n", logFile)
log.SetOutput(io.MultiWriter(hostlog, os.Stdout))
logger = log.New(io.MultiWriter(hostlog, os.Stderr), "", log.Flags())
} else {
logger = log.New(os.Stderr, "", log.Flags())
}
return logger
}
示例2: 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)
}
示例3: Init
// Init initializes flags and run all functions in initFunc.
func Init() {
log.SetFlags(log.Lshortfile | log.Flags())
flag.Parse()
if !flag.Parsed() {
log.Fatal("Unable to parse flags")
}
logger = log.New(os.Stderr, "", log.Lshortfile|log.Flags())
AssertTrue(logger != nil)
printVersionOnly()
// Next, run all the init functions that have been added.
for _, f := range initFunc {
f()
}
}
示例4: SetAttribPointers
func SetAttribPointers(locations interface{}, vertexData interface{}, instanced bool) {
attribs, _ := LocationMap(locations)
Type := reflect.TypeOf(vertexData).Elem()
stride := int(Type.Size())
for i := 0; i < Type.NumField(); i++ {
structElement := Type.Field(i)
elementType := structElement.Type
var size uint
var typ gl.GLenum
var kind reflect.Kind
switch elementType.Kind() {
case reflect.Array:
size = uint(elementType.Len())
kind = elementType.Elem().Kind()
default:
size = 1
kind = elementType.Kind()
}
switch kind {
case reflect.Float32:
typ = gl.FLOAT
case reflect.Float64:
typ = gl.DOUBLE
default:
panic("not implemented yet")
}
offset := structElement.Offset
Loc := attribs[structElement.Name]
if Loc >= 0 {
Loc.EnableArray()
Loc.AttribPointer(size, typ, false, stride, offset)
if instanced {
Loc.AttribDivisor(1)
}
if log.Flags()&VERTEX_INFO_FLAG != 0 {
log.Printf("%s: Loc: %d, size: %d, type: %d, stride: %d, offset: %d\n", structElement.Name, Loc, size, typ, stride, offset)
}
} else if log.Flags()&VERTEX_INFO_FLAG != 0 {
log.Printf("%s: Loc: %d, !!!\n", structElement.Name, Loc)
}
}
}
示例5: TestTripleDuplicates
func TestTripleDuplicates(t *testing.T) {
t.Parallel()
file, err := ioutil.TempFile(os.TempDir(), "triplestore.db")
if err != nil {
t.Fatal(err)
}
defer os.Remove(file.Name())
db, err := NewTripleStore(file.Name(), log.New(os.Stdout, "", log.Flags()))
if err != nil {
t.Fatal(err)
}
db.Insert(testTriples)
// Insert twice to ensure no duplicates.
db.Insert(testTriples)
info, err := db.Size()
if err != nil {
t.Fatal(err)
}
if info.Triples != uint64(len(testTriples)) {
t.Errorf("Size() = %#v; not %d", info, len(testTriples))
}
}
示例6: main
func main() {
flag.DurationVar(&gBenchDur, "d", time.Millisecond, "duration for bench")
var (
localAddr = flag.String("l", "", "local udp address, eg: ip:port")
serverAddr = flag.String("h", "", "server udp address, eg: ip:port")
concurent = flag.Int("c", 1, "concurent client number")
)
flag.Parse()
log.SetFlags(log.Flags() | log.Lshortfile)
if len(*localAddr) == 0 || len(*serverAddr) == 0 {
flag.Usage()
return
}
server, err := net.ResolveUDPAddr("udp", *serverAddr)
if err != nil {
fmt.Printf("Resolve server addr %s failed: %v\n", *serverAddr, err)
return
}
local, err := net.ResolveUDPAddr("udp", *localAddr)
if err != nil {
fmt.Printf("Resolve local addr %s failed: %v\n", *localAddr, err)
return
}
firstPort := local.Port
// 跳过监听失败的端口
for p, n := 0, 0; n < *concurent; p++ {
local.Port = firstPort + p
socket, err := net.ListenUDP("udp", local)
if err != nil {
fmt.Printf("Listen on local addr %v failed: %v\n", local, err)
continue
}
n++
c := Client{
Name: "deviceName",
ProduceTime: time.Now(),
DeviceType: 0xFFFE,
Sid: make([]byte, 16),
Socket: socket,
ServerAddr: server,
rch: make(chan []byte, 128),
}
binary.LittleEndian.PutUint32(c.SN[11:15], uint32(n))
binary.LittleEndian.PutUint32(c.MAC[3:7], uint32(n))
log.Printf("Client started, mac: %v, sn: %v", hex.EncodeToString(c.MAC[:]), hex.EncodeToString(c.SN[:]))
go c.Run()
}
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
for sig := range c {
switch sig {
case syscall.SIGINT, syscall.SIGTERM:
return
}
}
}
示例7: main
func main() {
var err error
db, err = sql.Open("mysql", "root:[email protected](182.92.69.21:3305)/game_server?charset=utf8")
db.SetMaxOpenConns(50)
db.SetMaxIdleConns(50)
defer db.Close()
err = db.Ping()
if err != nil {
log.Fatal(err)
}
log.SetFlags(log.Flags() | log.Lshortfile)
a.HandleConnect(handleConnect)
a.HandleMessage(handleMessage)
a.HandleDisconnect(handleDisconnect)
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
go a.Start()
go Handle()
go pingHandle()
<-ch
hql.Truncate_server(db)
hql.Truncate_platform(db)
a.Stop(shutdown)
wg.Wait()
}
示例8: main
func main() {
log.SetFlags(log.Flags() | log.Lshortfile)
parsed, err := docopt.Parse(whitespace.CleanWS(`
Usage:
docker_labels [options] <image-name>
Options:
--insecure makes the connection to e.g. a self-signed registry
`), nil, true, "", false)
if err != nil {
log.Fatal(err)
}
imageName := parsed["<image-name>"].(string)
client := docker_registry.NewClient()
if _, ok := parsed["--insecure"]; ok {
client.BecomeFoolishlyTrusting()
}
labels, err := client.LabelsForImageName(imageName)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d labels:\n", len(labels))
for key, value := range labels {
fmt.Printf("%s: %s\n", key, value)
}
}
示例9: main
func main() {
log.SetFlags(log.Flags() | log.Llongfile)
//recv := &chromebus.ChromebusRecordStdinReceiver{}
//str, _ := recv.GetRecord()
//log.Printf("%s", str)
//str, _ = recv.GetRecord()
//log.Printf("%s", str)
flag.Parse()
flag.VisitAll(defFlags)
if !serverMode {
chromebus.EnvSetup()
}
var e *chromebus.Engine
if pluginsDefined {
e = chromebus.CreateEngine(plugins, port)
} else {
e = chromebus.CreateEngine(nil, port)
}
go func() {
e.Start()
}()
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt, os.Kill)
<-signalChannel
e.CleanUp()
//rcv := ChromebusRecordStdinReceiver{}
//exec.Command("date")
}
示例10: main
func main() {
r := Rectangle{length: 5, width: 3}
fmt.Println("Rectangle r details are: ", r)
fmt.Println("Rectangle r's area is: ", r.Area())
s := Shaper(r)
fmt.Println("Area of the Shape r is: ", s.Area())
fmt.Println("Area of the Shape r is: ", s.Shit())
return
cfgFile := "file.txt"
f, err := os.OpenFile(cfgFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666) // For read access.
if err != nil {
checkError(err)
}
// var l int
myLog := log.New(f, "PREFIXIO ", log.Lshortfile|log.Ldate|log.Ltime)
// l, err = f.WriteString("HELLO THERE n");
// fmt.Printf("length is :%d\n", l);
if err != nil {
checkError2(err)
}
myLog.Println("from logger")
//myFileAppendLine(cfgFile, "HELLO THERE \n");
fmt.Printf("Flags:%q Prefix:%q\n", log.Flags(), log.Prefix())
os.Exit(0)
}
示例11: init
func init() {
log.SetFlags(log.Flags() | log.Lshortfile)
bytes, err := ioutil.ReadFile("config.conf")
e(err, true)
str := string(bytes)
lines := strings.Split(str, "\n")
reg, err := regexp.Compile(`\s+`)
e(err, true)
for num, line := range lines {
if line == "" {
continue
}
if strings.HasPrefix(line, "#") {
continue
}
fields := reg.Split(line, -1)
if len(fields) != 2 {
log.Printf("Line %d is not match the config format.", num+1)
continue
}
dbname := fields[0]
dburi := fields[1]
DBS[dbname] = dburi
dbs[dbname] = init_db(dburi)
}
}
示例12: main
// Setup registers all server handlers.
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
log.SetFlags(log.Flags() | log.Lshortfile)
flag.Parse()
s, err := newServer()
if err != nil {
log.Fatal(err)
}
defer s.graph.Close()
fs := http.FileServer(http.Dir("."))
http.Handle("/static/", fs)
http.HandleFunc("/", handleIndex)
http.HandleFunc("/api/v1/recommendation", s.handleRecommendation)
log.Printf("Serving on :%s...", *port)
err = http.ListenAndServe("0.0.0.0:"+*port, nil)
if err != nil {
log.Println(err)
}
log.Println("Server on 6060 stopped")
os.Exit(0)
}
示例13: NewServer
// NewServer creates a new server with routing information. If log is nil, stdout is used.
func NewServer(logger *log.Logger, port int) (*Server, error) {
if logger == nil {
logger = log.New(os.Stdout, "", log.Flags())
}
s := &Server{
Logger: logger,
Port: port,
Peers: make(map[string]*Conn),
handlers: make(map[string]protocolHandler),
}
s.listeningWG.Add(1)
s.IP = getHost()
s.listener = &httpListener{
accept: make(chan *httpConn, 10),
}
s.initHTTPRouting()
// Handlers
s.Handle("Handshake", s.handleHandshake)
s.Handle("PeerRequest", s.handlePeerRequest)
s.Handle("PeerNotify", s.handlePeerNotify)
return s, nil
}
示例14: TestModifyScale
func TestModifyScale(t *testing.T) {
log.SetFlags(log.Flags() | log.Lshortfile)
assert := assert.New(t)
mods := make(chan *sous.DeployablePair, 1)
errs := make(chan error, 10)
pair := baseDeployablePair()
pair.Prior.Deployment.DeployConfig.NumInstances = 12
pair.Post.Deployment.DeployConfig.NumInstances = 24
client := sous.NewDummyRectificationClient()
deployer := NewDeployer(client)
mods <- pair
close(mods)
deployer.RectifyModifies(mods, errs)
close(errs)
for e := range errs {
t.Error(e)
}
assert.Len(client.Deployed, 0)
if assert.Len(client.Created, 1) {
assert.Equal(24, client.Created[0].Count)
}
}
示例15: main
func main() {
var dumpConf bool
var confFile string
flag.BoolVar(&dumpConf, "dumpconf", false, "dump the default configuration file")
flag.StringVar(&confFile, "conf", "", "use this alternative configuration file")
flag.Parse()
stdoutLogger = log.New(os.Stderr, "", log.Flags())
if dumpConf {
dumpDefaultConf()
return
}
rand.Seed(time.Now().Unix())
if confFile != "" {
setConf(confFile)
}
if conf.RealIP {
goji.Insert(middleware.RealIP, middleware.Logger)
}
goji.Get("/", root)
goji.Get("/:id", getPaste)
goji.Post("/", createPaste)
goji.Serve()
}