Beispiel #1
0
func (m *MultiLogger) AddLogger(l *log.Logger) {
	m.loggers = append(m.loggers, l)
	//Update the just added logger to be consistent with the style of the
	//rest of the loggers.
	l.SetFlags(m.loggers[0].Flags())
	l.SetPrefix(m.loggers[0].Prefix())
}
Beispiel #2
0
func (ca *CookieAuth) SetLogger(l *log.Logger) {
	if l.Prefix() == "" {
		l.SetPrefix("[" + pkgID + "] ")
	}
	ca.mut.Lock()
	ca.logger = l
	ca.mut.Unlock()
}
Beispiel #3
0
// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output := Config.StringDefault("log."+name+".output", "stderr")
	var newlog revelLogs

	switch output {
	case "stdout":
		newlog = revelLogs{c: colors[name], w: os.Stdout}
		logger = newLogger(&newlog)
	case "stderr":
		newlog = revelLogs{c: colors[name], w: os.Stderr}
		logger = newLogger(&newlog)
	case "off":
		return newLogger(ioutil.Discard)
	default:
		if !filepath.IsAbs(output) {
			output = filepath.Join(BasePath, output)
		}

		logPath := filepath.Dir(output)
		if err := createDir(logPath); err != nil {
			log.Fatalln(err)
		}

		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	if strings.EqualFold(name, "request") {
		logger.SetFlags(0)
		return logger
	}

	// Set the prefix / flags.
	flags, found := Config.Int("log." + name + ".flags")
	if found {
		logger.SetFlags(flags)
	}

	prefix, found := Config.String("log." + name + ".prefix")
	if found {
		logger.SetPrefix(prefix)
	}

	return logger
}
Beispiel #4
0
func StartWorker(CacheInvalidation bool, WorkQueue chan File, log *log.Logger) {
	var err error
	for {
		select {
		case f := <-WorkQueue:
			startTime := time.Now().UTC()

			jobId := "b-" + randomString(5) + " "
			log.SetPrefix(jobId)

			log.Print("Batch process starting: " + f.Tag + ", " + f.Filename)
			// Simulate some processing time
			if f.MediaType() == "image" {
				err = f.GenerateImage(75, 75, true)
				if err != nil {
					log.Print(err)
				}
				err = f.GenerateImage(1140, 0, false)
				if err != nil {
					log.Print(err)
				}

				if CacheInvalidation {
					if err := f.Purge(); err != nil {
						log.Print(err)
					}
				}
			}
			finishTime := time.Now().UTC()
			elapsedTime := finishTime.Sub(startTime)
			log.Println("Completed in: " + elapsedTime.String())
		}
	}
}
Beispiel #5
0
// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output := Config.StringDefault("log."+name+".output", "stderr")

	switch output {
	case "stdout":
		logger = newLogger(os.Stdout)
	case "stderr":
		logger = newLogger(os.Stderr)
	default:
		if output == "off" {
			output = os.DevNull
		}

		dir_path := path.Dir(output)
		_, err := os.Stat(dir_path)
		if os.IsNotExist(err) {
			err = os.MkdirAll(dir_path, 0700)
			if err != nil {
				log.Fatalf("Failed to creating log directory", dir_path, ": ", err)
			}
		}

		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	// Set the prefix / flags.
	flags, found := Config.Int("log." + name + ".flags")
	if found {
		logger.SetFlags(flags)
	}

	prefix, found := Config.String("log." + name + ".prefix")
	if found {
		logger.SetPrefix(prefix)
	}

	return logger
}
Beispiel #6
0
// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output := Config.StringDefault("log."+name+".output", "stderr")
	var newlog revelLogs

	switch output {
	case "stdout":
		newlog = revelLogs{c: colors[name], w: os.Stdout}
		logger = newLogger(&newlog)
	case "stderr":
		newlog = revelLogs{c: colors[name], w: os.Stderr}
		logger = newLogger(&newlog)
	default:
		if output == "off" {
			output = os.DevNull
		}

		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	// Set the prefix / flags.
	flags, found := Config.Int("log." + name + ".flags")
	if found {
		logger.SetFlags(flags)
	}

	prefix, found := Config.String("log." + name + ".prefix")
	if found {
		logger.SetPrefix(prefix)
	}

	return logger
}
Beispiel #7
0
// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output, err := Config.String("log." + name + ".output")
	if err != nil {
		output = "stderr"
	}

	switch output {
	case "stdout":
		logger = newLogger(os.Stdout)
	case "stderr":
		logger = newLogger(os.Stderr)
	default:
		if output == "off" {
			output = os.DevNull
		}

		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	// Set the prefix / flags.
	flags, err := Config.Int("log." + name + ".flags")
	if err == nil {
		logger.SetFlags(flags)
	}

	prefix, err := Config.String("log." + name + ".prefix")
	if err == nil {
		logger.SetPrefix(prefix)
	}

	return logger
}
Beispiel #8
0
// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string, original *log.Logger) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output := Config.StringDefault("log."+name+".output", "")

	switch output {
	case "":
		return original
	case "stdout":
		logger = newLogger(&marsLogs{c: colors[name], w: os.Stdout})
	case "stderr":
		logger = newLogger(&marsLogs{c: colors[name], w: os.Stderr})
	case "off":
		return DisabledLogger
	default:
		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	// Set the prefix / flags.
	flags, found := Config.Int("log." + name + ".flags")
	if found {
		logger.SetFlags(flags)
	}

	prefix, found := Config.String("log." + name + ".prefix")
	if found {
		logger.SetPrefix(prefix)
	}

	return logger
}
Beispiel #9
0
func StartWorker(WorkQueue chan File, log *log.Logger) {
	for {
		select {
		case f := <-WorkQueue:
			startTime := time.Now().UTC()

			jobId := "b-" + randomString(5) + " "
			log.SetPrefix(jobId)

			log.Print("Batch process starting: " + f.Tag + ", " + f.Filename)
			// Simulate some processing time
			if f.MediaType() == "image" {
				err := f.GenerateThumbnail()
				if err != nil {
					log.Print(err)
				}
			}
			finishTime := time.Now().UTC()
			elapsedTime := finishTime.Sub(startTime)
			log.Println("Completed in: " + elapsedTime.String())
		}
	}
}
Beispiel #10
0
func Test(l log.Logger) {
	l.SetPrefix("pak")
	l.Println("test from pak")
}
Beispiel #11
0
func (l Logger) updateLogger(logger *log.Logger, tag string) *log.Logger {
	prefix := fmt.Sprintf("[%s] ", tag)
	logger.SetPrefix(prefix)
	return logger
}
Beispiel #12
0
func logOut(logger *log.Logger, level string, r *http.Request, format string, v ...interface{}) {
	logger.SetPrefix(fmt.Sprintf("[%6s] %s ", level, reqID(r)))
	logger.Output(3, fmt.Sprintf(format, v...))
}