Skip to main content

Logging

To get started with Dynamoose logging run the following command:

npm install --save-dev dynamoose-logger

The command above will install the dynamoose-logger package as a developer dependency. However, if you wish to install it as a normal dependency to use in production you can run the following command:

npm install --save dynamoose-logger

There is no need to import or require anything in your project after running that command. Dynamoose will automatically detect that you have the dynamoose-logger package installed, and will automatically provide the following methods for you to use in your application.

dynamoose.logger()

This async function will give you the basic logger instance that you can use to run methods to control the logging settings. In the event you do not have dynamoose-logger installed, this function will throw an error.

let logger;
try {
logger = await dynamoose.logger();
} catch (e) {
console.error("The `dynamoose-logger` package has not been installed.");
}

dynamoose.logger().providers.set([provider])

This function allows you to set a provider(s) to receive logged events in Dynamoose. The provider parameter can either be a provider object, or an array of provider projects. This function will overwrite all existing providers set. If you pass undefined, null, or an empty array in as the provider parameter all existing providers will be removed. By default there are no providers setup with the Dynamoose logger.

The simplest way to add logging to see what Dynamoose is doing under the hood is to run the following command. console is a specical internal log provider that can be used to print debug events to the console. You can also create custom log providers or find 3rd party plugin log providers for Dynamoose.

(await dynamoose.logger()).providers.set(console);

dynamoose.logger().providers.clear()

This function clears all existing log providers from Dynamooose. This function behaves the same as dynamoose.logger().providers.set([]).

(await dynamoose.logger()).providers.clear();

dynamoose.logger().providers.add(provider)

This function allows you to add a provider(s) to receive logged events in Dynamoose. The provider parameter can either be a provider object or an array of provider objects.

Unlike dynamoose.logger().providers.set this function appends the new providers to the existing providers and does not overwrite any existing providers.

(await dynamoose.logger()).providers.add(console);

dynamoose.logger().providers.delete(id)

This function allows you to pass in an id parameter to delete an existing provider.

(await dynamoose.logger()).providers.delete(id);

dynamoose.logger().providers.list()

This function returns an array of all the log providers Dynamoose is currently using.

(await dynamoose.logger()).providers.list();

dynamoose.logger().pause()

This function pauses all output of log events to all log providers.

(await dynamoose.logger()).pause();

dynamoose.logger().resume()

This function resumes all output of log events to all log providers.

(await dynamoose.logger()).resume();

dynamoose.logger().status()

This function returns active if log events are being emitted to log providers, or paused if log events have been paused from being emitted to log providers.

(await dynamoose.logger()).status(); // "active" || "paused"