An IO device for use with LoggerJSON to write log entries to GCP Cloud Logging via elixir-google-api.
Usually used for applications running somewhere else.
First, add the dependency to your project.
def deps do
[
{:logger_gcp, "~> 0.2"}
]
end
LoggerJSON 5.x will come with. Follow instructions for setting up LoggerJSON in the manner you desire, but note the following:
LoggerGCP
must be set as LoggerJSON's backend device- LoggerGCP will set LoggerJSON to use its GoogleCloudLogger formatter
The config should look something like this, for whichever environment you want to log to Google:
config :logger_json, :backend, device: LoggerGCP, metadata: :all
config :logger, backends: [LoggerJSON]
Then, configure LoggerGCP as follows.
Variable | Description |
---|---|
LOGGER_GCP_CREDENTIALS |
GCP Service Account JSON |
LOGGER_GCP_LOCATION |
Location value |
LOGGER_GCP_LOG_ID |
Log ID value |
LOGGER_GCP_NAMESPACE |
Namespace value |
LOGGER_GCP_NODE_ID |
Node ID value |
LOGGER_GCP_PROJECT_ID |
Project ID value |
All keys should be set for :logger_gcp
application.
Variable | Description |
---|---|
:credentials |
GCP Service Account JSON |
:location |
Location value |
:log_id |
Log ID value |
:namespace |
Namespace value |
:node_id |
Node ID value |
:project_id |
Project ID value |
This value may be:
- a String path to a file with JSON contents (usually downloaded from GCP console)
- the JSON content of the client_secret file (in the case of environment variable) e.g.
export LOGGER_GCP_CREDENTIALS=$(cat secret.json)
- a map as decoded from the JSON content of the client_secret file (in the case of config value) e.g.
config :logger_gcp, :credentials, %{
"type" => "service_account",
...
}
- See:
config/test.exs
export LOGGER_GCP_CREDENTIALS=/app/bin/example-project.client_secret.json
export LOGGER_GCP_LOCATION=Earth
export LOGGER_GCP_LOG_ID=example-id
export LOGGER_GCP_NAMESPACE=example-namespace
export LOGGER_GCP_NODE_ID=example-node-id
export LOGGER_GCP_PROJECT_ID=example-project-id