Constructor

LoggingWinston

new LoggingWinston(options)

This module provides support for streaming your winston logs to Stackdriver Logging.

Parameter

options

Optional

object

Examples

Import the client library

const LoggingWinston = require('@google-cloud/logging-winston');

Create a client that uses Application Default Credentials (ADC):

const loggingWinston = new LoggingWinston();

Create a client with explicit credentials:

const loggingWinston = new LoggingWinston({
  projectId: 'your-project-id',
  keyFilename: '/path/to/keyfile.json'
});

Full quickstart example:

const winston = require('winston');
const Logger = winston.Logger;
const Console = winston.transports.Console;

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

// Creates a Winston Stackdriver Logging client
const loggingWinston = new LoggingWinston();

// Create a Winston logger that streams to Stackdriver Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/winston_log"
const logger = new Logger({
  level: 'info', // log at 'info' and above
  transports: [
    // Log to the console
    new Console(),
    // And log to Stackdriver Logging
    loggingWinston,
  ],
});

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

Property

LOGGING_TRACE_KEY

static

string

Value: logging.googleapis.com/trace

Method

log

log(levelName, msg, metadata, callback)

Relay a log entry to the logging agent. This is normally called by winston.

Parameter

levelName

string

The severity level at which this entry is being logged. This should match one of the levels provided to the constructor which defaults to npm levels. This level will be translated to the appropriate Stackdriver logging severity level.

msg

string

The message to be logged.

metadata

Optional

object

Winston-provided metadata that should be attached to the log entry. If a httpRequest property is set, it will be treated as a HttpRequest request log message. If options.inspectMetadata is set, we will convert the remaining properties to strings before reporting.

callback

function()

A callback that is invoked when the logging agent either succeeds or gives up writing the log entry to the remote server.