当前位置: 首页>>代码示例>>Golang>>正文


Golang Logger.Shout方法代码示例

本文整理汇总了Golang中github.com/cortesi/devd/termlog.Logger.Shout方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Shout方法的具体用法?Golang Logger.Shout怎么用?Golang Logger.Shout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cortesi/devd/termlog.Logger的用法示例。


在下文中一共展示了Logger.Shout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: dirList

func dirList(ci inject.CopyInject, logger termlog.Logger, w http.ResponseWriter, name string, f http.File, templates *template.Template) {
	w.Header().Set("Cache-Control", "no-store, must-revalidate")
	files, err := f.Readdir(0)
	if err != nil {
		logger.Shout("Error reading directory for listing: %s", err)
		return
	}
	data := dirData{Name: name, Files: files}
	err = ci.ServeTemplate(http.StatusOK, w, templates.Lookup("dirlist.html"), data)
	if err != nil {
		logger.Shout("Failed to generate dir listing: %s", err)
	}
}
开发者ID:rawbite,项目名称:devd,代码行数:13,代码来源:fileserver.go

示例2: dirList

func dirList(ci inject.CopyInject, logger termlog.Logger, w http.ResponseWriter, name string, f http.File, templates *template.Template) {
	w.Header().Set("Cache-Control", "no-store, must-revalidate")
	files, err := f.Readdir(0)
	if err != nil {
		logger.Shout("Error reading directory for listing: %s", err)
		return
	}
	data := dirData{Name: name, Files: files}
	buff := bytes.NewBuffer(make([]byte, 0, 0))
	err = templates.Lookup("dirlist.html").Execute(buff, data)
	length := buff.Len()
	if err != nil {
		logger.Shout("Error producing directory listing: %s", err)
	}
	inj, err := ci.Sniff(buff)
	if err != nil {
		logger.Shout("Failed to inject in dir listing: %s", err)
		return
	}
	w.Header().Set(
		"Content-Length", fmt.Sprintf("%d", length+inj.Extra()),
	)
	_, err = inj.Copy(w)
	if err != nil {
		logger.Shout("Failed to inject in dir listing: %s", err)
		return
	}
}
开发者ID:npk,项目名称:devd,代码行数:28,代码来源:fileserver.go

示例3: Serve

// Serve starts the devd server. The callback is called with the serving URL
// just before service starts.
func (dd *Devd) Serve(address string, port int, certFile string, logger termlog.Logger, callback func(string)) error {
	templates, err := ricetemp.MakeTemplates(rice.MustFindBox("templates"))
	if err != nil {
		return fmt.Errorf("Error loading templates: %s", err)
	}
	mux, err := dd.Router(logger, templates)
	if err != nil {
		return err
	}
	var tlsConfig *tls.Config
	var tlsEnabled bool
	if certFile != "" {
		tlsConfig, err = getTLSConfig(certFile)
		if err != nil {
			return fmt.Errorf("Could not load certs: %s", err)
		}
		tlsEnabled = true
	}

	var hl net.Listener
	if port > 0 {
		hl, err = net.Listen("tcp", fmt.Sprintf("%v:%d", address, port))
	} else {
		hl, err = pickPort(address, portLow, portHigh, tlsEnabled)
	}
	if err != nil {
		return fmt.Errorf("Could not bind to port: %s", err)
	}

	if tlsConfig != nil {
		hl = tls.NewListener(hl, tlsConfig)
	}

	hl = slowdown.NewSlowListener(hl, dd.UpKbps*1024, dd.DownKbps*1024)
	url := formatURL(tlsEnabled, address, hl.Addr().(*net.TCPAddr).Port)
	logger.Say("Listening on %s (%s)", url, hl.Addr().String())
	server := &http.Server{Addr: hl.Addr().String(), Handler: mux}
	callback(url)
	err = server.Serve(hl)
	logger.Shout("Server stopped: %v", err)
	return nil
}
开发者ID:jonaz,项目名称:devd,代码行数:44,代码来源:server.go

示例4: serveFile

