The user with no hat
The user with no hat

Reputation: 10856

Is it possible to get the log point on GAE?

I'm wondering if it's possible to log the line/column number when i log an error. The GAE logging lib seems to store only the error message but I think it would be quite valuable to get the exact location of the error/log point like most logging libraries do.

Upvotes: 0

Views: 115

Answers (2)

themihai
themihai

Reputation: 8651

You can use the runtime package to trace the caller(I assume that's basically what you want). There is no GAE specific issue and it has nothing to do with the error handling.

   // The depth specifies how many stack frames above 
   // lives the source line to be identified in the log message.
    func traceCaller(depth int)(string, int){
    _, file, line, ok := runtime.Caller(2 + depth)
        if !ok {
            file = "???"
            line = 1
        } else {
            slash := strings.LastIndex(file, "/")
            if slash >= 0 {
                file = file[slash+1:]
            }
        }
        return file, line
}

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 882571

What you request is definitely possible, you just need to be very explicit about it! I recommend Andrew Gerrand's excellent article at http://blog.golang.org/error-handling-and-go for general information on the issue, including notes specific to App Engine.

That article does not specifically address stack traces, but of course you could do those yourself, via http://golang.org/pkg/runtime/#Stack .

Let's be honest and admit that Go -- being by design more of a system-programming language than of an application-focused one -- doesn't do quite as much implicit, automatic hand-holding for you, as more app-oriented languages such as the other App Engine ones -- Java, Python, PHP... [*] but, Go does give you all the tools you need to do just as little, or as much, "supporting infrastructure", as you desire to have in support of your own apps!-)

[*] hey, you don't even get automatically by-default propagating exceptions, as you do for other languages -- nay, you're responsible for catching and dealing with errors yourself, oh the horror...!-)

Upvotes: 1

Related Questions