本文整理匯總了Golang中code/google/com/p/log4go.NewFileLogWriter函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFileLogWriter函數的具體用法?Golang NewFileLogWriter怎麽用?Golang NewFileLogWriter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewFileLogWriter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: InitLogger
func InitLogger(logFile string, logFormat string, accessLogFile string, accessLogFormat string) {
loglevel := l4g.INFO
if conf.DebugMode {
loglevel = l4g.DEBUG
}
log = make(l4g.Logger)
flw := l4g.NewFileLogWriter(logFile, false)
flw.SetFormat(logFormat)
flw.SetRotate(false)
flw.SetRotateSize(0)
flw.SetRotateLines(0)
flw.SetRotateDaily(false)
log.AddFilter("file", loglevel, flw)
accessLog = make(l4g.Logger)
aflw := l4g.NewFileLogWriter(accessLogFile, false)
aflw.SetFormat(accessLogFormat)
aflw.SetRotate(false)
aflw.SetRotateSize(0)
aflw.SetRotateLines(0)
aflw.SetRotateDaily(false)
accessLog.AddFilter("file", loglevel, aflw)
}
示例2: Init
/*
Init - initialize log lib
RETURNS:
*Logger, nil - if succeed
nil, error - if fail
*/
func (l *Logger) Init() (*Logger, error) {
// check, and create dir if nonexist
if err := logDirCreate(l.logDir); err != nil {
return nil, err
}
// default level: INFO
level := log4go.INFO
if l.enableDebug {
level = log4go.DEBUG
}
// set logger format
logFormat := func(enableDebug bool) string {
if enableDebug {
return log4go.FORMAT_DEFAULT
}
return FORMAT_WITHOUT_SRC
}(l.enableDebug)
// create logger
logger := make(log4go.Logger)
// create writer for stdout
if l.enableStdout {
logger.AddFilter("stdout", level, log4go.NewConsoleLogWriter())
}
// create file writer for all log
fileName := filenameGen(l.progName, l.logDir, false)
logWriter := log4go.NewFileLogWriter(fileName, l.enableRotate)
if l.enableRotate {
logWriter.SetRotateSize(l.rotateSize)
logWriter.SetRotateDaily(true)
}
logWriter.SetFormat(logFormat)
logger.AddFilter("log", level, logWriter)
if l.enableWf {
fileNameWf := filenameGen(l.progName, l.logDir, true)
logWriterWf := log4go.NewFileLogWriter(fileNameWf, l.enableRotate)
if l.enableRotate {
logWriterWf.SetRotateSize(l.rotateSize)
logWriterWf.SetRotateDaily(true)
}
logWriterWf.SetFormat(logFormat)
logger.AddFilter("log_wf", log4go.WARNING, logWriterWf)
}
// set Logger
l.Logger = logger
return l, nil
}
示例3: GetLogger
func GetLogger(path string, level string) *Log {
var log Log
if path == "" {
path = DEFAULT_LOG_PATH
}
lv := log4go.ERROR
switch level {
case "debug":
lv = log4go.DEBUG
case "error":
lv = log4go.ERROR
case "info":
lv = log4go.INFO
}
l := log4go.NewDefaultLogger(lv)
//l.AddFilter("log", lv, log4go.NewFileLogWriter(path, true))
l.AddFilter("log", lv, log4go.NewFileLogWriter(path, false))
log.l = l
return &log
}
示例4: setupLogging
func setupLogging(loggingLevel, logFile string) {
level := log.DEBUG
switch loggingLevel {
case "info":
level = log.INFO
case "warn":
level = log.WARNING
case "error":
level = log.ERROR
}
for _, filter := range log.Global {
filter.Level = level
}
if logFile == "stdout" {
log.AddFilter("stdout", level, log.NewConsoleLogWriter())
} else {
logDir := filepath.Dir(logFile)
if err := os.MkdirAll(logDir, 0744); err != nil {
panic(err)
}
writer := log.NewFileLogWriter(logFile, false)
log.AddFilter("file", level, writer)
writer.SetFormat("[%D %t] [%L] (%S) %M")
writer.SetRotate(true)
writer.SetRotateSize(0)
writer.SetRotateLines(0)
writer.SetRotateDaily(true)
}
}
示例5: main
func main() {
flag.Parse()
log4go.AddFilter("file", log4go.FINEST, log4go.NewFileLogWriter("debug.log", *rotateLog))
defer func() {
py.NewLock()
py.Finalize()
}()
if err := termbox.Init(); err != nil {
log4go.Exit(err)
}
defer func() {
termbox.Close()
log4go.Debug(util.Prof)
if err := recover(); err != nil {
log4go.Crash(err)
}
}()
var t tbfe
t.dorender = make(chan bool, render_chan_len)
t.layout = make(map[*backend.View]layout)
t.loop()
}
示例6: main
func main() {
// Set the static directory for webgo
path := os.Getenv("GOPATH")
if path == "" {
fmt.Println("GOPATH NOT SET")
return
}
filepath := fmt.Sprintf("%s/../frontend/src/", path)
web.Config.StaticDir = filepath
// Setup logging
log := make(l4g.Logger)
// Create a default logger that is logging messages of FINE or higher
l4g.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter("error_log.log", false))
log.Close()
// Setup the DB
db.Init(path)
// Parse command line arguments
port := flag.Int("port", 80, "port number to start the server on")
flag.Parse()
url := fmt.Sprintf("0.0.0.0:%d", *port)
// Start the server!
serve.Routes()
web.Run(url)
}
示例7: setupLogging
func setupLogging(loggingLevel, logFile string) {
level := log.DEBUG
switch loggingLevel {
case "info":
level = log.INFO
case "warn":
level = log.WARNING
case "error":
level = log.ERROR
}
for _, filter := range log.Global {
filter.Level = level
}
logFileDir := filepath.Dir(logFile)
os.MkdirAll(logFileDir, 0744)
flw := log.NewFileLogWriter(logFile, false)
flw.SetFormat("[%D %T] [%L] (%S) %M")
flw.SetRotate(true)
flw.SetRotateSize(0)
flw.SetRotateLines(0)
flw.SetRotateDaily(true)
log.AddFilter("file", level, flw)
log.Info("Redirectoring logging to %s", logFile)
}
示例8: SetupLogging
func SetupLogging(loggingLevel, logFile string) {
level := log.DEBUG
switch loggingLevel {
case "info":
level = log.INFO
case "warn":
level = log.WARNING
case "error":
level = log.ERROR
}
log.Global = make(map[string]*log.Filter)
Global = log.Global
if logFile == "stdout" || logFile == "" {
flw := log.NewConsoleLogWriter()
log.AddFilter("stdout", level, flw)
} else if logFile == "stderr" || logFile == "" {
flw := log.NewConsoleLogWriter()
log.AddFilter("stderr", level, flw)
} else {
logFileDir := filepath.Dir(logFile)
os.MkdirAll(logFileDir, 0744)
flw := log.NewFileLogWriter(logFile, false)
log.AddFilter("file", level, flw)
flw.SetFormat("[%D %T] [%L] (%S) %M")
flw.SetRotate(true)
flw.SetRotateSize(0)
flw.SetRotateLines(0)
flw.SetRotateDaily(true)
}
Global.Info("Redirectoring logging to %s %s", logFile, level)
}
示例9: setLogOutput
func setLogOutput() {
_, err := os.OpenFile(tywa.LOG_FILE, os.O_RDWR, 0666)
if err != nil {
fmt.Println("Unable to open log file. Reason: ", err)
} else {
log.AddFilter("file", log.FINE, log.NewFileLogWriter(tywa.LOG_FILE, false))
}
}
示例10: initLogger
func initLogger() {
logger = make(log4go.Logger)
logger.AddFilter("stdout", log4go.INFO, log4go.NewConsoleLogWriter())
if logFileName := configCommon("log", INFO); logFileName != "" {
logger.AddFilter("file", log4go.INFO, log4go.NewFileLogWriter(logFileName, false).SetFormat("[%D %T][%L]%M - %S"))
}
logger.Info("log module initialized")
}
示例11: NewAgent
func NewAgent(opts Options) *Agent {
log := l4g.NewLogger()
log.AddFilter("file", l4g.DEBUG, l4g.NewFileLogWriter("agent.log", false))
return &Agent{
opts: opts,
exitChan: make(chan bool),
startTime: time.Now(),
clients: make(map[*Client]struct{}, opts.MaxOnlineNum),
Logger: log,
}
}
示例12: main
func main() {
// Get a new logger instance
log := l4g.NewLogger()
// Create a default logger that is logging messages of FINE or higher
log.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter(filename, false))
log.Close()
/* Can also specify manually via the following: (these are the defaults) */
flw := l4g.NewFileLogWriter(filename, false)
flw.SetFormat("[%D %T] [%L] (%S) %M")
flw.SetRotate(false)
flw.SetRotateSize(0)
flw.SetRotateLines(0)
flw.SetRotateDaily(false)
log.AddFilter("file", l4g.FINE, flw)
// Log some experimental messages
log.Finest("Everything is created now (notice that I will not be printing to the file)")
log.Info("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02"))
log.Critical("Time to close out!")
// Close the log
log.Close()
// Print what was logged to the file (yes, I know I'm skipping error checking)
fd, _ := os.Open(filename)
in := bufio.NewReader(fd)
fmt.Print("Messages logged to file were: (line numbers not included)\n")
for lineno := 1; ; lineno++ {
line, err := in.ReadString('\n')
if err == io.EOF {
break
}
fmt.Printf("%3d:\t%s", lineno, line)
}
fd.Close()
// Remove the file so it's not lying around
os.Remove(filename)
}
示例13: InitLogger
func InitLogger(filename string, logFormat string) {
log = make(l4g.Logger)
flw := l4g.NewFileLogWriter(filename, false)
flw.SetFormat(logFormat)
flw.SetRotate(false)
flw.SetRotateSize(0)
flw.SetRotateLines(0)
flw.SetRotateDaily(false)
log.AddFilter("file", l4g.INFO, flw)
//log.LoadConfiguration(filename)
}
示例14: setupLogging
func setupLogging(loggingLevel, logFile string) {
level := log.DEBUG
switch loggingLevel {
case "fine":
level = log.FINE
case "debug":
level = log.DEBUG
case "info":
level = log.INFO
case "warn":
level = log.WARNING
case "error":
level = log.ERROR
default:
log.Error("Unknown log level %s. Defaulting to DEBUG", loggingLevel)
}
log.Global = make(map[string]*log.Filter)
facility, ok := GetSysLogFacility(logFile)
if ok {
flw, err := NewSysLogWriter(facility)
if err != nil {
fmt.Fprintf(os.Stderr, "NewSysLogWriter: %s\n", err.Error())
return
}
log.AddFilter("syslog", level, flw)
} else if logFile == "stdout" {
flw := log.NewConsoleLogWriter()
log.AddFilter("stdout", level, flw)
} else {
logFileDir := filepath.Dir(logFile)
os.MkdirAll(logFileDir, 0744)
flw := log.NewFileLogWriter(logFile, false)
if flw == nil {
os.Exit(1)
}
log.AddFilter("file", level, flw)
flw.SetFormat("[%D %T] [%L] (%S) %M")
flw.SetRotate(true)
flw.SetRotateSize(0)
flw.SetRotateLines(0)
flw.SetRotateDaily(true)
}
log.Info("Redirectoring logging to %s", logFile)
}
示例15: LogTo
func LogTo(target string, verbosity string) {
var writer log.LogWriter = nil
switch target {
case "stdout":
writer = log.NewConsoleLogWriter()
case "none":
// no logging
default:
writer = log.NewFileLogWriter(target, true)
}
if writer != nil {
setupVerbosity(writer, verbosity)
}
}