Class LoggingWinston (5.2.2)

This module provides support for streaming your winston logs to [Cloud Logging](https://cloud.google.com/logging).

Inheritance

TransportStream > LoggingWinston

Package

@google-cloud/logging-winston

Examples

Import the client library const {LoggingWinston} = require('@google-cloud/logging-winston');

Create a client that uses a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application"Application Default Credentials (ADC): const loggingWinston = new LoggingWinston();

Create a client with a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually"explicit credentials: const loggingWinston = new LoggingWinston({ projectId: 'your-project-id', keyFilename: '/path/to/keyfile.json' });

Full quickstart example:


const winston = require('winston');

// Imports the Google Cloud client library for Winston
const {LoggingWinston} = require('@google-cloud/logging-winston');

const loggingWinston = new LoggingWinston();

// Create a Winston logger that streams to Cloud Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/winston_log"
const logger = winston.createLogger({
  level: 'info',
  transports: [
    new winston.transports.Console(),
    // Add Cloud Logging
    loggingWinston,
  ],
});

// Writes some log entries
logger.error('warp nacelles offline');
logger.info('shields at 99%');

Constructors

(constructor)(options)

constructor(options?: Options);

Constructs a new instance of the LoggingWinston class

Parameter
NameDescription
options Options

Properties

common

common: LoggingCommon;

LOGGING_SAMPLED_KEY

static readonly LOGGING_SAMPLED_KEY = "logging.googleapis.com/trace_sampled";

LOGGING_SPAN_KEY

static readonly LOGGING_SPAN_KEY = "logging.googleapis.com/spanId";

LOGGING_TRACE_KEY

static readonly LOGGING_TRACE_KEY = "logging.googleapis.com/trace";

Methods

log(info, callback)

log(info: any, callback: Callback): void;
Parameters
NameDescription
info any
callback Callback
Returns
TypeDescription
void