@google-cloud/logging-winston
- Version 6.0.0
- Published
- 116 kB
- 4 dependencies
- Apache-2.0 license
Install
npm i @google-cloud/logging-winston
yarn add @google-cloud/logging-winston
pnpm add @google-cloud/logging-winston
Overview
Cloud Logging transport for Winston
Index
Variables
Functions
Classes
Interfaces
Namespaces
Variables
variable LOGGING_SAMPLED_KEY
const LOGGING_SAMPLED_KEY: string;
variable LOGGING_SPAN_KEY
const LOGGING_SPAN_KEY: string;
variable LOGGING_TRACE_KEY
const LOGGING_TRACE_KEY: string;
Functions
function getCurrentTraceFromAgent
getCurrentTraceFromAgent: () => string | null;
function getDefaultMetadataForTracing
getDefaultMetadataForTracing: () => {};
Returns an object that can be passed to Winston.createLogger as defaultMeta to allow log-trace correlation with Winston 3. Log-trace correlation with Winston 3 is broken because the trace ID to be correlated with a log isn't evaluated when the log function is called, but rather when the log is written, which happens at some future point where the trace ID may no longer be accurate. To circumvent this, we take advantage of the fact that defaultMeta is copied when a log function is called, and use a dynamic property getter to evaluate the trace ID upon that copy.
We apply the same principle for timestamps, which is not strictly necessary for tracing but allows for more accurate timestamps in general.
If there are other default metadata fields with which the return value of this function must be merged, this object MUST be the base object. In other words, do not use the return value of this function as the non-first argument to Object.assign, or it will not work.
See https://github.com/googleapis/nodejs-logging-winston/issues/287 for more information.
Classes
class LoggingWinston
class LoggingWinston extends TransportStream {}
This module provides support for streaming your winston logs to [Cloud Logging](https://cloud.google.com/logging).
Parameter options
Parameter
{object} [options.level] The default log level. Winston will filter messages with a severity lower than this.
Parameter
{object} [options.levels] Custom logging levels as supported by winston. This list is used to translate your log level to the Cloud Logging level. Each property should have an integer value between 0 (most severe) and 7 (least severe). If you are passing a list of levels to your winston logger, you should provide the same list here.
Parameter
{boolean} [options.inspectMetadata=false] Serialize winston-provided log metadata using
util.inspect
.Parameter
{string} [options.logName=winston_log] The name of the log that will receive messages written to this transport.
Parameter
{object} [options.resource] The monitored resource that the transport corresponds to. On Google Cloud Platform, this is detected automatically, but you may optionally specify a specific monitored resource. For more information see the [official documentation]https://cloud.google.com/logging/docs/api/reference/rest/v2/MonitoredResource.
Parameter
{object} [options.serviceContext] For logged errors, we provide this as the service context. For more information see [this guide]https://cloud.google.com/error-reporting/docs/formatting-error-messages and the [official documentation]https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext.
Parameter
{string} [options.serviceContext.service] An identifier of the service, such as the name of the executable, job, or Google App Engine service name.
Parameter
{string} [options.serviceContext.version] Represents the version of the service.
Parameter
{string} [options.projectId] The project ID from the Google Cloud Console, e.g. 'grape-spaceship-123'. We will also check the environment variable
GCLOUD_PROJECT
for your project ID. If your app is running in an environment which supports , your project ID will be detected automatically.Parameter
{string} [options.keyFilename] Full path to the a .json, .pem, or .p12 key downloaded from the Google Cloud Console. If you provide a path to a JSON file, the
projectId
option above is not necessary. NOTE: .pem and .p12 require you to specify theemail
option as well.Parameter
{string} [options.email] Account email address. Required when using a .pem or .p12 keyFilename.
Parameter
{object} [options.credentials] Credentials object.
Parameter
{string} [options.credentials.client_email]
Parameter
{string} [options.credentials.private_key]
Parameter
{boolean} [options.autoRetry=true] Automatically retry requests if the response is related to rate limits or certain intermittent server errors. We will exponentially backoff subsequent requests by default.
Parameter
{number} [options.maxRetries=3] Maximum number of automatic retries attempted before returning the error.
Parameter
{constructor} [options.promise] Custom promise module to use instead of native Promises.
Example 1
Import the client library const {LoggingWinston} = require('@google-cloud/logging-winston');
Example 2
Create a client that uses Application Default Credentials (ADC): const loggingWinston = new LoggingWinston();
Example 3
Create a client with explicit credentials: const loggingWinston = new LoggingWinston({ projectId: 'your-project-id', keyFilename: '/path/to/keyfile.json' });
Example 4
include:samples/quickstart.js region_tag:logging_winston_quickstart Full quickstart example:
constructor
constructor(options?: Options);
property common
common: LoggingCommon;
property LOGGING_SAMPLED_KEY
static readonly LOGGING_SAMPLED_KEY: string;
property LOGGING_SPAN_KEY
static readonly LOGGING_SPAN_KEY: string;
property LOGGING_TRACE_KEY
static readonly LOGGING_TRACE_KEY: string;
method log
log: (info: any, callback: Callback) => void;
Interfaces
interface Options
interface Options extends LoggingOptions {}
property defaultCallback
defaultCallback?: Callback;
property format
format?: any;
Additional parameters for TransportStream. For more information on parameters, please see [winston-transport](https://github.com/winstonjs/winston-transport/blob/0e5e4c0056188a74e24407ee066902fb113bd8de/index.js#L8).
property handleExceptions
handleExceptions?: boolean;
property handleRejections
handleRejections?: boolean;
property inspectMetadata
inspectMetadata?: boolean;
Serialize winston-provided log metadata using
util.inspect
.
property labels
labels?: { [key: string]: string;};
property level
level?: string;
The default log level. Winston will filter messages with a severity lower than this.
property levels
levels?: { [name: string]: number;};
Custom logging levels as supported by winston. This list is used to translate your log level to the Cloud Logging level. Each property should have an integer value between 0 (most severe) and 7 (least severe). If you are passing a list of levels to your winston logger, you should provide the same list here.
property logname
logname?: string;
property logName
logName?: string;
The name of the log that will receive messages written to this transport.
property maxEntrySize
maxEntrySize?: number;
property prefix
prefix?: string;
property redirectToStdout
redirectToStdout?: boolean;
Boolen flag that opts-in redirecting the output to STDOUT instead of ingesting logs to Cloud Logging using Logging API. Defaults to . Redirecting logs can be used in Google Cloud environments with installed logging agent to delegate log ingestions to the agent. Redirected logs are formatted as one line Json string following the structured logging guidelines.
property resource
resource?: MonitoredResource;
The monitored resource that the transport corresponds to. On Google Cloud Platform, this is detected automatically, but you may optionally specify a specific monitored resource. For more information see the [official documentation]https://cloud.google.com/logging/docs/api/reference/rest/v2/MonitoredResource.
property serviceContext
serviceContext?: ServiceContext;
For logged errors, we provide this as the service context. For more information see [this guide]https://cloud.google.com/error-reporting/docs/formatting-error-messages and the [official documentation]https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext.
property silent
silent?: boolean;
property useMessageField
useMessageField?: boolean;
Boolean flag indicating if "message" field should be used to store structured, non-text data inside jsonPayload field. This flag applies only when Options#redirectToStdout is set. By default this value is true
Namespaces
namespace express
module 'build/src/middleware/express.d.ts' {}
variable REQUEST_LOG_SUFFIX
const REQUEST_LOG_SUFFIX: string;
function makeMiddleware
makeMiddleware: { (logger: winston.Logger, transport: LoggingWinston): Promise<Middleware>; (logger: winston.Logger, options?: Options): Promise<any>;};
Package Files (4)
Dependencies (4)
Dev Dependencies (18)
Peer Dependencies (1)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@google-cloud/logging-winston
.
- Markdown[](https://www.jsdocs.io/package/@google-cloud/logging-winston)
- HTML<a href="https://www.jsdocs.io/package/@google-cloud/logging-winston"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3759 ms. - Missing or incorrect documentation? Open an issue for this package.