Skip to main content

Log Entries

Log entries are the core aspect of rLog. They're what provide log messages, and carry the additional context of a log.

what you'll learn
  • What log entries are
  • The different components of a log
  • How data is attached to logs

Overview

Log entries themselves aren't nearly as complex as the systems surrounding them, but they do have a decent amount of information attached to them.

export type LogEntry = {
level: LogLevel;
message: string;
data: LogData;
encoded_data: LogData;
config: Writable<RLogConfig>;
context?: LogContext;
timestamp: number;
source_metadata: SourceMetadata;
};

Level

The level is the Log Level, or severity, of the log.

import { rLog } from "@rbxts/rlog";

const logger = new rLog();

logger.info("Hello world!");

In this case, LogLevel.INFO is the level.

Message

The message is the actual string message intended for the log.

import { rLog } from "@rbxts/rlog";

const logger = new rLog();

logger.info("Hello world!");

In this instance, Hello world! is the message.

Data

data is additional metadata specific to the log itself.

export type LogData = Record<string, unknown>;

You'll learn more about data in the other guides.

Encoded Data

encoded_data is just data in a form that's JSON friendly, and has been ran through the rLog serializer.

Config

config is a Writable version of the RLogConfig that was used when sending the log.

import { rLog } from "@rbxts/rlog";

const logger = new rLog({ tag: "Main" });

logger.info("Hello world!");

In this instance, { tag: "Main" } is the config.

Timestamp

timestamp is the epoch milliseconds in which the log occurred.

[INFO]: Actions -> Hello world!
{
timestamp: 1723757975945,
correlation_id: "Xzm9InKevNRjvqqo"
}
info

For the sake of brevity, most of the guides will exclude timestamp from their output.

In practice, this will be a part of your logs.

Context

context is the LogContext instance that was used when sending the log, if there was one present at all.

Log Context allows you to create linkage between log entries, and is one of the most important features of rLog.

But, it's a bit too complex of a topic for now; you'll learn more about it in the Log Context guide.

Correlation ID

correlation_id is a unique string attached to logs to identify entries that run across different rLog instances, but represent the same "flow".

These are provided via Log Context.

[INFO]: Actions -> Hello world!
{
timestamp: 1723757975945,
correlation_id: "Xzm9InKevNRjvqqo"
}

You'll learn more about Correlation IDs aswell in the Log Context guide.

Source Metadata

source_metadata is additional metadata detailing where in the source code this log occurred.

export type SourceMetadata = {
function_name?: string;
nearest_function_name?: string;
file_path: string;
line_number: number;
};

You'll learn more about Source Metadata in the Source Metadata guide.

Summary

Let's recap what we've learned about log entries:

  • They carry all the metadata associated with log messages
  • They keep track of when logs were sent, and who sent them
  • They allow logs to carry additional user provided data