Example #1
0
// Output -> log.Output
func (this *Logger) Output(calldepth int, s string) error {
	if this == nil {
		return log.Output(calldepth, s)
	}
	this.Calls++
	return this.Logger.Output(calldepth, s)
}
Example #2
0
func (r *Run) RenderSVG(out io.Writer) {
	const (
		size = 600 // image canvas
	)
	s := svg.New(out)
	s.Start(size, size)
	s.Circle(250, 250, 125, "fill:none;stroke:black")

	for idx, _ := range *r.bodies {

		body := (*r.bodies)[idx]
		bodyOrig := (*r.bodiesOrig)[idx]

		Info.Printf("Encoding body %d %f %f\n", idx, body.X, body.Y)

		// take into account rendering window
		var imX, imY float64
		if r.renderChoice == RUNNING_CONFIGURATION {
			imX = (body.X - r.xMin) / (r.xMax - r.xMin)
			imY = (body.Y - r.yMin) / (r.yMax - r.yMin)
		} else {
			// we display the original
			imX = (bodyOrig.X - r.xMin) / (r.xMax - r.xMin)
			imY = (bodyOrig.Y - r.yMin) / (r.yMax - r.yMin)
		}
		// if( (body.X > r.xMin) && (body.X < r.xMax) && (body.Y > r.yMin) && (body.Y < r.yMax) ) {
		if (imX > 0.0) && (imX < 1.0) && (imY > 0.0) && (imY < 1.0) {

			// check wether body is on a border
			isOnBorder := false
			coordX := body.X * float64(nbVillagePerAxe)
			distanceToBorderX := coordX - math.Floor(coordX)
			if distanceToBorderX < ratioOfBorderVillages/2.0 {
				isOnBorder = true
			}
			if distanceToBorderX > 1.0-ratioOfBorderVillages/2.0 {
				isOnBorder = true
			}

			coordY := body.Y * float64(nbVillagePerAxe)
			distanceToBorderY := coordY - math.Floor(coordY)
			if distanceToBorderY < ratioOfBorderVillages/2.0 {
				isOnBorder = true
			}
			if distanceToBorderY > 1.0-ratioOfBorderVillages/2.0 {
				isOnBorder = true
			}

			if isOnBorder && r.renderState == WITH_BORDERS {
				s.Circle(imX*size, imY*size, 0.1, "fill:none;stroke:red")
			} else {
				s.Circle(imX*size, imY*size, 0.1, "fill:none;stroke:black")
			}
		}
	}
	s.End()
	log.Output(1, fmt.Sprintf("end of render SVG"))
}
Example #3
0
File: log.go Project: sknop/direnv
func log_debug(msg string, a ...interface{}) {
	if !debugging {
		return
	}
	defer log.SetFlags(log.Flags())
	log.SetFlags(log.Flags() | log.Lshortfile)
	msg = fmt.Sprintf(msg, a...)
	log.Output(2, msg)
}
Example #4
0
func main() {
	const host string = "localhost"
	const port string = "80"
	http.Handle("/", http.FileServer(http.Dir(".")))
	// if there's a file named "index.hmtl" in this directory (".")
	// then the above code will show it, otherwise it will list the directory files
	fmt.Printf("Listening on %s ...\n", host+":"+port)
	log.Output(http.ListenAndServe(host+":"+port, nil))
}
Example #5
0
func Logf(ctx context.Context, format string, args ...interface{}) context.Context {
	ctx, l := GetContextWithLog(ctx)
	log.Output(2, fmt.Sprintf(format, args...))
	l.Log = append(l.Log, &oproto.LogMessage{
		Message:   fmt.Sprintf(format, args...),
		Timestamp: uint64(time.Now().UnixNano()),
	})
	return ctx
}
Example #6
0
func main() {
	defer handleExit() // plug the exit handler

	log.Print("Hello, log file!")
	log.Output(1, "this is an event")

	logger.Print("Hello, log file!")
	logger.Output(1, "this is an event")

	//panic(Exit{3}) // 3 is the exit code
}
Example #7
0
func (t *Timer) Stop() uint64 {
	duration := uint64(time.Since(t.startTime).Nanoseconds())
	if t.ctx != nil {
		_, l := GetContextWithLog(t.ctx)
		l.Log = append(l.Log, &oproto.LogMessage{
			Message:      fmt.Sprintf("%s: %s", t.message, time.Since(t.startTime).String()),
			Timestamp:    uint64(t.startTime.UnixNano()),
			EndTimestamp: uint64(time.Now().UnixNano()),
		})
		log.Output(2, fmt.Sprintf("%s: %s", t.message, time.Since(t.startTime).String()))
	}
	return duration
}
Example #8
0
func main() {
	// open a file
	f, err := os.OpenFile("LogToFile.log", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		log.Printf("error opening file: %v", err)
	}

	// don't forget to close it
	defer f.Close()

	// assign it to the standard logger
	log.SetOutput(f)

	log.Output(1, "this is an event")

}
Example #9
0
File: funcs.go Project: ohko/gmdd
// debug info
//  0 = Debug
//  1 = Info
//  2 = Warning
//  3 = Error
//  4 = Fatal
func Debug(no int64, msg ...interface{}) {
	i, _ := strconv.ParseInt(Conf["DEBUG"], 10, 64)
	if no < i {
		return
	}
	switch no {
	case DEBUG_TRACE:
		log.SetPrefix("T2 ")
	case DEBUG_DEBUG:
		log.SetPrefix("D3 ")
	case DEBUG_INFO:
		log.SetPrefix("I4 ")
	case DEBUG_WARN:
		log.SetPrefix("W5 ")
	case DEBUG_ERROR:
		log.SetPrefix("E6 ")
	default:
		log.SetPrefix("- ")
	}

	log.SetFlags(log.Llongfile | log.Ldate | log.Ltime)
	log.Output(2, fmt.Sprint(msg))
}
Example #10
0
File: log.go Project: ohko/gmvc
// debug info
//  1 = Off
//  2 = Debug
//  3 = Info
//  4 = Warning
//  5 = Error
//  6 = Fatal
func (this *Gmvc) Log(level int64, msg ...interface{}) {
	ll, _ := strconv.ParseInt(Options.LogLevel, 10, 64)
	if level < ll {
		return
	}
	switch level {
	case DEBUG_DEBUG:
		log.SetPrefix("D2 ")
	case DEBUG_INFO:
		log.SetPrefix("I3 ")
	case DEBUG_WARN:
		log.SetPrefix("W4 ")
	case DEBUG_ERROR:
		log.SetPrefix("E5 ")
	case DEBUG_FATAL:
		log.SetPrefix("F6 ")
	default:
		log.SetPrefix("- ")
	}

	log.SetFlags(log.Llongfile | log.Ldate | log.Ltime)
	log.Output(2, fmt.Sprint(msg))
}
Example #11
0
File: irc.go Project: sztanpet/sirc
func debug(format string, v ...interface{}) {
	if DebuggingEnabled {
		log.Output(2, fmt.Sprintf(format, v...))
	}
}
Example #12
0
func logErr(err error, format string, args ...interface{}) {
	if err != nil {
		args = append(args, err)
		log.Output(2, fmt.Sprintf(format, args...))
	}
}
Example #13
0
File: log.go Project: rs/rest-layer
// Log levels
const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelFatal
)

