Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/logging-bunyan

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/logging-bunyan - npm Package Compare versions

Comparing version 0.10.1 to 1.0.0

4

build/src/index.d.ts

@@ -128,3 +128,3 @@ /*!

*/
_write(record: types.BunyanLogRecord, encoding?: string, callback?: Function): void;
_write(record: types.BunyanLogRecord, encoding: string, callback: Function): void;
/**

@@ -137,3 +137,3 @@ * Relay an array of log entries to the logging agent. This is called by

encoding: string;
}>, callback?: Function): void;
}>, callback: Function): void;
}

@@ -21,3 +21,3 @@ "use strict";

exports.express = express;
const { Logging } = require('@google-cloud/logging');
const { Logging, detectServiceContext } = require('@google-cloud/logging');
// Map of Stackdriver logging levels.

@@ -135,3 +135,3 @@ const BUNYAN_TO_STACKDRIVER = new Map([

this.serviceContext = options.serviceContext;
this.stackdriverLog = (new Logging(options)).log(this.logName, {
this.stackdriverLog = new Logging(options).log(this.logName, {
removeCircular: true,

@@ -150,2 +150,10 @@ });

}
/* Asynchrnously attempt to discover the service context. */
if (!this.serviceContext) {
detectServiceContext(this.stackdriverLog.logging.auth).then((serviceContext) => {
this.serviceContext = serviceContext;
}, () => {
/* swallow any errors. */
});
}
}

