@driffel/universal-google-logger
Advanced tools
Comparing version 0.6.0 to 0.6.1
{ | ||
"name": "@driffel/universal-google-logger", | ||
"version": "0.6.0", | ||
"description": "", | ||
"version": "0.6.1", | ||
"description": "Log across Google Cloud (eg: GCE VMs, Firebase Functions) using one library.", | ||
"main": "./dist/index.js", | ||
@@ -6,0 +6,0 @@ "module": "./dist/index.mjs", |
# Universal Google Logger | ||
⏩ Use the same library to log across GCE VMs, Firebase Functions, etc. | ||
Use the same library to log across GCE VMs, Firebase Functions, etc. | ||
⏩ Makes sharing common code across environments easier. | ||
Makes sharing common code across environments easier. | ||
Usage with default logger instance: | ||
## Usage: | ||
``` | ||
### Configuration | ||
[View optional env configs](#environment-variable-configs-all-optional) | ||
### Code | ||
#### Usage with default logger instance: | ||
```javascript | ||
/** | ||
@@ -18,26 +26,27 @@ * Import method directly from default logger instance. | ||
*/ | ||
import {info} from "@driffel/universal-google-logger"; | ||
import { info } from "@driffel/universal-google-logger"; | ||
info("Text payload") | ||
info({someField: "JSON payload"}) | ||
info("Text payload"); | ||
info({ someField: "JSON payload" }); | ||
``` | ||
Usage with custom instance: | ||
#### Usage with custom instance: | ||
``` | ||
import {UniversalGoogleLogger} from "@driffel/universal-google-logger"; | ||
```javascript | ||
import { UniversalGoogleLogger } from "@driffel/universal-google-logger"; | ||
const customLogger = new UniversalGoogleLogger("Custom logger name"); | ||
customLogger.info("Text payload") | ||
customLogger.info({someField: "JSON payload"}) | ||
customLogger.info("Text payload"); | ||
customLogger.info({ someField: "JSON payload" }); | ||
``` | ||
Usage with trace-aware Express middleware: | ||
#### Usage with trace-aware Express middleware: | ||
``` | ||
import {attachContextWithTraceState} from "@driffel/universal-google-logger"; | ||
```javascript | ||
import { attachContextWithTraceState } from "@driffel/universal-google-logger"; | ||
const app = express().use(attachContextWithTraceState({rethrowExceptions: false})); | ||
const app = express().use( | ||
attachContextWithTraceState({ rethrowExceptions: false }) | ||
); | ||
``` | ||
@@ -64,5 +73,5 @@ | ||
This library wraps the functionality of `@google-cloud/logging` library and fills the gaps in metadata wherever available from google-provided environent variables or, if needed, the metadata server. It also propagates the correct severity levels, since it leverages google's logging library directly. | ||
This library wraps functionality of the `@google-cloud/logging` library and fills gaps in the metadata wherever available from google-provided environent variables or, if needed, the metadata server. It also propagates the correct severity levels, since it leverages google's logging library directly. | ||
There are also helper functions for including the `trace` metadata field which enables the "Show entries for this trace" feature that groups entries in Logs Explorer. This is done by leveraging [AsyncLocalStorage](https://nodejs.org/api/async_context.html#class-asynclocalstorage) to retain trace state through the call stack. | ||
There are also helper functions for including the `trace` metadata field which enables the "Show entries for this trace" feature that groups entries in the Logs Explorer. This is done by leveraging [AsyncLocalStorage](https://nodejs.org/api/async_context.html#class-asynclocalstorage) to retain trace state through the call stack. | ||
@@ -82,4 +91,4 @@ ### Environment variable configs (all optional): | ||
A single **synchronous** API call, if necessary, is made in the very beginning upon file import. This is to load the project ID in the event that it's not provided by an expected environment variable (`PROJECT_STRING_ID`, `GCLOUD_PROJECT`, or `GOOGLE_CLOUD_PROJECT`). | ||
A single **synchronous** (aka: blocking) API call, if necessary, is made in the very beginning upon file import. This is to load the project ID in the event that it's not provided by an expected environment variable (`PROJECT_STRING_ID`, `GCLOUD_PROJECT`, or `GOOGLE_CLOUD_PROJECT`). | ||
Although blocking requests are typically frowned upon, this was considered the lesser of two evils compared to the increased complexity of guaranteeing the required field is loaded asynchronously before it's needed. It should not cause any perfomance issues, as it only blocks one time, in the very beginning upon file import. The call can be entirely avoided as well, by manually populating `PROJECT_STRING_ID`. | ||
Although blocking requests are typically considered poor practice, this was preferred to the complexity of guaranteeing the required field is loaded asynchronously before it's needed. It should not cause any perfomance issues, as it only blocks a single time, in the very beginning on initial file import. The call can be entirely avoided as well, by manually populating the `PROJECT_STRING_ID` environment variable. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60424
92