// LoggerLevel sets the logging level of the framework.
var LoggerLevel = LogLevelInfo

// Logger is the function used by rest-layer to log messages. By default
// it does nothing but you can customize it to plug any logger.
var Logger = func(ctx context.Context, level LogLevel, msg string, fields map[string]interface{}) {
	log.Output(2, msg)
}

func logErrorf(ctx context.Context, format string, a ...interface{}) {
	if LoggerLevel <= LogLevelError && Logger != nil {
		Logger(ctx, LogLevelError, fmt.Sprintf(format, a...), nil)
	}
}

func logPanicf(ctx context.Context, format string, a ...interface{}) {
	msg := fmt.Sprintf(format, a...)
	if LoggerLevel <= LogLevelFatal && Logger != nil {
		Logger(ctx, LogLevelFatal, msg, nil)
	}
	panic(msg)
}
Example #14
0
func handleErr(err error) {
	if err != nil {
		log.Output(2, err.Error())
		os.Exit(1)
	}
}
Example #15
0
func logPrintf(format string, v ...interface{}) {
	if DebugLog {
		log.Output(3, fmt.Sprintf(format, v...))
	}
}
Example #16
0
func logPrintln(v ...interface{}) {
	if DebugLog {
		log.Output(3, fmt.Sprintln(v...))
	}
}