• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang log.LogTrace函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/gleez/smtpd/log.LogTrace函数的典型用法代码示例。如果您正苦于以下问题:Golang LogTrace函数的具体用法?Golang LogTrace怎么用?Golang LogTrace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: MailView

func MailView(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	id := ctx.Vars["id"]
	log.LogTrace("Loading Mail <%s> from Mongodb", id)

	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	m, err := ctx.Ds.Load(id)
	if err == nil {
		ctx.Ds.Messages.Update(
			bson.M{"id": m.Id},
			bson.M{"$set": bson.M{"unread": false}},
		)
		return RenderTemplate("mailbox/_show.html", w, map[string]interface{}{
			"ctx":     ctx,
			"title":   "Mail",
			"message": m,
		})
	} else {
		http.NotFound(w, r)
		return
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:27,代码来源:handlers.go


示例2: MailAttachment

func MailAttachment(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	id := ctx.Vars["id"]
	log.LogTrace("Loading Attachment <%s> from Mongodb", id)

	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	m, err := ctx.Ds.LoadAttachment(id)
	if err != nil {
		return fmt.Errorf("ID provided is invalid: %v", err)
	}

	if len(m.Attachments) > 0 {
		at := m.Attachments[0]

		data, err := base64.StdEncoding.DecodeString(at.Body)
		if err != nil {
			return fmt.Errorf("Cannot decode attachment: %v", err)
		}

		reader := bytes.NewReader(data)
		w.Header().Set("Content-Type", at.ContentType)
		//w.Header().Set("Content-Disposition", "attachment; filename=\""+at.FileName+"\"")
		http.ServeContent(w, r, at.FileName, time.Now(), reader)
		return nil
	} else {
		http.NotFound(w, r)
		return
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:34,代码来源:handlers.go


示例3: ParseSMTPMessage

// TODO support nested MIME content
func ParseSMTPMessage(m *config.SMTPMessage, hostname string, mimeParser bool) *Message {
	arr := make([]*Path, 0)
	for _, path := range m.To {
		arr = append(arr, PathFromString(path))
	}

	msg := &Message{
		Id:      bson.NewObjectId().Hex(),
		From:    PathFromString(m.From),
		To:      arr,
		Created: time.Now(),
		Ip:      m.Host,
		Unread:  true,
		Starred: false,
	}

	if mimeParser {
		msg.Content = &Content{Size: len(m.Data), Headers: make(map[string][]string, 0), Body: m.Data}
		// Read mail using standard mail package
		if rm, err := mail.ReadMessage(bytes.NewBufferString(m.Data)); err == nil {
			log.LogTrace("Reading Mail Message")
			msg.Content.Size = len(m.Data)
			msg.Content.Headers = rm.Header
			msg.Subject = MimeHeaderDecode(rm.Header.Get("Subject"))

			if mt, p, err := mime.ParseMediaType(rm.Header.Get("Content-Type")); err == nil {
				if strings.HasPrefix(mt, "multipart/") {
					log.LogTrace("Parsing MIME Message")
					MIMEBody := &MIMEBody{Parts: make([]*MIMEPart, 0)}
					if err := ParseMIME(MIMEBody, rm.Body, p["boundary"], msg); err == nil {
						log.LogTrace("Got multiparts %d", len(MIMEBody.Parts))
						msg.MIME = MIMEBody
					}
				} else {
					setMailBody(rm, msg)
				}
			} else {
				setMailBody(rm, msg)
			}
		} else {
			msg.Content.TextBody = m.Data
		}
	} else {
		msg.Content = ContentFromString(m.Data)
	}

	recd := fmt.Sprintf("from %s ([%s]) by %s (Smtpd)\r\n  for <%s>; %s\r\n", m.Helo, m.Host, hostname, msg.Id+"@"+hostname, time.Now().Format(time.RFC1123Z))
	//msg.Content.Headers["Delivered-To"]  = []string{msg.To}
	msg.Content.Headers["Message-ID"] = []string{msg.Id + "@" + hostname}
	msg.Content.Headers["Received"] = []string{recd}
	msg.Content.Headers["Return-Path"] = []string{"<" + m.From + ">"}
	return msg
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:54,代码来源:message.go


示例4: GreyMailFromAdd

func GreyMailFromAdd(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	id := ctx.Vars["id"]
	log.LogTrace("Greylist add mail %s", id)

	//we need a user to sign to
	if ctx.User == nil {
		log.LogWarn("Please login to add to grey list!")
		http.NotFound(w, r)
		return
	}

	// we need a user to be admin
	if ctx.User.IsSuperuser == false {
		http.NotFound(w, r)
		return
	}

	// we need to load email
	m, err := ctx.Ds.Load(id)
	if err != nil {
		log.LogTrace("Greylist mail Id not found %s", id)
		http.NotFound(w, r)
		return
	}

	e := fmt.Sprintf("%[email protected]%s", m.From.Mailbox, m.From.Domain)
	if to, _ := ctx.Ds.IsGreyMail(e, "from"); to == 0 {
		log.LogTrace("Greylist inserting mail %s", e)
		gm := data.GreyMail{
			Id:        bson.NewObjectId(),
			CreatedBy: ctx.User.Id.Hex(),
			CreatedAt: time.Now(),
			IsActive:  true,
			Email:     e,
			Local:     m.From.Mailbox,
			Domain:    m.From.Domain,
			Type:      "from",
		}

		if err = ctx.Ds.Emails.Insert(gm); err != nil {
			log.LogError("Error inserting grey list: %s", err)
			http.NotFound(w, r)
			return
		}

		return
	}

	http.NotFound(w, r)
	return
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:51,代码来源:handlers.go


示例5: Start

// Start() the web server
func Start() {
	addr := fmt.Sprintf("%v:%v", webConfig.Ip4address, webConfig.Ip4port)
	server := &http.Server{
		Addr:         addr,
		Handler:      nil,
		ReadTimeout:  60 * time.Second,
		WriteTimeout: 60 * time.Second,
	}

	// We don't use ListenAndServe because it lacks a way to close the listener
	log.LogInfo("HTTP listening on TCP4 %v", addr)
	var err error
	listener, err = net.Listen("tcp", addr)
	if err != nil {
		log.LogError("HTTP failed to start TCP4 listener: %v", err)
		// TODO More graceful early-shutdown procedure
		panic(err)
	}

	err = server.Serve(listener)
	if shutdown {
		log.LogTrace("HTTP server shutting down on request")
	} else if err != nil {
		log.LogError("HTTP server failed: %v", err)
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:27,代码来源:server.go


示例6: ServeHTTP

// ServeHTTP builds the context and passes onto the real handler
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	// Create the context
	ctx, err := NewContext(req)
	if err != nil {
		log.LogError("Failed to create context: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	defer ctx.Close()

	// Run the handler, grab the error, and report it
	buf := new(httpbuf.Buffer)
	log.LogTrace("Web: %v %v %v %v", parseRemoteAddr(req), req.Proto, req.Method, req.RequestURI)
	err = h(buf, req, ctx)
	if err != nil {
		log.LogError("Error handling %v: %v", req.RequestURI, err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// Save the session
	if err = ctx.Session.Save(req, buf); err != nil {
		log.LogError("Failed to save session: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// Apply the buffered response to the writer
	buf.Apply(w)
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:31,代码来源:server.go


示例7: Stop

func Stop() {
	log.LogTrace("HTTP shutdown requested")
	shutdown = true
	if listener != nil {
		listener.Close()
	} else {
		log.LogError("HTTP listener was nil during shutdown")
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:9,代码来源:server.go


示例8: openLogFile

// openLogFile creates or appends to the logfile passed on commandline
func openLogFile() error {
	// use specified log file
	var err error
	logf, err = os.OpenFile(*logfile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err != nil {
		return fmt.Errorf("Failed to create %v: %v\n", *logfile, err)
	}
	golog.SetOutput(logf)
	log.LogTrace("Opened new logfile")
	return nil
}
开发者ID:hiteshjoshi,项目名称:smtpd,代码行数:12,代码来源:main.go


示例9: Register

func Register(w http.ResponseWriter, req *http.Request, ctx *Context) error {
	if ctx.User != nil {
		ctx.Session.AddFlash("Already logged in")
		http.Redirect(w, req, reverse("Mails"), http.StatusSeeOther)
	}

	r := &data.LoginForm{
		Username: req.FormValue("username"),
		Password: req.FormValue("password"),
	}

	if r.Validate() {
		result := &data.User{}
		err := ctx.Ds.Users.Find(bson.M{"username": r.Username}).One(&result)
		if err == nil {
			ctx.Session.AddFlash("User already exists!")
			return RegisterForm(w, req, ctx)
		}

		u := &data.User{
			Id:          bson.NewObjectId(),
			Firstname:   req.FormValue("firstname"),
			Lastname:    req.FormValue("lastname"),
			Email:       req.FormValue("email"),
			Username:    r.Username,
			IsActive:    false,
			JoinedAt:    time.Now(),
			LastLoginIp: ctx.ClientIp,
		}
		u.SetPassword(r.Password)

		if err := ctx.Ds.Users.Insert(u); err != nil {
			ctx.Session.AddFlash("Problem registering user.")
			return RegisterForm(w, req, ctx)
		}

		if u.IsActive {
			//store the user id in the values and redirect to index
			ctx.Session.Values["user"] = u.Id.Hex()
			ctx.Session.AddFlash("Registration successful")
			http.Redirect(w, req, reverse("Mails"), http.StatusSeeOther)
			return nil
		} else {
			log.LogTrace("Registration successful")
			ctx.Session.AddFlash("Registration successful")
			return LoginForm(w, req, ctx)
		}
	} else {
		ctx.Session.AddFlash("Please fill all fields!")
		return RegisterForm(w, req, ctx)
	}

	return fmt.Errorf("Failed to register!")
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:54,代码来源:handlers.go


示例10: ParseTemplate

// ParseTemplate loads the requested template along with _base.html, caching
// the result (if configured to do so)
func ParseTemplate(name string, partial bool) (*template.Template, error) {
	cachedMutex.Lock()
	defer cachedMutex.Unlock()

	if t, ok := cachedTemplates[name]; ok {
		return t, nil
	}

	tempPath := strings.Replace(name, "/", string(filepath.Separator), -1)
	tempFile := filepath.Join(webConfig.TemplateDir, tempPath)
	log.LogTrace("Parsing template %v", tempFile)

	var err error
	var t *template.Template
	if partial {
		// Need to get basename of file to make it root template w/ funcs
		base := path.Base(name)
		t = template.New(base).Funcs(TemplateFuncs)
		t, err = t.ParseFiles(tempFile)
	} else {
		t = template.New("layout.html").Funcs(TemplateFuncs)
		// Note that the layout file must be the first parameter in ParseFiles
		t, err = t.ParseFiles(filepath.Join(webConfig.TemplateDir, "layout.html"), tempFile)
	}
	if err != nil {
		return nil, err
	}

	// Allows us to disable caching for theme development
	if webConfig.TemplateCache {
		if partial {
			log.LogTrace("Caching partial %v", name)
			cachedTemplates[name] = t
		} else {
			log.LogTrace("Caching template %v", name)
			cachedTemplates[name] = t
		}
	}

	return t, nil
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:43,代码来源:template.go


示例11: NginxHTTPAuth

// If running Nginx as a proxy, give Nginx the IP address and port for the SMTP server
// Primary use of Nginx is to terminate TLS so that Go doesn't need to deal with it.
// This could perform auth and load balancing too
// See http://wiki.nginx.org/MailCoreModule
func NginxHTTPAuth(w http.ResponseWriter, r *http.Request, ctx *Context) error {
	//log.LogTrace("Nginx Auth Client: %s", parseRemoteAddr(r))
	log.LogTrace("Nginx Auth Client IP <%s> (%s)", r.Header.Get("Client-IP"), r.Header.Get("Client-Host"))

	cfg := config.GetSmtpConfig()

	w.Header().Add("Auth-Status", "OK")
	w.Header().Add("Auth-Server", cfg.Ip4address.String())
	w.Header().Add("Auth-Port", strconv.Itoa(cfg.Ip4port))
	fmt.Fprint(w, "")
	return nil
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:16,代码来源:handlers.go


示例12: MailList

func MailList(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	log.LogTrace("Loading Mails from Mongodb")

	page, _ := strconv.Atoi(ctx.Vars["page"])
	limit := 25

	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	t, err := ctx.Ds.Total()
	if err != nil {
		http.NotFound(w, r)
		return
	}

	p := NewPagination(t, limit, page, "/mails")
	if page > p.Pages() {
		http.NotFound(w, r)
		return
	}

	messages, err := ctx.Ds.List(p.Offset(), p.Limit())
	if err == nil {
		return RenderTemplate("mailbox/_list.html", w, map[string]interface{}{
			"ctx":        ctx,
			"title":      "Mails",
			"messages":   messages,
			"end":        p.Offset() + p.Limit(),
			"pagination": p,
		})
	} else {
		http.NotFound(w, r)
		return
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:39,代码来源:handlers.go


示例13: Login

func Login(w http.ResponseWriter, req *http.Request, ctx *Context) error {
	l := &data.LoginForm{
		Username: req.FormValue("username"),
		Password: req.FormValue("password"),
	}

	if l.Validate() {
		u, err := ctx.Ds.Login(l.Username, l.Password)

		if err == nil {
			//store the user id in the values and redirect to index
			log.LogTrace("Login successful for session <%v>", u.Id)
			ctx.Ds.Users.Update(
				bson.M{"_id": u.Id},
				bson.M{"$set": bson.M{"lastlogintime": time.Now(), "lastloginip": ctx.ClientIp}, "$inc": bson.M{"logincount": 1}},
			)

			if u.IsActive {
				ctx.Session.Values["user"] = u.Id.Hex()
				http.Redirect(w, req, reverse("Mails"), http.StatusSeeOther)
				return nil
			} else {
				log.LogTrace("The user is not activated")
				ctx.Session.AddFlash("Username is not activated")
				return LoginForm(w, req, ctx)
			}
		} else {
			log.LogTrace("Invalid Username/Password")
			ctx.Session.AddFlash("Invalid Username/Password")
			return LoginForm(w, req, ctx)
		}
	} else {
		ctx.Session.AddFlash("Please fill all fields!")
		return LoginForm(w, req, ctx)
	}

	return fmt.Errorf("Failed to login!")
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:38,代码来源:handlers.go


示例14: MailDelete

func MailDelete(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	id := ctx.Vars["id"]
	log.LogTrace("Delete Mail <%s> from Mongodb", id)

	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	err = ctx.Ds.DeleteOne(id)
	if err == nil {
		log.LogTrace("Deleted mail id: %s", id)
		ctx.Session.AddFlash("Successfuly deleted mail id:" + id)
		http.Redirect(w, r, reverse("Mails"), http.StatusSeeOther)
		return nil
	} else {
		http.NotFound(w, r)
		return err
	}

}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:23,代码来源:handlers.go


示例15: Status

func Status(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	updateSystemStatus()

	return RenderTemplate("root/status.html", w, map[string]interface{}{
		"ctx":       ctx,
		"SysStatus": sysStatus,
	})
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:15,代码来源:handlers.go


示例16: SaveMail

func (ds *DataStore) SaveMail() {
	log.LogTrace("Running SaveMail Rotuines")
	var err error
	var recon bool

	for {
		mc := <-ds.SaveMailChan
		msg := ParseSMTPMessage(mc, mc.Domain, ds.Config.MimeParser)

		if ds.Config.Storage == "mongodb" {
			mc.Hash, err = ds.Storage.(*MongoDB).Store(msg)

			// if mongo conection is broken, try to reconnect only once
			if err == io.EOF && !recon {
				log.LogWarn("Connection error trying to reconnect")
				ds.Storage = CreateMongoDB(ds.Config)
				recon = true

				//try to save again
				mc.Hash, err = ds.Storage.(*MongoDB).Store(msg)
			}

			if err == nil {
				recon = false
				log.LogTrace("Save Mail Client hash : <%s>", mc.Hash)
				mc.Notify <- 1

				//Notify web socket
				ds.NotifyMailChan <- mc.Hash
			} else {
				mc.Notify <- -1
				log.LogError("Error storing message: %s", err)
			}
		}
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:36,代码来源:storage.go


示例17: CreateMongoDB

func CreateMongoDB(c config.DataStoreConfig) *MongoDB {
	log.LogTrace("Connecting to MongoDB: %s\n", c.MongoUri)

	session, err := mgo.Dial(c.MongoUri)
	if err != nil {
		log.LogError("Error connecting to MongoDB: %s", err)
		return nil
	}

	return &MongoDB{
		Config:   c,
		Session:  session,
		Messages: session.DB(c.MongoDb).C(c.MongoColl),
		Users:    session.DB(c.MongoDb).C("Users"),
		Hosts:    session.DB(c.MongoDb).C("GreyHosts"),
		Emails:   session.DB(c.MongoDb).C("GreyMails"),
		Spamdb:   session.DB(c.MongoDb).C("SpamDB"),
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:19,代码来源:mongostore.go


示例18: tlsHandler

func (c *Client) tlsHandler() {
	if c.tls_on {
		c.Write("502", "Already running in TLS")
		return
	}

	if c.server.TLSConfig == nil {
		c.Write("502", "TLS not supported")
		return
	}

	log.LogTrace("Ready to start TLS")
	c.Write("220", "Ready to start TLS")

	// upgrade to TLS
	var tlsConn *tls.Conn
	tlsConn = tls.Server(c.conn, c.server.TLSConfig)
	err := tlsConn.Handshake() // not necessary to call here, but might as well

	if err == nil {
		//c.conn   = net.Conn(tlsConn)
		c.conn = tlsConn
		c.bufin = bufio.NewReader(c.conn)
		c.bufout = bufio.NewWriter(c.conn)
		c.tls_on = true

		// Reset envelope as a new EHLO/HELO is required after STARTTLS
		c.reset()

		// Reset deadlines on the underlying connection before I replace it
		// with a TLS connection
		c.conn.SetDeadline(time.Time{})
		c.flush()
	} else {
		c.logWarn("Could not TLS handshake:%v", err)
		c.Write("550", "Handshake error")
	}

	c.state = 1
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:40,代码来源:server.go


示例19: ContentFromString

func ContentFromString(data string) *Content {
	log.LogTrace("Parsing Content from string: <%d>", len(data))
	x := strings.SplitN(data, "\r\n\r\n", 2)
	h := make(map[string][]string, 0)

	if len(x) == 2 {
		headers, body := x[0], x[1]
		hdrs := strings.Split(headers, "\r\n")
		var lastHdr = ""
		for _, hdr := range hdrs {
			if lastHdr != "" && strings.HasPrefix(hdr, " ") {
				h[lastHdr][len(h[lastHdr])-1] = h[lastHdr][len(h[lastHdr])-1] + hdr
			} else if strings.Contains(hdr, ": ") {
				y := strings.SplitN(hdr, ": ", 2)
				key, value := y[0], y[1]
				// TODO multiple header fields
				h[key] = []string{value}
				lastHdr = key
			} else {
				log.LogWarn("Found invalid header: '%s'", hdr)
			}
		}
		//log.LogTrace("Found body: '%s'", body)
		return &Content{
			Size:    len(data),
			Headers: h,
			Body:    body,
			//Body:   "",
		}
	} else {
		return &Content{
			Size:     len(data),
			Headers:  h,
			Body:     x[0],
			TextBody: x[0],
		}
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:38,代码来源:message.go


示例20: Ping

func Ping(w http.ResponseWriter, r *http.Request, ctx *Context) error {
	log.LogTrace("Ping successful")
	fmt.Fprint(w, "OK")
	return nil
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:5,代码来源:handlers.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang testing.T类代码示例发布时间:2022-05-23
下一篇:
Golang log.LogError函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap