1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-08 17:51:57 +00:00

log: Replace glog with a new logging module

glog works fine and has great features, but it does not play along well
with systemd or standard log rotators (as it does the rotation itself).

So this patch replaces glog with a new logging module "log", which by
default logs to stderr, in a systemd-friendly manner.

Logging to files or syslog is still supported.
This commit is contained in:
Alberto Bertogli
2016-10-24 03:02:11 +01:00
parent 60ed30e95a
commit 60a7932bd3
19 changed files with 446 additions and 138 deletions

View File

@@ -8,7 +8,6 @@ import (
"os"
"time"
"github.com/golang/glog"
"golang.org/x/net/idna"
"blitiri.com.ar/go/chasquid/internal/domaininfo"
@@ -48,7 +47,7 @@ func (s *SMTP) Deliver(from string, to string, data []byte) (error, bool) {
tr.Debugf("%s -> %s", from, to)
toDomain := envelope.DomainOf(to)
mx, err := lookupMX(toDomain)
mx, err := lookupMX(tr, toDomain)
if err != nil {
// Note this is considered a permanent error.
// This is in line with what other servers (Exim) do. However, the
@@ -162,7 +161,7 @@ retry:
return nil, false
}
func lookupMX(domain string) (string, error) {
func lookupMX(tr *trace.Trace, domain string) (string, error) {
if v, ok := fakeMX[domain]; ok {
return v, nil
}
@@ -175,10 +174,11 @@ func lookupMX(domain string) (string, error) {
mxs, err := net.LookupMX(domain)
if err == nil {
if len(mxs) == 0 {
glog.Infof("domain %q has no MX, falling back to A", domain)
tr.Printf("domain %q has no MX, falling back to A", domain)
return domain, nil
}
tr.Printf("MX %s", mxs[0].Host)
return mxs[0].Host, nil
}
@@ -188,6 +188,7 @@ func lookupMX(domain string) (string, error) {
// For now, if the error is permanent, we assume it's because there was no
// MX and fall back, otherwise we return.
// TODO: Find a better way to do this.
tr.Errorf("MX lookup error: %v", err)
dnsErr, ok := err.(*net.DNSError)
if !ok {
return "", err