@@ -189,3 +197,3 @@ /**

timestamp: record.time,
severity: BUNYAN_TO_STACKDRIVER.get(Number(record.level))
severity: BUNYAN_TO_STACKDRIVER.get(Number(record.level)),
};

@@ -192,0 +200,0 @@ // If the record contains a httpRequest property, provide it on the entry

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -34,43 +26,44 @@ /*!

*/
function middleware(options) {
return __awaiter(this, void 0, void 0, function* () {
const defaultOptions = { logName: 'bunyan_log', level: 'info' };
options = Object.assign({}, defaultOptions, options);
const loggingBunyanApp = new index_1.LoggingBunyan(Object.assign({}, options, {
// For request bundling to work, the parent (request) and child (app) logs
// need to have distinct names. For exact requirements see:
// https://cloud.google.com/appengine/articles/logging#linking_app_logs_and_requests
logName: `${options.logName}_${exports.APP_LOG_SUFFIX}`
}));
const logger = bunyan.createLogger({
name: `${options.logName}_${exports.APP_LOG_SUFFIX}`,
streams: [loggingBunyanApp.stream(options.level)]
async function middleware(options) {
const defaultOptions = { logName: 'bunyan_log', level: 'info' };
options = Object.assign({}, defaultOptions, options);
const loggingBunyanApp = new index_1.LoggingBunyan(Object.assign({}, options, {
// For request bundling to work, the parent (request) and child (app) logs
// need to have distinct names. For exact requirements see:
// https://cloud.google.com/appengine/articles/logging#linking_app_logs_and_requests
logName: `${options.logName}_${exports.APP_LOG_SUFFIX}`,
}));
const logger = bunyan.createLogger({
name: `${options.logName}_${exports.APP_LOG_SUFFIX}`,
streams: [loggingBunyanApp.stream(options.level)],
});
const auth = loggingBunyanApp.stackdriverLog.logging.auth;
const [env, projectId] = await Promise.all([
auth.getEnv(),
auth.getProjectId(),
]);
// Unless we are running on Google App Engine or Cloud Functions, generate a
// parent request log entry that all the request-specific logs ("app logs")
// will nest under. GAE and GCF generate the parent request logs
// automatically.
let emitRequestLog;
if (env !== google_auth_library_1.GCPEnv.APP_ENGINE && env !== google_auth_library_1.GCPEnv.CLOUD_FUNCTIONS) {
const loggingBunyanReq = new index_1.LoggingBunyan(options);
const requestLogger = bunyan.createLogger({
name: options.logName,
streams: [loggingBunyanReq.stream(options.level)],
});
const auth = loggingBunyanApp.stackdriverLog.logging.auth;
const [env, projectId] = yield Promise.all([auth.getEnv(), auth.getProjectId()]);
// Unless we are running on Google App Engine or Cloud Functions, generate a
// parent request log entry that all the request-specific logs ("app logs")
// will nest under. GAE and GCF generate the parent request logs
// automatically.
let emitRequestLog;
if (env !== google_auth_library_1.GCPEnv.APP_ENGINE && env !== google_auth_library_1.GCPEnv.CLOUD_FUNCTIONS) {
const loggingBunyanReq = new index_1.LoggingBunyan(options);
const requestLogger = bunyan.createLogger({
name: options.logName,
streams: [loggingBunyanReq.stream(options.level)]
});
emitRequestLog = (httpRequest, trace) => {
requestLogger.info({ [index_1.LOGGING_TRACE_KEY]: trace, httpRequest });
};
}
return {
logger,
mw: logging_1.middleware.express.makeMiddleware(projectId, makeChildLogger, emitRequestLog)
emitRequestLog = (httpRequest, trace) => {
requestLogger.info({ [index_1.LOGGING_TRACE_KEY]: trace, httpRequest });
};
function makeChildLogger(trace) {
return logger.child({ [index_1.LOGGING_TRACE_KEY]: trace }, true /* simple child */);
}
});
}
return {
logger,
mw: logging_1.middleware.express.makeMiddleware(projectId, makeChildLogger, emitRequestLog),
};
function makeChildLogger(trace) {
return logger.child({ [index_1.LOGGING_TRACE_KEY]: trace }, true /* simple child */);
}
}
exports.middleware = middleware;
//# sourceMappingURL=express.js.map

@@ -7,2 +7,24 @@ # Changelog

## [1.0.0](https://www.github.com/googleapis/nodejs-logging-bunyan/compare/v0.10.1...v1.0.0) (2019-05-29)
### ⚠ BREAKING CHANGES
* upgrade engines field to >=8.10.0 (#298)
### Bug Fixes
* proper signature for _write[v] ([#287](https://www.github.com/googleapis/nodejs-logging-bunyan/issues/287)) ([8bb305a](https://www.github.com/googleapis/nodejs-logging-bunyan/commit/8bb305a))
* **deps:** update dependency google-auth-library to v4 ([#308](https://www.github.com/googleapis/nodejs-logging-bunyan/issues/308)) ([e309b7c](https://www.github.com/googleapis/nodejs-logging-bunyan/commit/e309b7c))
### Build System
* upgrade engines field to >=8.10.0 ([#298](https://www.github.com/googleapis/nodejs-logging-bunyan/issues/298)) ([143933c](https://www.github.com/googleapis/nodejs-logging-bunyan/commit/143933c))
### Features
* auto-detect service context ([#290](https://www.github.com/googleapis/nodejs-logging-bunyan/issues/290)) ([595a4db](https://www.github.com/googleapis/nodejs-logging-bunyan/commit/595a4db))
## v0.10.1

@@ -195,2 +217,1 @@

- chore: the ultimate fix for repo-tools EPERM (#64)
{
"name": "@google-cloud/logging-bunyan",
"description": "Stackdriver Logging stream for Bunyan",
"version": "0.10.1",
"version": "1.0.0",
"license": "Apache-2.0",
"author": "Google Inc.",
"engines": {
"node": ">=6.0.0"
"node": ">=8.10.0"
},

@@ -56,8 +56,8 @@ "repository": "googleapis/nodejs-logging-bunyan",

"dependencies": {
"@google-cloud/logging": "^4.1.0",
"google-auth-library": "^3.1.0"
"@google-cloud/logging": "^5.0.0",
"google-auth-library": "^4.0.0"
},
"devDependencies": {
"@google-cloud/common": "^0.31.0",
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"@google-cloud/common": "^2.0.0",
"@google-cloud/nodejs-repo-tools": "^3.3.0",
"@types/bunyan": "^1.8.4",

@@ -68,5 +68,3 @@ "@types/express": "^4.16.0",

"@types/proxyquire": "^1.3.28",
"@types/request": "^2.48.1",
"@types/uuid": "^3.4.4",
"linkinator": "^1.1.2",
"bunyan": "^1.8.12",

@@ -78,11 +76,12 @@ "codecov": "^3.0.2",

"eslint-config-prettier": "^4.0.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-node": "^9.0.0",
"eslint-plugin-prettier": "^3.0.0",
"express": "^4.16.3",
"gts": "^0.9.0",
"gts": "^1.0.0",
"intelli-espower-loader": "^1.0.1",
"jsdoc": "^3.5.5",
"jsdoc-baseline": "git+https://github.com/hegemonic/jsdoc-baseline.git",
"mocha": "^6.0.0",
"nyc": "^13.0.0",
"jsdoc": "^3.6.2",
"jsdoc-baseline": "^0.1.0",
"linkinator": "^1.1.2",
"mocha": "^6.1.4",
"nyc": "^14.0.0",
"post-install-check": "0.0.1",

@@ -93,4 +92,3 @@ "power-assert": "^1.6.0",

"source-map-support": "^0.5.6",
"teeny-request": "^3.11.0",
"typescript": "~3.3.0",
"typescript": "~3.5.0",
"uuid": "^3.3.2"

@@ -97,0 +95,0 @@ },

@@ -0,17 +1,22 @@

[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `python -m synthtool`."
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
# [Stackdriver Logging for Bunyan](https://github.com/googleapis/nodejs-logging-bunyan)
This module provides an easy to use, higher-level layer for working with [Stackdriver Logging](https://cloud.google.com/logging/docs),
compatible with [Bunyan](https://www.npmjs.com/package/bunyan). Simply attach this as a transport to your existing Bunyan loggers.
[![release level](https://img.shields.io/badge/release%20level-beta-yellow.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)
[![release level](https://img.shields.io/badge/release%20level-beta-yellow.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
[![npm version](https://img.shields.io/npm/v/@google-cloud/logging-bunyan.svg)](https://www.npmjs.org/package/@google-cloud/logging-bunyan)
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-logging-bunyan/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-logging-bunyan)
This module provides an easy to use, higher-level layer for working with
[Stackdriver Logging](https://cloud.google.com/logging/docs), compatible with
[Bunyan](https://www.npmjs.com/package/bunyan). Simply attach this as a
transport to your existing Bunyan loggers.
* [Stackdriver Logging for Bunyan API Reference][client-docs]
Stackdriver Logging stream for Bunyan
* [Stackdriver Logging for Winston Node.js Client API Reference][client-docs]
* [Stackdriver Logging for Winston Documentation][product-docs]
* [github.com/googleapis/nodejs-logging-bunyan](https://github.com/googleapis/nodejs-logging-bunyan)
* [Logging Documentation][product-docs]

@@ -25,2 +30,3 @@ Read more about the client libraries for Cloud APIs, including the older

* [Quickstart](#quickstart)

@@ -39,28 +45,14 @@ * [Before you begin](#before-you-begin)

1. Select or create a Cloud Platform project.
[Go to the projects page][projects]
1. Enable billing for your project.
[Enable billing][billing]
1. Enable the Stackdriver Logging API.
[Enable the API][enable_api]
1. [Select or create a Cloud Platform project][projects].
1. [Enable the Stackdriver Logging for Winston API][enable_api].
1. [Set up authentication with a service account][auth] so you can access the
API from your local workstation.
[projects]: https://console.cloud.google.com/project
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=logging.googleapis.com
[auth]: https://cloud.google.com/docs/authentication/getting-started
### Installing the client library
For a more detailed Stackdriver Logging setup guide, see https://cloud.google.com/logging/docs/setup/nodejs.
```bash
npm install @google-cloud/logging-bunyan
```
### Installing the client library
npm install --save @google-cloud/logging-bunyan
### Using the client library

@@ -71,3 +63,3 @@

// Imports the Google Cloud client library for Bunyan (Node 6+)
// Imports the Google Cloud client library for Bunyan
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');

@@ -84,8 +76,6 @@

name: 'my-service',
// log at 'info' and above
level: 'info',
streams: [
// Log to the console
{stream: process.stdout},
// And log to Stackdriver Logging
// Log to the console at 'info' and above
{stream: process.stdout, level: 'info'},
// And log to Stackdriver Logging, logging at 'info' and above
loggingBunyan.stream('info'),

@@ -98,4 +88,4 @@ ],

logger.info('shields at 99%');
```
### Using as an express middleware

@@ -233,2 +223,3 @@

## Samples

@@ -241,9 +232,17 @@

| --------------------------- | --------------------------------- | ------ |
| Express | [source code](https://github.com/googleapis/nodejs-logging-bunyan/blob/master/samples/express.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-logging-bunyan&page=editor&open_in_editor=samples/express.js,samples/README.md) |
| Quickstart | [source code](https://github.com/googleapis/nodejs-logging-bunyan/blob/master/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-logging-bunyan&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
| Explict Auth Setup | [source code](https://github.com/googleapis/nodejs-logging-bunyan/blob/master/samples/setup_explicit.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-logging-bunyan&page=editor&open_in_editor=samples/setup_explicit.js,samples/README.md) |
The [Stackdriver Logging for Winston Node.js Client API Reference][client-docs] documentation
also contains samples.
## Versioning
This library follows [Semantic Versioning](https://semver.org/).
This library follows [Semantic Versioning](http://semver.org/).
This library is considered to be in **beta**. This means it is expected to be

@@ -254,2 +253,5 @@ mostly stable while we work toward a general availability release; however,

More Information: [Google Cloud Platform Launch Stages][launch_stages]

@@ -270,13 +272,7 @@

[client-docs]: https://cloud.google.com/nodejs/docs/reference/logging-bunyan/latest/
[product-docs]: https://cloud.google.com/logging/docs
[product-docs]: https://cloud.google.com/logging
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[http-request-message]: https://cloud.google.com/logging/docs/reference/v2/rpc/google.logging.type#google.logging.type.HttpRequest
[error-reporting]: https://cloud.google.com/error-reporting/
[@google-cloud/error-reporting]: https://www.npmjs.com/package/@google-cloud/error-reporting
[uncaught]: https://nodejs.org/api/process.html#process_event_uncaughtexception
[unhandled]: https://nodejs.org/api/process.html#process_event_unhandledrejection
[trace-agent]: https://www.npmjs.com/package/@google-cloud/trace-agent
[LogEntry]: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
[trace-viewing-log-entries]: https://cloud.google.com/trace/docs/viewing-details#log_entries
[projects]: https://console.cloud.google.com/project
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=logging.googleapis.com
[auth]: https://cloud.google.com/docs/authentication/getting-started
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc