Skip to content

Get Sansar

Script API

Log

Where: Client
More page actions

For the complete documentation index, see llms.txt. This page is also available as Markdown.

Class Namespace Sansar.Script Inherits InstanceInterface

The Log class handles script logging and error reporting

public class Log : InstanceInterface

Remarks

A simple script for viewing the log messages might be:

Example

LogExample.cs
/* (C) Linden Research, Inc. All Rights Reserved. */
using Sansar.Script;
using Sansar.Simulation;
public class LogExample : SceneObjectScript
{
public override void Init()
{
// Basic log message
Log.Write(LogLevel.Info, "LogExample initialized");
// Log with format parameters
var sampleValue = "example";
Log.Write(LogLevel.Warning, "Sample value: {0}", sampleValue);
// Simulate a recoverable error to show LogLevel.Error usage.
var success = TryDoWork();
if (!success)
{
Log.Write(LogLevel.Error, "The sample work loop reported a failure.");
}
}
private bool TryDoWork()
{
// Placeholder for sample logic
return false;
}
}

Source: Examples/LogExample.cs in the Sansar 47.10.0 client ScriptApi snapshot.

Members at a glance

KindMembers
FieldsConsoleHistory · MaximumMessageLength · MaximumTagLength
PropertiesMessages
MethodsClear · Write · WriteDebug

Fields

ConsoleHistory

Deprecated
[System.Obsolete("Messages are no longer stored.", true)] public const int ConsoleHistory

The maximum number of messages to store on this console.

Value: int — The maximum number of messages stored by the console.

MaximumMessageLength

Added in 45.0.4
public const int MaximumMessageLength

The maximum length of a log message.

MaximumTagLength

Added in 45.0.4
public const int MaximumTagLength

The maximum length of the log message tag.

Properties

Messages

Deprecated
[System.Obsolete("Messages are no longer stored.", true)] public IEnumerable<Log.Message> Messages { get; }

All current log messages.

Value: IEnumerable<Log.Message> — All currently stored log messages.

Methods

Clear

Deprecated
[System.Obsolete("Messages are no longer stored.", true)] public void Clear()

Clears all messages in this console.

Remarks

Messages cannot be restored.

Deprecated
[System.Obsolete("Messages are no longer stored.", true)] public void Clear(LogLevel logLevel)

Clears all messages in this console with the given logLevel.

ParameterTypeDescription
logLevelLogLevelThe LogLevel to clear from the log. Multiple loglevels can be cleared in a single cal.
Remarks

Messages cannot be restored.

Deprecated
[System.Obsolete("Messages are no longer stored.", true)] public void Clear(ScriptId scriptId)

Clears all messages in this console with the given ScriptId.

ParameterTypeDescription
scriptIdScriptIdThe ScriptId to clear from the log.
Remarks

Messages cannot be restored.

Deprecated
[System.Obsolete("Messages are no longer stored.", true)] public void Clear(string tag)

Clears all messages in this console with the given tag.

ParameterTypeDescription
tagstringThe tag to clear from the log.
Remarks

Messages cannot be restored.

Write

public void Write(string message)

Writes an info message to the server log.

ParameterTypeDescription
messagestringThe message to be logged.
Remarks

Log messages may be throttled.

public void Write(LogLevel logLevel, string message)

Writes a message to the server log.

ParameterTypeDescription
logLevelLogLevelLogLevel of the message.
messagestringThe message to be logged.
Remarks

Log messages may be throttled.

public void Write(string tag, string message)

Writes an info message to the server log.

ParameterTypeDescription
tagstringA freeform string tag for filtering the message.
messagestringThe message to be logged.
Remarks

Log messages may be throttled.

public void Write(LogLevel logLevel, string tag, string message)

Writes a message to the server log.

ParameterTypeDescription
logLevelLogLevelLogLevel of the message.
tagstringTag for the message.
messagestringMessage to log.
Remarks

Also tracks the sending script and the time. No messages are locally retained.

WriteDebug

Added in 45.0.4
public void WriteDebug(     string message,     string tag,     [System.Runtime.CompilerServices.CallerMemberName] string callerMemberName,     [System.Runtime.CompilerServices.CallerLineNumber] int callerLineNumber )

Writes a debug message to the server log, including caller information.

ParameterTypeDescription
messagestring(Optional) The message to be logged. When left empty, it will only log caller information.
tagstring(Optional) A tag for the message.
callerMemberNamestringAutomatically populated with the name of the calling member (method or property).
callerLineNumberintAutomatically populated with the line number in the source code where the method was called.
Remarks

Log messages may be throttled. WriteDebug(..) serves the same purpose as using Write(LogLevel.Debug, ..), while also including automatically populated caller information for debugging purposes.

Generated from the Sansar 47.10.0 client ScriptApi snapshot.