#
LogRocketLogger
A logger outputting messages to a LogRocket session replay.
#
Reference
const logger = new LogRocketLogger(options?: { logLevel? })
#
Parameters
options: An optional object literal of options:logLevel: Sets the minimum severity of entries the logger will process. Possible values aredebug,information,warning,error,critical.
#
Methods
Refer to the Logger and LoggerScope documentation.
#
Usage
#
Log a debug entry
import { LogRocketLogger } from "@workleap/telemetry/react"; // or from "@workleap/logrocket/react";
const logger = new LogRocketLogger();
logger.debug("Hello world!");
#
Log an information entry
import { LogRocketLogger } from "@workleap/telemetry/react"; // or from "@workleap/logrocket/react";
const logger = new LogRocketLogger();
logger.information("Hello world!");
#
Log a warning entry
import { LogRocketLogger } from "@workleap/telemetry/react"; // or from "@workleap/logrocket/react";
const logger = new LogRocketLogger();
logger.warning("Hello world!");
#
Log an error entry
import { LogRocketLogger } from "@workleap/telemetry/react"; // or from "@workleap/logrocket/react";
const logger = new LogRocketLogger();
logger.error("Hello world!");
#
Log a critical entry
import { LogRocketLogger } from "@workleap/telemetry/react"; // or from "@workleap/logrocket/react";
const logger = new LogRocketLogger();
logger.critical("Hello world!");
#
Filter log entries
A minimum severity of entries to process can be configured as an option. Messages with a lower severity than the configured level will then be ignored.
import { LogRocketLogger } from "@workleap/telemetry/react"; // or from "@workleap/logrocket/react";
const logger = new LogRocketLogger({
logLevel: LogLevel.error
});
// Will be ignored because "debug" is lower than the "error" severity.
logger.debug("Hello world!");
For reference, here's a description of each level:
#
Debug
- Very detailed, often verbose, logs used mainly during development.
- Example: API request/response bodies, lifecycle hooks, variable state.
#
Information
- General events that show the normal flow of the application.
- Example: User login, component mounted, scheduled task started.
#
Warning
- Non-critical issues that might need attention but don't break functionality.
- Example: Deprecated API usage, retries after a failed network call.
#
Error
- Failures that prevent part of the system from working as intended.
- Example: Unhandled exceptions, failed database query, API call failed with 500.
#
Critical
- Severe errors that cause the application to stop functioning or risk data integrity.
- Example: Application crash, loss of critical service connection.
#
Build complex log entry
Multiple segments can be chained to create a log entry that combines styled text, errors, and objects. To process all segments and output the log to the console, complete the chain by calling any log method.
import { LogRocketLogger } from "@workleap/telemetry/react"; // or from "@workleap/logrocket/react";
const logger = new LogRocketLogger();
logger
.withText("Processing segment")
.withObject({ id: 1 })
.withText("failed with error")
.withError(new Error("The error"))
.debug();
#
Use a logging scope
import { LogRocketLogger } from "@workleap/telemetry/react"; // or from "@workleap/logrocket/react";
const logger = new LogRocketLogger();
const scope = logger.startScope("Module 1 registration");
scope.debug("Registering routes...");
scope
.withText("Routes registered!")
.withObject([{
path: "/foo",
label: "Foo"
}])
.debug();
scope.debug("Fetching data...");
scope
.withText("Data fetching failed")
.withError(new Error("The specified API route doesn't exist."))
.error();
scope.debug("Registration failed!");
// Once the scope is ended, the log entries will be outputted to the console.
scope.end();
#
Dismiss a logging scope
A scope can be dismissed to prevent it's log entries from being outputted to the console.
import { LogRocketLogger } from "@workleap/telemetry/react"; // or from "@workleap/logrocket/react";
const logger = new LogRocketLogger();
const scope = logger.startScope("Module 1 registration");
scope.debug("Registering routes...");
scope
.withText("Routes registered!")
.withObject([{
path: "/foo",
label: "Foo"
}])
.debug();
scope.debug("Fetching data...");
// Will not output any log entries to the console.
scope.end({ dismiss: true });
See also
Follow privacy best practices to reduce the risk of exposing Personally Identifiable Information (PII) in LogRocket session replays.
If telemetry hasn't been set up for your project yet, please refer to the setup guide before continuing.
initializeTelemetry
By default, LogRocket session replays can display logs captured during a user session. To prevent exposure of Personally Identifiable Information