constbunyan=require('bunyan');// Imports the Google Cloud client library for Bunyanconst{LoggingBunyan}=require('@google-cloud/logging-bunyan');// Creates a Bunyan Cloud Logging clientconstloggingBunyan=newLoggingBunyan();// Create a Bunyan logger that streams to Cloud Logging// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/bunyan_log"constlogger=bunyan.createLogger({// The JSON payload of the log as it appears in Cloud 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 Cloud Logging, logging at 'info' and aboveloggingBunyan.stream('info'),],});// Writes some log entrieslogger.error('warp nacelles offline');logger.info('shields at 99%');
Constructors
(constructor)(options)
constructor(options?:types.Options);
Constructs a new instance of the LoggingBunyan class
Intercept log entries as they are written so we can attempt to add the trace ID in the same continuation as the function that wrote the log, because the trace agent currently uses continuation local storage for the trace context.
By the time the Writable stream buffer gets flushed and _write gets called we may well be in a different continuation.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-11-19 UTC."],[],[]]