本文整理汇总了Golang中github.com/cortesi/devd/termlog.Logger.Say方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Say方法的具体用法?Golang Logger.Say怎么用?Golang Logger.Say使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cortesi/devd/termlog.Logger
的用法示例。
在下文中一共展示了Logger.Say方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LogHeader
// LogHeader logs a header
func LogHeader(log termlog.Logger, h http.Header) {
max := 0
for k := range h {
if len(k) > max {
max = len(k)
}
}
for k, vals := range h {
for _, v := range vals {
pad := fmt.Sprintf(fmt.Sprintf("%%%ds", max-len(k)+1), " ")
log.Say(
"\t%s%s%s",
color.BlueString(k)+":",
pad,
v,
)
}
}
}
示例2: devdHandler
func devdHandler(log termlog.Logger, route Route, templates *template.Template, logHeaders bool, ignoreHeaders []*regexp.Regexp, livereload bool, latency int) http.Handler {
ci := inject.CopyInject{}
if livereload {
ci = injectLivereload
}
next := route.Endpoint.Handler(templates, ci)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var sublog termlog.Logger
if matchStringAny(ignoreHeaders, fmt.Sprintf("%s%s", route.Host, r.RequestURI)) {
sublog = termlog.DummyLogger{}
} else {
sublog = log.Group()
}
timr := timer.Timer{}
defer func() {
timing := termlog.DefaultPalette.Timestamp.SprintFunc()("timing: ")
sublog.SayAs(
"timer",
timing+timr.String(),
)
sublog.Done()
}()
timr.RequestHeaders()
time.Sleep(time.Millisecond * time.Duration(latency))
sublog.Say("%s %s", r.Method, r.URL)
if logHeaders {
LogHeader(sublog, r.Header)
}
ctx := timr.NewContext(context.Background())
ctx = termlog.NewContext(ctx, sublog)
next.ServeHTTPContext(
ctx,
&ResponseLogWriter{
log: sublog,
rw: w,
timr: &timr,
logHeaders: logHeaders,
},
r,
)
})
}
示例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
}
示例4: testpatt
func testpatt(l termlog.Logger) {
l.Say("Log")
l.Notice("Notice!")
l.Warn("Warn!")
l.Shout("Error!")
}
示例5: 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
}