本文整理匯總了Golang中github.com/ian-kent/go-log/log.Trace函數的典型用法代碼示例。如果您正苦於以下問題:Golang Trace函數的具體用法?Golang Trace怎麽用?Golang Trace使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Trace函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Chunked
func (r *Response) Chunked() chan []byte {
c := make(chan []byte)
r.IsChunked = true
r.Send()
go func() {
for b := range c {
if len(b) == 0 {
log.Trace("Chunk stream ended")
if r.Gzipped {
r.gzwriter.Close()
}
break
}
log.Trace("Writing chunk: %d bytes", len(b))
if r.Gzipped {
r.gzwriter.Write(b)
} else {
r.Write(b)
}
if f, ok := r.writer.(nethttp.Flusher); ok {
f.Flush()
}
}
}()
return c
}
示例2: Static
func (h *Router) Static(filename string) HandlerFunc {
return func(session *http.Session) {
// TODO beware of ..?
re := regexp.MustCompile("{{(\\w+)}}")
fcopy := re.ReplaceAllStringFunc(filename, func(m string) string {
parts := re.FindStringSubmatch(m)
log.Trace("Found var: %s; name: %s", m, parts[1])
if val, ok := session.Stash[parts[1]]; ok {
log.Trace("Value found in stash for %s: %s", parts[1], val)
return val.(string)
}
log.Trace("No value found in stash for var: %s", parts[1])
return m
})
asset, err := h.Config.AssetLoader(fcopy)
if err != nil {
log.Debug("Static file not found: %s", fcopy)
session.RenderNotFound()
} else {
m := MIME.TypeFromFilename(fcopy)
if len(m) > 0 {
log.Debug("Setting Content-Type: %s", m)
session.Response.Headers.Add("Content-Type", m[0])
}
session.Response.Write(asset)
}
}
}
示例3: ParseCPANLines
func ParseCPANLines(lines []string) (*CPANFile, error) {
cpanfile := &CPANFile{}
for _, l := range lines {
if len(l) == 0 {
continue
}
log.Trace("Parsing line: %s", l)
dep, err := ParseCPANLine(l)
if err != nil {
log.Error("=> Error parsing line: %s", err)
continue
}
if dep != nil {
log.Info("=> Found dependency: %s", dep)
cpanfile.AddDependency(dep)
continue
}
log.Trace("=> No error and no dependency found")
}
log.Info("Found %d dependencies in cpanfile", len(cpanfile.Dependencies))
return cpanfile, nil
}
示例4: parseRules
func (fh *FormHelper) parseRules() {
s := reflect.TypeOf(fh.Model).Elem()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i).Name
tag := s.Field(i).Tag
if len(tag) > 0 {
log.Trace("Model field [%s] has validation tag: %s", f, tag)
s := strings.Split(string(tag), ";")
for _, rule := range s {
p := strings.SplitN(rule, ":", 2)
if len(p) == 1 {
rule = strings.TrimSpace(p[0])
log.Trace("Found rule [%s]", rule)
} else {
rule = strings.TrimSpace(p[0])
params := strings.TrimSpace(p[1])
log.Trace("Found rule [%s] with parameters [%s]", rule, params)
if _, ok := fh.Rules[f]; !ok {
fh.Rules[f] = make([]*Rule, 0)
}
switch rule {
case "minlength":
fh.Rules[f] = append(fh.Rules[f], MinLength(params))
case "maxlength":
fh.Rules[f] = append(fh.Rules[f], MaxLength(params))
}
}
}
}
}
}
示例5: Populate
func (fh *FormHelper) Populate(multipart bool) *FormHelper {
// TODO nested form values
t := reflect.TypeOf(fh.Model)
v := reflect.ValueOf(fh.Model)
s := t.Elem()
w := v.Elem()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i).Name
fl := strings.ToLower(f)
log.Trace("Model field [%s] mapped to form field [%s]", f, fl)
var val []string
if multipart {
val = fh.Session.Request.MultipartForm().Value[fl]
} else {
val = fh.Session.Request.PostForm()[fl]
}
if len(val) > 0 {
fh.Values[f] = val[0]
w.Field(i).SetString(val[0])
log.Trace("Field [%s] had value [%s]", fl, fh.Values[fl])
}
}
return fh
}
示例6: SaveIndex
func SaveIndex(index string, indexes map[string]*Source) {
// TODO append, but needs to know which stuff is new
//out, err := os.OpenFile(".gopancache/index", os.O_RDWR|os.O_APPEND, 0660)
out, err := os.Create(index)
if err != nil {
log.Error("Error creating index: %s", err.Error())
}
for _, source := range indexes {
out.Write([]byte(source.Name + " [" + source.URL + "]\n"))
log.Trace(source.Name)
for _, author := range source.Authors {
out.Write([]byte(" " + author.Name + " [" + author.URL + "]\n"))
log.Trace(" %s", author.Name)
for _, pkg := range author.Packages {
out.Write([]byte(" " + pkg.Name + " => " + pkg.URL + "\n"))
log.Trace(" %s => %s", pkg.Name, pkg.URL)
for p, pk := range pkg.Provides {
out.Write([]byte(" " + p + " (" + pk.Version + "): " + pk.File + "\n"))
log.Trace(" %s (%s): %s", p, pk.Version, pk.File)
}
}
}
}
out.Close()
}
示例7: Validate
func (fh *FormHelper) Validate() *FormHelper {
for k, f := range fh.Rules {
log.Trace("Validating field [%s] with value [%s]", k, fh.Values[k])
valid := true
for _, r := range f {
log.Trace("Executing rule [%s] with parameters [%s]", r.Name, r.Parameters)
err := r.Function(fh.Values[k])
if err != nil {
log.Trace("Rule [%s] failed: %s", r.Name, err)
fh.HasErrors = true
valid = false
if _, ok := fh.Errors[k]; !ok {
fh.Errors[k] = make(map[string]error)
}
fh.Errors[k][r.Name] = err
} else {
log.Trace("Rule [%s] passed", r.Name)
}
}
log.Trace("Field [%s] is valid: %t", k, valid)
}
return fh
}
示例8: Version
func (p *Package) Version() float64 {
if p.cachedVer > 0 {
return p.cachedVer
}
v := ""
// try and match against a provided package
for _, prov := range p.Provides {
if len(prov.Version) > 0 && prov.Version != "undef" {
if len(v) == 0 {
log.Trace("No version cached, using first version found [%s] from [%s]", prov.Version, prov.Name)
v = prov.Version
} else {
if p.Name == strings.Replace(prov.Name, "::", "-", -1)+"-"+prov.Version {
log.Trace("Version cached but found better match, using [%s] from [%s]", prov.Version, prov.Name)
v = prov.Version
}
}
}
}
if len(v) == 0 {
matches := fnToVer.FindStringSubmatch(p.Name)
if len(matches) >= 3 {
log.Trace("Found regex match: %s", matches[2])
v = matches[2]
}
}
p.cachedVer = VersionFromString(v)
return p.cachedVer
}
示例9: getCmd
func (m *Module) getCmd() *exec.Cmd {
var c *exec.Cmd
if _, ok := config.Test.Modules[m.Name]; ok || config.Test.Global {
log.Trace("Executing cpanm install without --notest flag for %s", m.Cached)
c = exec.Command("cpanm", "-L", config.InstallDir, m.Cached)
} else {
log.Trace("Executing cpanm install with --notest flag for %s", m.Cached)
c = exec.Command("cpanm", "--notest", "-L", config.InstallDir, m.Cached)
}
return c
}
示例10: Send
func (r *Response) Send() {
if r.headerSent {
return
}
r.headerSent = true
r.SessionID()
r.writeSessionData()
for k, v := range r.Headers {
for _, h := range v {
log.Trace("Adding header [%s]: [%s]", k, h)
r.writer.Header().Add(k, h)
}
}
for _, c := range r.Cookies {
nethttp.SetCookie(r.writer, c)
}
r.writer.WriteHeader(r.Status)
if r.Gzipped {
r.gzwriter.Write(r.buffer.Bytes())
} else {
r.writer.Write(r.buffer.Bytes())
}
if !r.IsChunked && !r.IsEventStream {
if r.Gzipped {
r.gzwriter.Close()
}
}
}
示例11: render
func (session *Session) render(asset string) error {
asset = "assets/templates/" + asset
var t *template.Template
c, ok := session.Config.Cache["template:"+asset]
if !ok {
log.Trace("Loading asset: %s", asset)
a, err := session.Config.AssetLoader(asset)
log.Trace("Creating template: %s", asset)
t = template.New(asset)
t.Delims(session.Config.LeftDelim, session.Config.RightDelim)
if err != nil || a == nil {
log.Error("Failed loading template %s: %s", asset, err)
return err
}
log.Trace("Parsing template: %s", asset)
_, err = t.Parse(string(a))
if err != nil {
log.Error("Failed parsing template %s: %s", asset, err)
return err
}
log.Trace("Template parsed successfully: %s", asset)
session.Config.Cache["template:"+asset] = t
} else {
t = c.(*template.Template)
log.Trace("Template loaded from cache: %s", asset)
}
var b bytes.Buffer
err := t.Execute(&b, session.Stash)
if err != nil {
log.Error("Failed executing template %s: %s", asset, err)
return err
}
_, err = session.Response.Write(b.Bytes())
if err != nil {
log.Error("Error writing output for template %s: %s", asset, err)
return err
}
return nil
}
示例12: AddDependency
func (d *DependencyList) AddDependency(dep *Dependency) {
if _, ok := perl_core[dep.Name]; ok {
log.Trace("Dependency " + dep.Name + " is from perl core")
return
}
if d.Dependencies == nil {
d.Dependencies = make([]*Dependency, 0)
}
d.Dependencies = append(d.Dependencies, dep)
}
示例13: ParseCPANLine
func ParseCPANLine(line string) (*Dependency, error) {
if len(line) == 0 {
return nil, nil
}
matches := re.FindStringSubmatch(line)
if len(matches) == 0 {
log.Trace("Unable to parse line: %s", line)
return nil, nil
}
module := matches[2]
version := strings.Replace(matches[4], " ", "", -1)
comment := matches[5]
dependency, err := DependencyFromString(module, version)
if strings.HasPrefix(strings.Trim(comment, " "), "# REQS: ") {
comment = strings.TrimPrefix(strings.Trim(comment, " "), "# REQS: ")
log.Trace("Found additional dependencies: %s", comment)
for _, req := range strings.Split(comment, ";") {
req = strings.Trim(req, " ")
bits := strings.Split(req, "-")
new_dep, err := DependencyFromString(bits[0], bits[1])
if err != nil {
log.Error("Error parsing REQS dependency: %s", req)
continue
}
log.Trace("Added dependency: %s", new_dep)
dependency.Additional = append(dependency.Additional, new_dep)
}
}
if err != nil {
return nil, err
}
log.Info("%s (%s %s)", module, dependency.Modifier, dependency.Version)
return dependency, err
}
示例14: Serve
func (h *Router) Serve(session *http.Session) {
for _, route := range h.Routes {
if matches := route.Route.Pattern.FindStringSubmatch(session.Request.URL.Path); len(matches) > 0 {
_, ok := route.Route.Methods[session.Request.Method]
if ok {
for i, named := range route.Route.Pattern.SubexpNames() {
if len(named) > 0 {
log.Trace("Matched named pattern '%s': %s", named, matches[i])
session.Stash[named] = matches[i]
}
}
session.Route = route.Route
defer func() {
if e := recover(); e != nil {
switch e.(type) {
case string:
session.RenderException(500, errors.New(e.(string)))
default:
session.RenderException(500, e.(error))
}
session.Response.Send()
session.Response.Close()
}
}()
var wg sync.WaitGroup
wg.Add(1)
// func() will be executed only if *all* event handlers call next()
h.Config.Events.Emit(session, events.BeforeHandler, func() {
route.Handler.ServeHTTP(session)
h.Config.Events.Emit(session, events.AfterHandler, func() {
session.Response.Send()
session.Response.Close()
wg.Done()
})
})
wg.Wait()
return
}
}
}
// no pattern matched; send 404 response
h.Config.Events.Emit(session, events.BeforeHandler, func() {
session.RenderNotFound()
h.Config.Events.Emit(session, events.AfterHandler, func() {
session.Response.Send()
})
})
}
示例15: Populate
// Populates a package namespace, e.g. constructing each part of the namespace
// when passed []string{'Mojolicious','Plugin','PODRenderer'}
func (p *PkgSpace) Populate(parts []string, pkg *gopan.PerlPackage) {
if len(parts) > 0 {
if _, ok := p.Children[parts[0]]; !ok {
p.Children[parts[0]] = &PkgSpace{
Namespace: parts[0],
Packages: make([]*gopan.PerlPackage, 0),
Children: make(map[string]*PkgSpace),
Parent: p,
Versions: make(map[float64]*gopan.PerlPackage),
}
}
if len(parts) == 1 {
p.Children[parts[0]].Packages = append(p.Children[parts[0]].Packages, pkg)
p.Children[parts[0]].Versions[gopan.VersionFromString(pkg.Version)] = pkg
log.Trace("Version linked: %f for %s in %s", gopan.VersionFromString(pkg.Version), pkg.Name, p.Namespace)
} else {
p.Children[parts[0]].Populate(parts[1:], pkg)
}
}
}