Skip to main content

Community log

Use the community log to send messages from your server to the administrators of a Root community. It's a good way to report important events, warnings, or errors that need human attention.

What is the community log?

The community log is a persistent, admin-visible log. It appears inside the Root client and helps community administrators understand what's happening in your code. Each community has its own log.

  • The API is available from your server-side code
  • The log is visible to community members with the ChannelManageApp permission
  • Messages are not visible to you, the developer. They're displayed inside the Root client, not the Root Developer Portal
  • Messages are retained for 90 days.

When to use it

Use the community log to report things that should be seen by a human administrator. For example:

  • A user tried to post something invalid
  • Your server hit an unexpected condition but recovered
  • Your server hit an unexpected condition and had to shut down.

How to write to the community log

To log a message, call the create method on rootServer.dataStore.logs.community. You pass a request object that contains the log message and its severity. The returned response object contains the unique ID for the log entry you just created (there's currently nothing to do with this ID, it's reserved for future use).

Example

import {
rootServer,
RootApiException,
CommunityAppLogType,
CommunityAppLogCreateRequest,
CommunityAppLogCreateResponse
} from "@rootsdk/server";

// Create the request object with a warning message
const request: CommunityAppLogCreateRequest = {
communityAppLogType: CommunityAppLogType.Warn,
message: "No new-member role provided. Using default role."
};

try {
// Send the log entry to the community log
const response: CommunityAppLogCreateResponse = await rootServer.dataStore.logs.community.create(request);
} catch (error: unknown) {
if (error instanceof RootApiException) {
console.error("Root API exception:", error.errorCode, error.message);
} else {
console.error("Unexpected error writing to community log:", error);
}
}

Message levels

Use the appropriate communityAppLogType to indicate severity:

TypeDescription
InfoGeneral information
WarnA warning that something might be wrong
ErrorSomething failed, but the system can continue
FatalA critical failure that requires a code update

Permissions

Only members with the ChannelManageApp permission in the community will see your messages. Make sure you only log things that administrators need to know.

Summary

  • Use rootServer.dataStore.logs.community.create() to write to the community log
  • Messages are shown to community admins inside the Root client
  • Messages are kept for 90 days

The community log is your conduit directly to community administrators. Use it to keep them informed.