GCP Cloud Logging logger, for Golang.
The idea behind this package is to provide the simplest way to log messages to Google Cloud Logging, without having to worry about the details of setting up the Google Cloud Logging client and/or affecting the current application structure.
go get github.com/qurami/gcp-lolo-go
This package works in combination with logrus, as follows:
// Create a new logrus logger
logger := logrus.New()
// Set the log level (optional)
logger.SetLevel(logrus.InfoLevel)
// Create a new GCP hook
logger, err := gcplologo.SetupGCPLogging("your-project-id", "your-logger-name")
if err != nil {
log.Fatalf("Failed to create GCP hook: %v", err)
}
// Use the logger
logger.Info("This is an info message")
Please refer to the included demo application for a complete example.
As the package exports logs on GCP Logging, you need some GCP credentials. You can provide them in the following ways:
- By setting either one of the following environment variables:
GOOGLE_APPLICATION_CREDENTIALS
: the path to the local GCP credentials file, orGCP_CREDENTIALS_JSON
: a string containing the GCP credentials JSON
- By running the application within an environment that has the GCP credentials set up (e.g. a GCP VM, GCP Cloud Run, etc.)
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.