1

I have some Functions which is written in Go language and I am Exporting those functions to C(Cross Compiling) with the below command which generates .h and .a file go build -buildmode=c-archive -o foo.a and generating the Shared library with the command go build -buildmode=c-shared -o C:\Users\Nems\TestingLogs1\armeabi-v7a\libfoo.so which generates .so file. I am integrating those file in Android studio and the Application is running fine, The problem for me is I want to see the Logging statements(used fmt and log both) of Go file in android studio Logcat.

I tried many ways to display logs of Go in android studio but none of those work for me.

  • Share some code snippets how you are using log in .go files? – Rajat Gupta Apr 04 '23 at 05:11
  • //export StartTunnel func StartTunnel(endpoint string, remotes []string, userId string, tenantId string, proxy string) error { log.Printf("******** Starting Reverse Client Tunnel - v%s, %v ********", shshare.BuildVersion, os.Args) log.Printf("CPC Gateway EP: %s , Remote data: %s", hasConfig.Server, remotes) fmt.Printf("******** Starting Reverse Client Tunnel - endpoint %s, remotes: %s, userId: %s, tenantId: %s, proxy: %s ********", endpoint, remotes, userId, tenantId, proxy) } this are some common log statements which has been used in Go file. – sayed neiman Apr 04 '23 at 05:37

1 Answers1

0

In the end Android requires you to use liblog library. https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/Android.bp

You would have to check how to use it for Go.

A similar answer for NDK would be something like this. https://stackoverflow.com/a/4629747/9458132

Rajat Gupta
  • 419
  • 3
  • 10
  • https://stackoverflow.com/a/4629747/9458132 this is useful for printing logs from inside JNI file, but I want to print logs which is inside the library. – sayed neiman Apr 04 '23 at 05:35