コード例 #1
0
ファイル: Run.go プロジェクト: spambarrier/anaLog
func Run() {
	defer func() {
		anaLog.Close()
		idl.Panic("shutdown")
	}()

	if config.AppLog.SlackLogUrl != "" {

		prio := priority.Warning
		if config.AnaLog.DevelopmentEnv {
			prio = priority.Debugging
		}

		idl.AddHook(&iDslackLog.SlackLogHook{
			AcceptedPriorities: priority.Threshold(prio),
			HookURL:            config.AppLog.SlackLogUrl,
			IconURL:            "",
			Channel:            "",
			IconEmoji:          "",
			Username:           "******",
		})
	}

	idl.StandardLogger().Async = true
	idl.SetPrefix("anaLog")
	idl.SetErrCallback(func(err error) {
		idl.StandardLogger().Async = true
		idl.Log(&idl.Event{
			idl.StandardLogger(),
			map[string]interface{}{
				"error": err,
			},
			time.Now(),
			priority.Emergency,
			"AppLogger caught an internal error",
		})
		panic("AppLogger caught an internal error")
	})

	if config.AnaLog.DevelopmentEnv {
		go scheduler.StartIn(1 * time.Second)
	} else {
		go scheduler.StartIn(10 * time.Second)
	}

	server.Listen()
}
コード例 #2
0
ファイル: server.go プロジェクト: spambarrier/anaLog
func Listen() {
	logger := iDnegroniLog.NewMiddleware(idl.StandardLogger())

	logger.Stack2Http = config.AnaLog.DevelopmentEnv

	n := negroni.New(logger /*negroni.NewStatic(http.Dir(helper.GetFilePath("./public")))*/)

	cookiestore := cookiestore.New([]byte(config.AnaLog.CookieSecret))
	n.Use(sessions.Sessions("perm_analog_session", cookiestore))
	n.Use(negroni.HandlerFunc(preflight))

	n.UseHandler(router.New())

	if config.AnaLog.UseSocketMaster {
		listener, err := client.Listen(protocol.SocketDefinition{
			Port: config.SocketMaster.Port,
			HTTP: &protocol.SocketHTTPDefinition{
				DomainSuffix: config.SocketMaster.DomainSuffix,
				PathPrefix:   config.SocketMaster.PathPrefix,
			},
			/*TLS: &protocol.SocketTLSDefinition{
				Cert: config.SocketMaster.Cert,
				Key:  config.SocketMaster.Key,
			},*/
		})
		if err != nil {
			idl.Emerg(err)
		}
		idl.Notice("Serving via SocketMaster")
		http.Serve(listener, n)
	} else if config.AnaLog.Fcgi {
		listener, err := net.Listen("tcp", config.AnaLog.Listen)
		if err != nil {
			idl.Emerg(err)
		}
		idl.Notice("Serving via FastCGI")
		fcgi.Serve(listener, n)
	} else {
		idl.Notice("Serving via inbuilt HTTP Server")
		n.Run(config.AnaLog.Listen)
	}
}
コード例 #3
0
ファイル: webapp.go プロジェクト: spambarrier/anaLog
package webapp

import (
	idl "go.iondynamics.net/iDlogger"
	"go.iondynamics.net/iDlogger/priority"
	"net/http"
	"time"
)

var Std = idl.StandardLogger()

type Error struct {
	Error   error
	Message string
	Code    int
	Write   bool
}

func New(err error, message string, code int) *Error {
	return &Error{Error: err, Message: message, Code: code, Write: false}
}

func Write(err error, message string, code int) *Error {
	return &Error{Error: err, Message: message, Code: code, Write: true}
}

type Handler func(http.ResponseWriter, *http.Request) *Error

func (fn Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if e := fn(w, r); e != nil {
		Std.Log(&idl.Event{Std, map[string]interface{}{"Error": e.Error, "Message": e.Message, "Code": e.Code}, time.Now(), priority.Error, e.Error.Error()})