npm

Check out our latest tech talk, "JavaScript Supply Chain Security" presented by VP of Security, Adam Baldwin.Watch it here »

@google-cloud/logging

5.1.3 • Public • Published
Google Cloud Platform logo

Stackdriver Logging: Node.js Client

release level npm version codecov

Stackdriver Logging allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.

Table of contents:

Quickstart

Before you begin

  1. Select or create a Cloud Platform project.
  2. Enable the Stackdriver Logging API.
  3. Set up authentication with a service account so you can access the API from your local workstation.

Installing the client library

npm install @google-cloud/logging

Using the client library

async function quickstart(
  projectId = 'YOUR_PROJECT_ID', // Your Google Cloud Platform project ID
  logName = 'my-log' // The name of the log to write to
) {
  // Imports the Google Cloud client library
  const {Logging} = require('@google-cloud/logging');
 
  // Creates a client
  const logging = new Logging({projectId});
 
  // Selects the log to write to
  const log = logging.log(logName);
 
  // The data to write to the log
  const text = 'Hello, world!';
 
  // The metadata associated with the entry
  const metadata = {
    resource: {type: 'global'},
  };
 
  // Prepares a log entry
  const entry = log.entry(metadata, text);
 
  // Writes the log entry
  await log.write(entry);
  console.log(`Logged: ${text}`);
}
 

Samples

Samples are in the samples/ directory. The samples' README.md has instructions for running the samples.

Sample Source Code Try it
Fluent source code Open in Cloud Shell
Logs source code Open in Cloud Shell
Quickstart source code Open in Cloud Shell
Sinks source code Open in Cloud Shell

The Stackdriver Logging Node.js Client API Reference documentation also contains samples.

Versioning

This library follows Semantic Versioning.

This library is considered to be General Availability (GA). This means it is stable; the code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against GA libraries are addressed with the highest priority.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

License

Apache Version 2.0

See LICENSE

install

npm i @google-cloud/logging

Downloadsweekly downloads

97,062

version

5.1.3

license

Apache-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability