Logs
How to use logging functionality with the Fivemanage SDK
This section provides examples of how to use the LogMessage export on the server. It also includes explanations of the various settings within config.json, detailing how each can be configured to customize logging functionality.
Examples are provided in both Lua and JavaScript. TypeScript developers can refer to the type annotations provided in the function definitions for guidance on the expected argument and return types.
Config Settings:
-
"level": Sets the minimum log level to capture. "info" by default, meaning only logs of "info" level and above are recorded. This value must be one of the options defined in the "levels" array.
-
"levels": Defines the hierarchy of log levels from most to least critical. Only levels included in this array can be used during runtime.
-
"console": Enables or disables logging to the server console. Set to
trueto activate console logging. -
"enableCloudLogging": Determines whether logs should be sent to the Fivemanage cloud. Set to
falseto keep logs local ortrueto enable cloud logging. -
"appendPlayerIdentifiers": When
true, player identifiers are automatically appended to the log's metadata ifmetadata.playerSourceand/ormetadata.targetSourceare specified. -
"excludedPlayerIdentifiers": A list of identifier types that will be excluded from appended identifier metadata.
Server Exports
Function Definition:
Log(dataset: string, level: string, message: string, metadata?: { playerSource?: string | number, targetSource?: string | number, [key: string]: unknown }): voidLua Example:
exports.fmsdk:Log("default", "info", "Player connected", {
playerSource = source,
customData = "Additional info"
})
-- Without metadata
exports.fmsdk:Log("default", "error", "An error occurred")JavaScript Example:
exports.fmsdk.Log("default", "info", "Player connected", {
playerSource: player.id,
customData: "Additional info",
});
// Without metadata
exports.fmsdk.Log("error", "An error occurred");With datasets
If you want to ingest logs to a specific dataset, you can use the dataset parameter. This is useful for organizing logs by different categories or modules.
The export: fmsdk:LogMessage will always use the 'default' dataset for backwards compatibility, and does not offer the dataset parameter.
Lua Example:
exports.fmsdk:Log("core", "info", "User connected", {
playerSource = source,
customData = "User ID: 12345"
})
---
exports.fmsdk:Log("bank", "info", "Someone gave money to a shrimp!", {
playerSource = source,
amount = 100,
})Shorthand exports
If you want to use the shorthand exports, you can use the following:
exports.fmsdk:Info("default", "Player connected", {
playerSource = source,
myField = "Additional info"
})
exports.fmsdk:Error("inventory", "An error occurred")
exports.fmsdk:Warn("police", "Police car stolen", {
playerSource = source,
carId = "ABC123"
})