Inheritance
Writable
>
LoggingBunyan
Package
@google-cloud/logging-bunyan
Examples
Import the client library
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');
Create a client that uses Application Default Credentials (ADC):
const loggingBunyan = new
LoggingBunyan();
Create a client with explicit credentials:
const loggingBunyan = new LoggingBunyan({
projectId: 'your-project-id',
keyFilename: '/path/to/keyfile.json'
});
Full quickstart example:
const bunyan = require('bunyan');
// Imports the Google Cloud client library for Bunyan
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');
// Creates a Bunyan Cloud Logging client
const loggingBunyan = new LoggingBunyan();
// Create a Bunyan logger that streams to Cloud 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 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 above
loggingBunyan.stream('info'),
],
});
// Writes some log entries
logger.error('warp nacelles offline');
logger.info('shields at 99%');
Constructors
(constructor)(options)
constructor(options?: types.Options);
Constructs a new instance of the LoggingBunyan
class
Parameter
Name | Description |
options |
types.Options
|
Properties
stackdriverLog
stackdriverLog: types.StackdriverLog;
Methods
_write(record, encoding, callback)
_write(record: types.BunyanLogRecord, encoding: string, callback: Function): void;
Relay a log entry to the logging agent. This is called by bunyan through Writable#write.
Parameters
Name | Description |
record |
types.BunyanLogRecord
|
encoding |
string
|
callback |
Function
|
Returns
_writev(chunks, callback)
_writev(chunks: Array<{
chunk: any;
encoding: string;
}>, callback: Function): void;
Relay an array of log entries to the logging agent. This is called by bunyan through Writable#write.
Parameters
Name | Description |
chunks |
Array<{
chunk: any;
encoding: string;
}>
|
callback |
Function
|
Returns
properLabels(labels)
static properLabels(labels: any): boolean;
Parameter
Name | Description |
labels |
any
|
Returns
stream(level)
stream(level: types.LogLevel): types.StreamResponse;
Convenience method that Builds a bunyan stream object that you can put in the bunyan streams list.
Parameter
Name | Description |
level |
types.LogLevel
|
Returns
Type | Description |
types.StreamResponse | |
write(record, callback)
write(record: types.BunyanLogRecord, callback?: Function): boolean;
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.
Parameters
Name | Description |
record |
types.BunyanLogRecord
|
callback |
Function
|
Returns
write(record, encoding, callback)
write(record: types.BunyanLogRecord, encoding?: string, callback?: Function): boolean;
Parameters
Name | Description |
record |
types.BunyanLogRecord
|
encoding |
string
|
callback |
Function
|
Returns