本文整理匯總了Golang中github.com/ian-kent/go-log/log.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Resolve
// Resolve dependencies in a dependency list
// Resolves dependencies in order they occured originally
func (d *DependencyList) Resolve() error {
if d == nil {
log.Debug("No dependencies to resolve")
return nil
}
log.Debug("Resolving dependencies")
errs := make([]string, 0)
for _, dep := range d.Dependencies {
log.Debug("Resolving module dependency: %s", dep)
if err := dep.Resolve(d.Parent); err != nil {
log.Error("Error resolving module dependencies [%s]: %s", dep, err)
errs = append(errs, dep.String())
break
}
}
if len(errs) > 0 {
log.Error("Failed to find dependencies:")
for _, err := range errs {
log.Error("=> %s", err)
}
return errors.New("Failed to find dependencies")
}
return nil
}
示例2: 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
}
示例3: 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()
}
示例4: WatchConfig
func WatchConfig(configWrapper iConfigWrapper, configPath string) {
watcherForConfigFile, err := fsnotify.NewWatcher()
CheckError(err)
go func() {
for {
select {
case e := <-watcherForConfigFile.Event:
if lastConfigModifiedTime.Add(1 * time.Second).After(time.Now()) {
continue
}
lastConfigModifiedTime = time.Now()
// log.Warn("Config '%s' modified, but NOT RELOADING YET.", e.Name)
log.Warn("Config '%s' modified, now reloading (most of the) config settings.", e.Name)
configWrapper.SetConfig(loadFile(configPath))
configWrapper.ConfigReloaded()
break
case err := <-watcherForConfigFile.Error:
log.Error("Error: %+v", err)
break
}
}
}()
err = watcherForConfigFile.Watch(configPath)
CheckError(err)
}
示例5: NetworkName
// NetworkName returns the SSID of the wifi network.
func NetworkName(nif string) string {
if nif == "" {
nif = C.GoString(C.guessWifiInterfaceName())
}
if nif == "" {
log.Debug("Could not find Wi-Fi network interface")
return ""
}
active := C.getWifiActive(C.CString(nif))
powerOn := C.getWifiPowerOn(C.CString(nif))
if !active {
log.Debug("Wi-Fi network interface is not active")
return ""
}
if !powerOn {
log.Debug("Wi-Fi network interface is not powered on")
return ""
}
ssid := C.GoString(C.getWifiSSID(C.CString(nif)))
if ssid == "" {
log.Error("Wi-Fi network interface ssid empty")
}
return ssid
}
示例6: 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
}
示例7: RenderException
func (session *Session) RenderException(status int, err error) {
key := uuid.NewUUID().String()
session.Response.Status = status
session.Stash["Gotcha"].(map[string]interface{})["Error"] = err.Error()
session.Stash["Gotcha"].(map[string]interface{})["ErrorId"] = key
buf := make([]byte, 1<<16)
n := runtime.Stack(buf, true)
session.Stash["Gotcha"].(map[string]interface{})["Stack"] = fmt.Sprintf("%s", buf[:n])
log.Error("Exception %s: %s\n%s", key, err.Error(), session.Stash["Gotcha"].(map[string]interface{})["Stack"])
e := session.render("error.html")
if e != nil {
log.Error("Error rendering error page: %s", e)
session.Response.Write([]byte("[" + key + "] Internal Server Error: " + err.Error() + "\n"))
}
}
示例8: RenderNotFound
func (session *Session) RenderNotFound() {
session.Stash["Gotcha"].(map[string]interface{})["Error"] = "Not found"
session.Response.Status = 404
e := session.render("notfound.html")
if e != nil {
log.Error("Error rendering not found page: %s", e)
}
}
示例9: RemoveModule
func RemoveModule(index string, source *Source, author *Author, pkg *Package) {
out, err := os.OpenFile(index, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
if err != nil {
log.Error("Error opening index: %s", err.Error())
return
}
out.Write([]byte(source.Name + " [" + source.URL + "]\n"))
out.Write([]byte(" " + author.Name + " [" + author.URL + "]\n"))
out.Write([]byte(" -" + pkg.Name + " => " + pkg.URL + "\n"))
out.Close()
}
示例10: LoadConfig
func LoadConfig(global string, workspaces []string) {
// Load global environment
log.Info("Loading global environment file: %s", global)
cfg, err := LoadConfigFile(global)
if err != nil {
log.Error("Error loading global configuration: %s", err.Error())
}
if cfg != nil {
GlobalConfigWorkspace = cfg
}
// Load workspaces
for _, conf := range workspaces {
log.Info("Loading workspace file: %s", conf)
cfg, err := LoadConfigFile(conf)
if err != nil {
log.Error("Error loading workspace: %s", err.Error())
}
if cfg != nil {
ConfigWorkspaces[cfg.Name] = cfg
}
}
}
示例11: AppendToIndex
func AppendToIndex(index string, source *Source, author *Author, pkg *Package) {
out, err := os.OpenFile(index, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
if err != nil {
log.Error("Error opening index: %s", err.Error())
return
}
out.Write([]byte(source.Name + " [" + source.URL + "]\n"))
out.Write([]byte(" " + author.Name + " [" + author.URL + "]\n"))
out.Write([]byte(" " + pkg.Name + " => " + pkg.URL + "\n"))
for p, pk := range pkg.Provides {
out.Write([]byte(" " + p + " (" + pk.Version + "): " + pk.File + "\n"))
}
out.Close()
}
示例12: HasJSONXS
func HasJSONXS() bool {
cmd := exec.Command("perl", "-MJSON::XS", "-e", "")
_, err := cmd.Output()
if err != nil {
log.Error("Error executing command: %s", err)
return false
}
ps := cmd.ProcessState
sy := ps.Sys().(syscall.WaitStatus)
exit := sy.ExitStatus()
if exit != 0 {
return false
}
return true
}
示例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: Load
func (s *Source) Load() error {
log.Debug("Loading source: %s", s)
switch s.Type {
case "CPAN":
log.Debug("=> Got CPAN source")
return s.loadCPANSource()
case "BackPAN":
log.Debug("=> Got BackPAN source")
return s.loadBackPANSource()
case "SmartPAN":
log.Debug("=> Got SmartPAN source")
return nil
case "MetaCPAN":
log.Debug("=> Got MetaCPAN source")
return nil
default:
log.Error("Unrecognised source type: %s", s.Type)
return errors.New(fmt.Sprintf("Unrecognised source: %s", s))
}
}
示例15: HasPerl
func HasPerl() (bool, string) {
cmd := exec.Command("perl", "-V::version:")
out, err := cmd.Output()
if err != nil {
log.Error("Error executing command: %s", err)
return false, ""
}
ps := cmd.ProcessState
sy := ps.Sys().(syscall.WaitStatus)
exit := sy.ExitStatus()
if exit != 0 {
return false, ""
}
s := string(out)
s = strings.TrimSpace(s)
l := strings.Split(s, "\n")
v := l[0]
return true, v
}