1.0.11 • Published 3 years ago

gcp-logger-wrapper v1.0.11

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

GCP Logger

What?

This is a small wrapper around the gcp logger client library enabling a simpler interface to the logging client.

Why?

The logger from gcp required configuration and setup that can be normalized and abstracted away. When using cloudfunctions we want the logs to be normalized and reduce the overhead of creating and using them.

How?

You need to have (set up authentication)https://cloud.google.com/docs/authentication/production for a service account permitted to read and write logs.

import {createLogger, Logger} from "./index";

logger: Logger = createLogger(
    "my-project",  // <- gcp proiject id
    "my-cloud-function-logger"  // <- logger name
) 
    .setResourceType("cloud_function") // <- resource type
    .addLabel("eventId", context.eventId) // <- add a value to the log entry label 
    .mergeToResourceLabels({
        function_name: "my-function",
    }); // <- add a value to the log entry resource label

if (process.env.ENV === "local") {
    logger.enableConsoleLogging(); // <- will pipe logs to the console in addition to the google log explorer
}
1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago