File: logger.go

package info (click to toggle)
golang-github-revel-revel 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,240 kB
  • sloc: xml: 7; makefile: 7; javascript: 1
file content (66 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package revel

import (
	"github.com/revel/revel/logger"
)

//Logger
var (
	// The root log is what all other logs are branched from, meaning if you set the handler for the root
	// it will adjust all children
	RootLog = logger.New()
	// This logger is the application logger, use this for your application log messages - ie jobs and startup,
	// Use Controller.Log for Controller logging
	// The requests are logged to this logger with the context of `section:requestlog`
	AppLog = RootLog.New("module", "app")
	// This is the logger revel writes to, added log messages will have a context of module:revel in them
	// It is based off of `RootLog`
	RevelLog = RootLog.New("module", "revel")

	// This is the handler for the AppLog, it is stored so that if the AppLog is changed it can be assigned to the
	// new AppLog
	appLogHandler *logger.CompositeMultiHandler

	// This oldLog is the revel logger, historical for revel, The application should use the AppLog or the Controller.oldLog
	// DEPRECATED
	oldLog = AppLog.New("section", "deprecated")
	// System logger
	SysLog = AppLog.New("section", "system")
)

// Initialize the loggers first
func init() {

	//RootLog.SetHandler(
	//	logger.LevelHandler(logger.LogLevel(log15.LvlDebug),
	//		logger.StreamHandler(os.Stdout, logger.TerminalFormatHandler(false, true))))
	initLoggers()
	OnAppStart(initLoggers, -5)

}
func initLoggers() {
	appHandle := logger.InitializeFromConfig(BasePath, Config)

	// Set all the log handlers
	setAppLog(AppLog, appHandle)
}

// Set the application log and handler, if handler is nil it will
// use the same handler used to configure the application log before
func setAppLog(appLog logger.MultiLogger, appHandler *logger.CompositeMultiHandler) {
	if appLog != nil {
		AppLog = appLog
	}

	if appHandler != nil {
		appLogHandler = appHandler
		// Set the app log and the handler for all forked loggers
		RootLog.SetHandler(appLogHandler)

		// Set the system log handler - this sets golang writer stream to the
		// sysLog router
		logger.SetDefaultLog(SysLog)
		SysLog.SetStackDepth(5)
		SysLog.SetHandler(appLogHandler)
	}
}