本文整理汇总了Golang中github.com/qiniu/log.Println函数的典型用法代码示例。如果您正苦于以下问题:Golang Println函数的具体用法?Golang Println怎么用?Golang Println使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Println函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: wsLog
func (s *Supervisor) wsLog(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
log.Println(name)
proc, ok := s.procMap[name]
if !ok {
log.Println("No such process")
// TODO: raise error here?
return
}
c, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Print("upgrade:", err)
return
}
defer c.Close()
for data := range proc.Output.NewChanString(r.RemoteAddr) {
err := c.WriteMessage(1, []byte(data))
if err != nil {
proc.Output.CloseWriter(r.RemoteAddr)
break
}
}
}
示例2: wsEvents
func (s *Supervisor) wsEvents(w http.ResponseWriter, r *http.Request) {
c, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Print("upgrade:", err)
return
}
defer c.Close()
ch := make(chan string, 0)
s.addStatusChangeListener(ch)
go func() {
_, _ = <-ch // ignore the history messages
for message := range ch {
// Question: type 1 ?
c.WriteMessage(1, []byte(message))
}
// s.eventB.RemoveListener(ch)
}()
for {
mt, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", mt, err)
break
}
log.Printf("recv: %v %s", mt, message)
err = c.WriteMessage(mt, message)
if err != nil {
log.Println("write:", err)
break
}
}
}
示例3: startWorker
func startWorker() {
log.Println("start Worker")
Cronjob.Clear()
Cronjob.AddFunc(Config.Flow.Cron, func() { log.Println(Config.Flow.Cron + ": start DumpFlow()"); go DumpFlow(); })
//Cronjob.AddFunc("@every 1s", func() { fmt.Println("Every 1") })
Cronjob.Start()
//defer Cronjob.Stop()
//Cronjob.Entries()
}
示例4: addOrUpdateProgram
func (s *Supervisor) addOrUpdateProgram(pg Program) error {
// defer s.broadcastEvent(pg.Name + " add or update")
if err := pg.Check(); err != nil {
return err
}
origPg, ok := s.pgMap[pg.Name]
if ok {
if reflect.DeepEqual(origPg, pg) {
return nil
}
s.broadcastEvent(pg.Name + " update")
log.Println("Update:", pg.Name)
origProc := s.procMap[pg.Name]
isRunning := origProc.IsRunning()
go func() {
s.stopAndWait(origProc.Name)
newProc := s.newProcess(pg)
s.procMap[pg.Name] = newProc
s.pgMap[pg.Name] = pg // update origin
if isRunning {
newProc.Operate(StartEvent)
}
}()
} else {
s.names = append(s.names, pg.Name)
s.pgMap[pg.Name] = pg
s.procMap[pg.Name] = s.newProcess(pg)
s.broadcastEvent(pg.Name + " added")
}
return nil
}
示例5: actionConfigTest
func actionConfigTest(c *cli.Context) error {
if _, _, err := newSupervisorHandler(); err != nil {
log.Fatal(err)
}
log.Println("test is successful")
return nil
}
示例6: startCommand
func (p *Process) startCommand() {
// p.Stdout.Reset()
// p.Stderr.Reset()
// p.Output.Reset() // Donot reset because log is still needed.
log.Printf("start cmd(%s): %s", p.Name, p.Command)
p.cmd = p.buildCommand()
p.SetState(Running)
if err := p.cmd.Start(); err != nil {
log.Warnf("program %s start failed: %v", p.Name, err)
p.SetState(Fatal)
return
}
go func() {
errC := GoFunc(p.cmd.Wait)
startTime := time.Now()
select {
case <-errC:
// if p.cmd.Wait() returns, it means program and its sub process all quited. no need to kill again
// func Wait() will only return when program session finishs. (Only Tested on mac)
log.Printf("program(%s) finished, time used %v", p.Name, time.Since(startTime))
if time.Since(startTime) < time.Duration(p.StartSeconds)*time.Second {
if p.retryLeft == p.StartRetries { // If first time quit so fast, just set to fatal
p.SetState(Fatal)
log.Printf("program(%s) exit too quick, status -> fatal", p.Name)
return
}
}
p.waitNextRetry()
case <-p.stopC:
log.Println("recv stop command")
p.stopCommand() // clean up all process
}
}()
}
示例7: DownloadImg
func DownloadImg(url_ string) {
resp, err := http.Get(url_)
if goutils.CheckErr(err) {
return
}
log.Println(resp.Header.Get("Content-Type"))
log.Println(resp.ContentLength)
_ = resp
b, err := ioutil.ReadAll(resp.Body)
if goutils.CheckErr(err) {
return
}
// log.Println(b)
file, _ := os.OpenFile("down.png", os.O_CREATE|os.O_WRONLY, 0644)
file.Write(b)
}
示例8: proxyHandler
func proxyHandler(w http.ResponseWriter, r *http.Request) {
hj, ok := w.(http.Hijacker)
if !ok {
http.Error(w, "webserver don't support hijacking", http.StatusInternalServerError)
return
}
var proxyFor = r.Header.Get("X-Proxy-For")
log.Println("X-Proxy-For client name:", r.RemoteAddr, proxyFor)
connCh, ok := namedConnection[proxyFor]
if !ok {
http.Error(w, "inside error: proxy not ready to receive conn", http.StatusInternalServerError)
return
}
hjconn, bufrw, err := hj.Hijack()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
connCh <- nil
return
}
//if _, ok := hjconn.(*net.TCPConn); ok {
//log.Println("Hijack is tcp conn")
//}
conn := NewHijackReadWriteCloser(hjconn.(*net.TCPConn), bufrw)
connCh <- conn
}
示例9: NewRecord
func (k *Keeper) NewRecord(name string) (key string, rec *Record, err error) {
k.tkmu.Lock()
defer k.tkmu.Unlock()
task, ok := k.tasks[name]
if !ok {
return "", nil, fmt.Errorf("No such task has name: %s", name)
}
xe.ShowSQL = true
total, err := xe.Where("name = ?", name).Count(&Record{})
log.Println("CC:", total, err)
// order update
k.removeFromOrder(name)
k.taskOrder = append([]string{name}, k.taskOrder...)
idx := int(total)
rec = &Record{
Name: name,
Index: idx,
Buffer: bytes.NewBuffer(nil),
T: task,
}
key = rec.Key()
k.crmu.Lock()
k.runRecs[key] = rec
k.crmu.Unlock()
return key, rec, nil
}
示例10: start
func (p *ProxyConn) start() {
defer p.lconn.Close()
defer p.rconn.Close()
//connect to remote
// rconn, err := net.DialTCP("tcp", nil, p.raddr)
// if err != nil {
// log.Printf("Remote connection failed: %s", err)
// return
// }
// p.rconn = rconn
// defer p.rconn.Close()
// FIXME: may need to set a flag
if tcpconn, ok := p.lconn.(*net.TCPConn); ok {
tcpconn.SetNoDelay(true)
}
if tcpconn, ok := p.rconn.(*net.TCPConn); ok {
tcpconn.SetNoDelay(true)
}
// p.lconn.SetNoDelay(true)
// p.rconn.SetNoDelay(true)
//display both ends
// log.Printf("Opened %s >>> %s", p.lconn.RemoteAddr().String(), p.rconn.RemoteAddr().String())
//bidirectional copy
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
ch1 := p.pipe(p.lconn, p.rconn)
<-ch1
closeRead(p.lconn)
closeWrite(p.rconn)
log.Println("close local -> remote")
wg.Done()
}()
go func() {
ch2 := p.pipe(p.rconn, p.lconn)
<-ch2
closeRead(p.rconn)
closeWrite(p.lconn)
log.Println("close remote -> local")
wg.Done()
}()
wg.Wait()
//wait for close...
// log.Printf("Closed (%d bytes sent, %d bytes recieved)", p.sentBytes, p.receivedBytes)
}
示例11: main
func main() {
flag.Parse()
log.SetOutputLevel(*flagdebug)
configFileName := filepath.Clean(*flagconfig + "/main.conf")
log.Debugf("config file '%s'\n", configFileName)
log.Printf("Starting %s\n", VERSION)
if *cpuprofile != "" {
prof, err := os.Create(*cpuprofile)
if err != nil {
panic(err.Error())
}
pprof.StartCPUProfile(prof)
defer func() {
log.Println("closing file")
prof.Close()
}()
defer func() {
log.Println("stopping profile")
pprof.StopCPUProfile()
}()
}
go configWatcher(configFileName)
terminate := make(chan os.Signal)
signal.Notify(terminate, os.Interrupt)
<-terminate
log.Printf("signal received, stopping")
if *memprofile != "" {
f, err := os.Create(*memprofile)
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)
f.Close()
}
//os.Exit(0)
}
示例12: update_popup
func update_popup() (ReadEntity, error) {
fs, fes, err := feedentries_updated()
if err == nil {
return ReadEntity{ReadSource: fs, Entries: fes}, nil
}
log.Println("update-popup", err)
return ReadEntity{}, err
}
示例13: load_gfwrules
func load_gfwrules() {
fp := filepath.Join(backend_config().DataFolder, "gfwlist.txt")
reader, err := os.Open(fp)
if err == nil {
defer reader.Close()
backend_context.ruler, err = gfwlist.NewGfwRuler(reader)
}
log.Println("gfwlist-load", err, fp)
}
示例14: actionStatus
func actionStatus(c *cli.Context) error {
err := checkServerStatus()
if err != nil {
log.Fatal(err)
} else {
log.Println("Server is running, OK.")
}
return nil
}
示例15: addRoute
func addRoute(m *macaron.Macaron, method, patten, script, contentType string) {
log.Println("Add Route:", method, patten, script)
method = strings.ToUpper(method)
switch method {
case "GET":
m.Get(patten, NewScriptHandler(script, contentType))
case "POST":
m.Post(patten, NewScriptHandler(script, contentType))
}
}