How to use @google-cloud/logging-bunyan - 9 common examples

To help you get started, we’ve selected a few @google-cloud/logging-bunyan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mistval / kotoba / bot / src / start.js View on Github external
function createLogger() {
  // Use Bunyan logger connected to StackDriver if GCP credentials are present.
  if (hasGCloudKey) {
    const consoleLogger = new ConsoleLogger();
    const stackDriverLogger = new StackdriverBunyan({ keyFilename: GCLOUD_KEY_PATH });
    return Bunyan.createLogger({
      name: 'kotoba-bot',
      streams: [
        stackDriverLogger.stream('info'),
        consoleLogger.stream('info'),
      ],
    });
  }

  return undefined; // Use default console logger
}
github GoogleCloudPlatform / nodejs-serverless-url-shortener / frontend / logger / index.js View on Github external
'use strict';

// [START logging_bunyan_quickstart]
const bunyan = require('bunyan');
const production = process.env.NODE_ENV === 'production';

const streams = [{
  stream: process.stdout,
  level: 'info'
}];

if (production) {
  // Imports the Google Cloud client library for Bunyan
  const {LoggingBunyan} = require('@google-cloud/logging-bunyan');
  // Creates a Bunyan Stackdriver Logging client
  const loggingBunyan = new LoggingBunyan();
  streams.push(loggingBunyan.stream('info'));
}

// Create a Bunyan logger that streams to Stackdriver Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/bunyan_log"
const logger = bunyan.createLogger({
  // The JSON payload of the log as it appears in Stackdriver Logging
  // will contain "name": "my-service"
  name: 'frontend',
  streams
});

module.exports = logger;
github expo / turtle / src / logger / streams / gcloud.ts View on Github external
export default function create() {
  if (!config.google.credentials) {
    return null;
  }

  const gcloudStream = new LoggingBunyan({
    name: 'turtle',
    resource: {
      type: 'generic_node',
      labels: {
        node_id: config.hostname,
        location: '', // default value
        namespace: '', // default value
      },
    },
  });
  return {
    level: config.logger.level,
    type: 'raw',
    stream: gcloudStream,
  };
}
github googleapis / nodejs-logging-bunyan / samples / quickstart.js View on Github external
* distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

// [START logging_bunyan_quickstart]
const bunyan = require('bunyan');

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

// Creates a Bunyan Stackdriver Logging client
const loggingBunyan = new LoggingBunyan();

// Create a Bunyan logger that streams to Stackdriver Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/bunyan_log"
const logger = bunyan.createLogger({
  // The JSON payload of the log as it appears in Stackdriver Logging
  // will contain "name": "my-service"
  name: 'my-service',
  streams: [
    // 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'),
  ],
});

// Writes some log entries
github googleapis / nodejs-logging-bunyan / samples / setup_explicit.js View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

// sample-metadata:
//   title: Explict Auth Setup

/* eslint-disable no-unused-vars */
// [START logging_bunyan_setup_explicit]
// Imports the Google Cloud client library for Bunyan
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');

// Creates a client
const loggingBunyan = new LoggingBunyan({
  projectId: 'your-project-id',
  keyFilename: '/path/to/key.json',
});
// [END logging_bunyan_setup_explicit]
/* eslint-enable no-unused-vars */
github GoogleCloudPlatform / nodejs-serverless-url-shortener / shortlink / logger / index.js View on Github external
* distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

// [START logging_bunyan_quickstart]
const bunyan = require('bunyan');

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

// Creates a Bunyan Stackdriver Logging client
const loggingBunyan = new LoggingBunyan();

// Create a Bunyan logger that streams to Stackdriver Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/bunyan_log"
const logger = bunyan.createLogger({
  // The JSON payload of the log as it appears in Stackdriver Logging
  // will contain "name": "my-service"
  name: 'shortlink',
  streams: [
    // 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'),
  ],
});

module.exports = logger;
github googleapis / nodejs-logging-bunyan / samples / express.js View on Github external
async function startServer() {
  const {logger, mw} = await lb.express.middleware({
    logName: 'samples_express',
  });
  const app = express();

  // Install the logging middleware. This ensures that a Bunyan-style `log`
  // function is available on the `request` object. This should be the very
  // first middleware you attach to your app.
  app.use(mw);

  // Setup an http route and a route handler.
  app.get('/', (req, res) => {
    // `req.log` can be used as a bunyan style log method. All logs generated
    // using `req.log` use the current request context. That is, all logs
    // corresponding to a specific request will be bundled in the Stackdriver
    // UI.
    req.log.info('this is an info log message');
github meetup / meetup-web-platform / packages / mwp-logger-plugin / src / logger.js View on Github external
NODE_ENV,
	GAE_INSTANCE,
	GCLOUD_PROJECT,
	GAE_VERSION,
	GAE_SERVICE,
	DISABLE_GAE_LOG,
} = process.env;
if (!NODE_ENV || NODE_ENV === 'development') {
	streams.push({
		type: 'raw',
		stream: bunyanDebugStream({ forceColor: true, basepath: process.cwd() }),
	});
}

if (GAE_INSTANCE && !DISABLE_GAE_LOG) {
	const GAELogger = new LoggingBunyan({
		logName: 'mwp_log',
		resource: {
			type: 'gae_app',
			labels: {
				project_id: GCLOUD_PROJECT,
				module_id: GAE_SERVICE,
				version_id: GAE_VERSION,
			},
		},
		serviceContext: {
			service: GAE_SERVICE,
			version: GAE_VERSION,
		},
	});
	GAELogger.on('error', err => console.error(err));
github meetup / meetup-web-platform / packages / mwp-logger-plugin / src / logger.js View on Github external
NODE_ENV,
	GAE_INSTANCE,
	GCLOUD_PROJECT,
	GAE_VERSION,
	GAE_SERVICE,
	DISABLE_GAE_LOG,
} = process.env;
if (!NODE_ENV || NODE_ENV === 'development') {
	streams.push({
		type: 'raw',
		stream: bunyanDebugStream({ forceColor: true, basepath: process.cwd() }),
	});
}

if (GAE_INSTANCE && !DISABLE_GAE_LOG) {
	const GAELogger = new LoggingBunyan({
		logName: 'mwp_log',
		resource: {
			type: 'gae_app',
			labels: {
				project_id: GCLOUD_PROJECT,
				module_id: GAE_SERVICE,
				version_id: GAE_VERSION,
			},
		},
		serviceContext: {
			service: GAE_SERVICE,
			version: GAE_VERSION,
		},
	});
	GAELogger.on('error', err => console.error(err));

@google-cloud/logging-bunyan

Cloud Logging stream for Bunyan

Apache-2.0
Latest version published 24 days ago

Package Health Score

84 / 100
Full package analysis