// name is '/'-separated, not filepath.Separator.
func (fserver *FileServer) serveFile(
	logger termlog.Logger,
	w http.ResponseWriter,
	r *http.Request,
	name string,
	redirect bool,
) {
	const indexPage = "/index.html"

	// redirect .../index.html to .../
	// can't use Redirect() because that would make the path absolute,
	// which would be a problem running under StripPrefix
	if strings.HasSuffix(r.URL.Path, indexPage) {
		logger.SayAs(
			"debug", "debug fileserver: redirecting %s -> ./", indexPage,
		)
		localRedirect(w, r, "./")
		return
	}

	f, err := fserver.Root.Open(name)
	if err != nil {
		logger.WarnAs("debug", "debug fileserver: %s", err)
		if err := notFound(fserver.Inject, fserver.Templates, w); err != nil {
			logger.Shout("Internal error: %s", err)
		}
		return
	}
	defer f.Close()

	d, err1 := f.Stat()
	if err1 != nil {
		logger.WarnAs("debug", "debug fileserver: %s", err)
		if err := notFound(fserver.Inject, fserver.Templates, w); err != nil {
			logger.Shout("Internal error: %s", err)
		}
		return
	}

	if redirect {
		// redirect to canonical path: / at end of directory url
		// r.URL.Path always begins with /
		url := r.URL.Path
		if d.IsDir() {
			if url[len(url)-1] != '/' {
				localRedirect(w, r, path.Base(url)+"/")
				return
			}
		} else {
			if url[len(url)-1] == '/' {
				localRedirect(w, r, "../"+path.Base(url))
				return
			}
		}
	}

	// use contents of index.html for directory, if present
	if d.IsDir() {
		index := name + indexPage
		ff, err := fserver.Root.Open(index)
		if err == nil {
			defer ff.Close()
			dd, err := ff.Stat()
			if err == nil {
				name = index
				d = dd
				f = ff
			}
		}
	}

	// Still a directory? (we didn't find an index.html file)
	if d.IsDir() {
		if checkLastModified(w, r, d.ModTime()) {
			return
		}
		dirList(fserver.Inject, logger, w, name, f, fserver.Templates)
		return
	}

	// serverContent will check modification time
	sizeFunc := func() (int64, error) { return d.Size(), nil }
	err = serveContent(fserver.Inject, w, r, d.Name(), d.ModTime(), sizeFunc, f)
	if err != nil {
		logger.Warn("Error serving file: %s", err)
	}
}
开发者ID:rawbite,项目名称:devd,代码行数:88,代码来源:fileserver.go

示例5: testpatt

func testpatt(l termlog.Logger) {
	l.Say("Log")
	l.Notice("Notice!")
	l.Warn("Warn!")
	l.Shout("Error!")
}
开发者ID:npk,项目名称:devd,代码行数:6,代码来源:termlog_demo.go

示例6: Serve

// Serve starts the devd server
func (dd *Devd) Serve(logger termlog.Logger) error {
	templates, err := ricetemp.MakeTemplates(rice.MustFindBox("templates"))
	if err != nil {
		return fmt.Errorf("Error loading templates: %s", err)
	}

	ignores := make([]*regexp.Regexp, 0, 0)
	for _, expr := range dd.IgnoreLogs {
		v, err := regexp.Compile(expr)
		if err != nil {
			return fmt.Errorf("%s", err)
		}
		ignores = append(ignores, v)
	}

	routeColl := make(RouteCollection)
	for _, s := range dd.Routes {
		err := routeColl.Set(s)
		if err != nil {
			return fmt.Errorf("Invalid route specification: %s", err)
		}
	}

	mux := http.NewServeMux()
	for match, route := range routeColl {
		handler := dd.RouteHandler(logger, route, templates, ignores)
		mux.Handle(match, http.StripPrefix(route.Path, handler))
	}

	lr := livereload.NewServer("livereload", logger)
	if dd.LivereloadEnabled() {
		mux.Handle("/livereload", lr)
		mux.Handle("/livereload.js", http.HandlerFunc(lr.ServeScript))
	}
	if dd.LivereloadRoutes {
		err = WatchRoutes(routeColl, lr, dd.Excludes, logger)
		if err != nil {
			return fmt.Errorf("Could not watch routes for livereload: %s", err)
		}
	}
	if len(dd.Watch) > 0 {
		err = WatchPaths(dd.Watch, dd.Excludes, lr, logger)
		if err != nil {
			return fmt.Errorf("Could not watch path for livereload: %s", err)
		}
	}

	var hl net.Listener
	tlsEnabled := false
	if dd.CertFile != "" {
		tlsEnabled = true
	}
	if dd.Port > 0 {
		hl, err = net.Listen("tcp", fmt.Sprintf("%v:%d", dd.Address, dd.Port))
	} else {
		hl, err = pickPort(dd.Address, portLow, portHigh, tlsEnabled)
	}
	if err != nil {
		return fmt.Errorf("Could not bind to port: %s", err)
	}

	var tlsConfig *tls.Config
	if dd.CertFile != "" {
		tlsConfig, err = getTLSConfig(dd.CertFile)
		if err != nil {
			return fmt.Errorf("Could not load certs: %s", err)
		}
		hl = tls.NewListener(hl, tlsConfig)
	}
	hl = slowdown.NewSlowListener(hl, dd.UpKbps*1024, dd.DownKbps*1024)

	url := formatURL(tlsEnabled, dd.Address, hl.Addr().(*net.TCPAddr).Port)
	logger.Say("Listening on %s (%s)", url, hl.Addr().String())
	if dd.OpenBrowser {
		go func() {
			webbrowser.Open(url)
		}()
	}
	server := &http.Server{
		Addr:    hl.Addr().String(),
		Handler: hostPortStrip(mux),
	}
	err = server.Serve(hl)
	logger.Shout("Server stopped: %v", err)
	return nil
}
开发者ID:supiyun,项目名称:devd,代码行数:87,代码来源:cli.go


注:本文中的github.com/cortesi/devd/termlog.Logger.Shout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。