appengine golang logs

171 views
Skip to first unread message

Sankar

unread,
Nov 3, 2017, 3:58:34 AM11/3/17
to golang-nuts
Hi


I have a golang file where I have code like:


log.Fatal("My error message: ", err)


When the above statement is executed, In the appengine logviewer, I get something like:

panic: os.Exit called goroutine 1 [running]:
os.Exit(0x1)
go/src/os/proc.go:58 +0x7c log.Fatal(0xc008549f60, 0x2, 0x2)
go/src/log/log.go:303 +0x79 main.main()
main.go:42 +0x201

But I dont get any error message. The main.go:42 corresponds to the log.Fatal line in my code but I do not get to see the error message that is printed as part of the log statement.

I see that appengine package has a "Log" function which may print the AppLogs such that they can be viewed from the Google Appengine log console itself.

My question is, can the golang default log package be somehow instructed to redirect to appengine ? Something like:

if env == "AppEngine" {
  log.SetOutput(appengine.DefaultLogger) 
}

in my main file ? This way, I get to make my code not locked to google cloud and also can deploy existing code which uses log already.

Any pointers ?

Thanks.

Jim Cote

unread,
Nov 3, 2017, 1:47:13 PM11/3/17
to golang-nuts
In appengine you have to use google.golang.org/appengine/log package.  The log calls must have a context passed to it.

Sankar P

unread,
Nov 3, 2017, 10:59:38 PM11/3/17
to Jim Cote, golang-nuts
I knew about this package. I mentioned about this in my mail itself :-) 

I wanted a different way as it is not always possible to replace "log" calls in all the existing code. Some libraries need to be used in binaries which will be deployed outside appengine. They should not have a dependency on appengine libraries ideally.


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/XbhcR5eFdno/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Tamás Gulácsi

unread,
Nov 4, 2017, 2:14:25 AM11/4/17
to golang-nuts
Use log.SetWriter to divert log calls to appenginelog, if deployed there.

Sankar P

unread,
Nov 4, 2017, 3:11:27 AM11/4/17
to Tamás Gulácsi, golang-nuts
There is no log.SetWriter in either the builtin log package or the appengine log package. There is a log.SetOutput which I mentioned in my original mail, but I am not able to understand how to connect it to the appengine logs.

2017-11-04 11:44 GMT+05:30 Tamás Gulácsi <tgula...@gmail.com>:
Use log.SetWriter to divert log calls to appenginelog, if deployed there.
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/XbhcR5eFdno/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gulácsi Tamás

unread,
Nov 4, 2017, 3:17:50 AM11/4/17
to Sankar P, golang-nuts

Sankar P <sankar.c...@gmail.com> ezt írta (időpont: 2017. nov. 4., Szo, 8:10):
There is no log.SetWriter in either the builtin log package or the appengine log package. There is a log.SetOutput which I mentioned in my original mail, but I am not able to understand how to connect it to the appengine logs.
2017-11-04 11:44 GMT+05:30 Tamás Gulácsi <tgula...@gmail.com>:
Use log.SetWriter to divert log calls to appenginelog, if deployed there.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/XbhcR5eFdno/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Sankar P

unread,
Nov 4, 2017, 3:26:52 AM11/4/17
to Gulácsi Tamás, golang-nuts
Tried something similar already. 

context.Background() does not work with the appengine log package and panics at runtime. Passing nil also did not work.

Probably initialising the AELogAdapter with a ctx from appengine request, in the _ah start handler is the only way. Thanks for the idea.

I, for one, though wish that there was a simpler way. 

2017-11-04 12:47 GMT+05:30 Gulácsi Tamás <tgula...@gmail.com>:
Sankar P <sankar.c...@gmail.com> ezt írta (időpont: 2017. nov. 4., Szo, 8:10):
There is no log.SetWriter in either the builtin log package or the appengine log package. There is a log.SetOutput which I mentioned in my original mail, but I am not able to understand how to connect it to the appengine logs.
2017-11-04 11:44 GMT+05:30 Tamás Gulácsi <tgula...@gmail.com>:
Use log.SetWriter to divert log calls to appenginelog, if deployed there.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/XbhcR5eFdno/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

David Arroyo

unread,
Nov 4, 2017, 3:36:36 AM11/4/17
to golan...@googlegroups.com
Sankar,

Have you tried using the Flexible environment? Flex provides a more "conventional" environment for your programs. There are some tradeoffs compared with App Engine Standard, but it should be easier to stay portable.

David

You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Sankar P

unread,
Nov 4, 2017, 3:43:57 AM11/4/17
to David Arroyo, golang-nuts
Thanks. I did not know this. I assumed that the only difference between flexible and standard was the pricing, I was wrong. Thanks for the link.

To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/XbhcR5eFdno/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages