-
Notifications
You must be signed in to change notification settings - Fork 8
Log Parsing
To tackle the issue of parsing brickadia console logs, the LogWrangler was created. It wrangles logs into a manageable form.
It's important to note that some console commands will take longer to run when there are more players on the server and some watchers may time out or run slower.
Term | Definition |
---|---|
Pattern | A function or Regex that matches a brickadia server log |
Matcher | Given a pattern and a callback, a matcher will execute the callback every time a log matches the pattern |
Watcher | Given a pattern, a watcher will wait for a log to match the pattern and resolve with the matched line |
Log Line | A line of the brickadia server log |
Log Chunk | A block of logs that match the same pattern with incremental indices |
Log Array | A LogChunk with items after each matched chunk line |
When running console commands, it's helpful to be able to parse large blocks of uniform data. The Omegga.watchLogChunk(cmd, pattern, options)
method does just that.
This method is a helper method for a watcher.
If nothing is matched within the configured time, the promise rejects. Otherwise, it resolves with an array of the matched results.
Check out the commandInjector for some example usage of watchLogChunk
and watchLogArray
.
Name | Type | Description |
---|---|---|
cmd | string |
Brickadia console command to run |
pattern |
RegExp or function
|
returns non-null or matches when a log line is matched. The result is the added to the promise result |
options | object |
Options to configure the watcher |
Options are an object of {optionName: optionValue}
based on the below table.
Name | Type | Default | Description |
---|---|---|---|
first |
string or function
|
none | Determines if this is the first log line in the log chunk. If first is set to 'index' , the chunk will start when the index capture group of the pattern argument is '0' . If first is a function, the chunk will start when the function returns true |
last |
function |
none | Same as last option in addWatcher (below) |
afterMatchDelay |
number |
10 |
Same as afterMatchDelay option in addWatcher (below) |
timeoutDelay |
number |
100 |
Same as timeoutDelay option in addWatcher (below) |
The following is the result of the console command: GetAll BRPlayerState PlayerNamePrivate
[2021.02.16-23.52.46:582][320]0) BP_PlayerState_C /Game/Maps/Plate/Plate.Plate:PersistentLevel.BP_PlayerState_C_2147482508.PlayerNamePrivate = cake
[2021.02.16-23.52.46:582][320]1) BP_PlayerState_C /Game/Maps/Plate/Plate.Plate:PersistentLevel.BP_PlayerState_C_2147482402.PlayerNamePrivate = cake
[2021.02.16-23.52.46:582][320]2) BP_PlayerState_C /Game/Maps/Plate/Plate.Plate:PersistentLevel.BP_PlayerState_C_2147482287.PlayerNamePrivate = cake
Watch Log Array is useful for parsing console output that is multi dimensional (A result for each player, and each result has multiple entries). This method is an extension of Watch Log Chunk.
If nothing is matched within the configured time, the promise rejects. Otherwise, it resolves with an array of the matched results.
Check out the commandInjector for some example usage of watchLogChunk
and watchLogArray
.
[{
item: /* capture group from the match of itemPattern */,
members: [
/* array of capture groups from the match of memberPattern */
],
}, /* ... */ ]
Name | Type | Description |
---|---|---|
cmd |
string |
Brickadia console command to run |
itemPattern |
RegExp |
A regex to match the top level items. Must have an (?) capture group. Information is extracted via capture groups. |
memberPattern |
RegExp |
A regex to match the bottom level logs. |
The following is the result of the console command: GetAll BP_Ruleset_C MemberStates
Note: the two spaces before 0:
and 1:
are tabs in the game output.
[2021.02.16-23.53.27:331][701]0) BP_Ruleset_C /Game/Maps/Plate/Plate.Plate:PersistentLevel.BP_Ruleset_C_2147482516.MemberStates =
[2021.02.16-23.53.27:331][701] 0: BP_PlayerState_C'/Game/Maps/Plate/Plate.Plate:PersistentLevel.BP_PlayerState_C_2147482508'
[2021.02.16-23.53.27:331][701] 1: BP_PlayerState_C'/Game/Maps/Plate/Plate.Plate:PersistentLevel.BP_PlayerState_C_2147482402'
[2021.02.16-23.53.27:331][701]1) BP_Ruleset_C /Game/Maps/Plate/Plate.Plate:PersistentLevel.BP_Ruleset_C_2147482167.MemberStates =
[2021.02.16-23.53.27:331][701] 0: BP_PlayerState_C'/Game/Maps/Plate/Plate.Plate:PersistentLevel.BP_PlayerState_C_2147482287'
The following code will extract Rulesets (minigames) as items with PlayerStates (clients) as members:
const ruleMembersRegExp = /^(?<index>\d+)\) BP_Ruleset_C (.+):PersistentLevel.(?<ruleset>BP_Ruleset_C_\d+)\.MemberStates =$/;
const playerStateRegExp = /^\t(?<index>\d+): BP_PlayerState_C'(.+):PersistentLevel\.(?<state>BP_PlayerState_C_\d+)'$/;
Omegga.watchLogArray('GetAll BP_Ruleset_C MemberStates', ruleMembersRegExp, playerStateRegExp)
.then(console.log)
.catch(console.error)
Matchers are used by Omegga to trigger events. You can find the matchers omegga uses in the src/omegga/matchers directory.
These are less useful for plugins that use existing triggers and more useful for adding new core features to Omegga.
Name | Type | Description |
---|---|---|
pattern |
RegExp or function
|
returns non-null or matches when a log line is matched. The result is the arguments to the callback |
callback |
function |
Function to run when the pattern matches |
Watchers are used when waiting for something to produce console output.
If nothing is matched within the configured time, the promise rejects.
Name | Type | Description |
---|---|---|
pattern |
RegExp or function
|
returns non-null or matches when a log line is matched. The result is the return value of the promise |
options |
object |
Options to configure the watcher |
Options are an object of {optionName: optionValue}
based on the below table.
Name | Type | Default | Description |
---|---|---|---|
timeoutDelay |
number |
50 |
Milliseconds before the watcher rejects |
bundle |
boolean |
false |
If bundle is set to true, it returns all matches after the timeout ends rather than resolving (can't be used with delay 0) |
debounce |
bool |
false |
(used with bundle) Waits extra time after each match before timing out |
last |
function |
none | (used with bundle) A function run on the log line. if it returns true, the watcher resolves early |
exec |
function |
none | A function run after the watcher is created |
Here is an example options object:
{
timeoutDelay: 50,
bundle: false,
debounce: false,
afterMatchDelay: 0,
exec: () => Omegga.writeln('Chat.Broadcast "Hello"')
}