@larablox/monolog 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +86 -0
- package/out/Monolog/Handler/AbstractProcessingHandler.d.ts +3 -1
- package/out/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.d.ts +19 -0
- package/out/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.luau +30 -0
- package/out/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.d.ts +29 -0
- package/out/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.luau +61 -0
- package/out/Monolog/Handler/FingersCrossed/ErrorLevelActivationStrategy.d.ts +14 -0
- package/out/Monolog/Handler/FingersCrossed/ErrorLevelActivationStrategy.luau +32 -0
- package/out/Monolog/Handler/FingersCrossedHandler.d.ts +107 -0
- package/out/Monolog/Handler/FingersCrossedHandler.luau +208 -0
- package/out/Monolog/Handler/FormattableHandlerInterface.d.ts +23 -0
- package/out/Monolog/Handler/FormattableHandlerInterface.luau +36 -0
- package/out/Monolog/Handler/GroupHandler.d.ts +49 -0
- package/out/Monolog/Handler/GroupHandler.luau +139 -0
- package/out/Monolog/Handler/HandlerInterface.d.ts +10 -0
- package/out/Monolog/Handler/HandlerInterface.luau +36 -1
- package/out/Monolog/Handler/ProcessableHandlerInterface.d.ts +26 -0
- package/out/Monolog/Handler/ProcessableHandlerInterface.luau +15 -0
- package/out/Monolog/Handler/RobloxConsoleHandler.d.ts +19 -46
- package/out/Monolog/Handler/RobloxConsoleHandler.luau +28 -99
- package/out/Monolog/Handler/WhatFailureGroupHandler.d.ts +26 -0
- package/out/Monolog/Handler/WhatFailureGroupHandler.luau +85 -0
- package/package.json +11 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* PHP: `Monolog\Handler\FormattableHandlerInterface`.
|
|
5
|
+
*
|
|
6
|
+
* Upstream pairs this with `FormattableHandlerTrait`; Luau has no traits, so
|
|
7
|
+
* implementers carry the `$formatter` field and `getDefaultFormatter()`
|
|
8
|
+
* themselves -- see `AbstractProcessingHandler`.
|
|
9
|
+
|
|
10
|
+
]]
|
|
11
|
+
--[[
|
|
12
|
+
*
|
|
13
|
+
* True when the given value implements `FormattableHandlerInterface`.
|
|
14
|
+
*
|
|
15
|
+
* PHP checks this with `instanceof`; there is no `instanceof` for an
|
|
16
|
+
* interface here, so this checks structurally for the two callable members,
|
|
17
|
+
* exactly as `isResettable()` (`ResettableInterface.ts`) already does.
|
|
18
|
+
|
|
19
|
+
]]
|
|
20
|
+
local function isFormattable(value)
|
|
21
|
+
local _value = value
|
|
22
|
+
if not (type(_value) == "table") then
|
|
23
|
+
return false
|
|
24
|
+
end
|
|
25
|
+
local candidate = value
|
|
26
|
+
local _setFormatter = candidate.setFormatter
|
|
27
|
+
local _condition = type(_setFormatter) == "function"
|
|
28
|
+
if _condition then
|
|
29
|
+
local _getFormatter = candidate.getFormatter
|
|
30
|
+
_condition = type(_getFormatter) == "function"
|
|
31
|
+
end
|
|
32
|
+
return _condition
|
|
33
|
+
end
|
|
34
|
+
return {
|
|
35
|
+
isFormattable = isFormattable,
|
|
36
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Handler } from "./Handler";
|
|
2
|
+
import type { FormatterInterface } from "../Formatter/FormatterInterface";
|
|
3
|
+
import type { HandlerInterface } from "./HandlerInterface";
|
|
4
|
+
import type { LogRecord } from "../LogRecord";
|
|
5
|
+
import type { Processor } from "../Processor/ProcessorInterface";
|
|
6
|
+
import type { ProcessableHandlerInterface } from "./ProcessableHandlerInterface";
|
|
7
|
+
import type { ResettableInterface } from "../ResettableInterface";
|
|
8
|
+
/**
|
|
9
|
+
* PHP: `Monolog\Handler\GroupHandler`. Forwards records to multiple handlers.
|
|
10
|
+
*
|
|
11
|
+
* Upstream gets its processor stack from `ProcessableHandlerTrait`; Luau has
|
|
12
|
+
* no traits, so the trait's members (`processors`, `processRecord()`,
|
|
13
|
+
* `resetProcessors()`, `pushProcessor()`, `popProcessor()`) are spelled out
|
|
14
|
+
* here, the same way `AbstractProcessingHandler` already folds it in.
|
|
15
|
+
*/
|
|
16
|
+
export declare class GroupHandler extends Handler implements ProcessableHandlerInterface, ResettableInterface {
|
|
17
|
+
protected processors: Processor[];
|
|
18
|
+
protected handlers: Array<HandlerInterface>;
|
|
19
|
+
protected bubble: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Upstream's `\InvalidArgumentException` for a non-handler in the array is
|
|
22
|
+
* kept rather than dropped: it is `GroupHandler`'s own explicit check, not
|
|
23
|
+
* PHP's parameter type-check, and this port is consumed from plain Luau
|
|
24
|
+
* too, where TypeScript's `Array<HandlerInterface>` proves nothing. There
|
|
25
|
+
* is no exception class hierarchy on this platform, so it is a plain
|
|
26
|
+
* `error()` carrying upstream's message.
|
|
27
|
+
*/
|
|
28
|
+
constructor(handlers: Array<HandlerInterface>, bubble?: boolean);
|
|
29
|
+
/** Checks whether any of the grouped handlers will handle the record. */
|
|
30
|
+
isHandling(record: LogRecord): boolean;
|
|
31
|
+
/** Handles a record, forwarding a clone of it to every grouped handler. */
|
|
32
|
+
handle(record: LogRecord): boolean;
|
|
33
|
+
/** Handles a set of records at once. */
|
|
34
|
+
handleBatch(records: Array<LogRecord>): void;
|
|
35
|
+
/** Adds a processor in the stack. */
|
|
36
|
+
pushProcessor(processor: Processor): this;
|
|
37
|
+
/** Removes the processor on top of the stack and returns it. */
|
|
38
|
+
popProcessor(): Processor | undefined;
|
|
39
|
+
/** Processes a record. */
|
|
40
|
+
protected processRecord(record: LogRecord): LogRecord;
|
|
41
|
+
/** Resets any processors on this handler that support resetting. */
|
|
42
|
+
protected resetProcessors(): void;
|
|
43
|
+
/** Resets this handler's processors and every grouped handler. */
|
|
44
|
+
reset(): void;
|
|
45
|
+
/** Closes every grouped handler. */
|
|
46
|
+
close(): void;
|
|
47
|
+
/** Sets the formatter on every grouped handler that supports one. */
|
|
48
|
+
setFormatter(formatter: FormatterInterface): this;
|
|
49
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local Handler = TS.import(script, script.Parent, "Handler").Handler
|
|
4
|
+
local isFormattable = TS.import(script, script.Parent, "FormattableHandlerInterface").isFormattable
|
|
5
|
+
local isHandler = TS.import(script, script.Parent, "HandlerInterface").isHandler
|
|
6
|
+
local isResettable = TS.import(script, script.Parent.Parent, "ResettableInterface").isResettable
|
|
7
|
+
local runProcessor = TS.import(script, script.Parent.Parent, "Processor", "ProcessorInterface").runProcessor
|
|
8
|
+
--[[
|
|
9
|
+
*
|
|
10
|
+
* PHP: `Monolog\Handler\GroupHandler`. Forwards records to multiple handlers.
|
|
11
|
+
*
|
|
12
|
+
* Upstream gets its processor stack from `ProcessableHandlerTrait`; Luau has
|
|
13
|
+
* no traits, so the trait's members (`processors`, `processRecord()`,
|
|
14
|
+
* `resetProcessors()`, `pushProcessor()`, `popProcessor()`) are spelled out
|
|
15
|
+
* here, the same way `AbstractProcessingHandler` already folds it in.
|
|
16
|
+
|
|
17
|
+
]]
|
|
18
|
+
local GroupHandler
|
|
19
|
+
do
|
|
20
|
+
local super = Handler
|
|
21
|
+
GroupHandler = setmetatable({}, {
|
|
22
|
+
__tostring = function()
|
|
23
|
+
return "GroupHandler"
|
|
24
|
+
end,
|
|
25
|
+
__index = super,
|
|
26
|
+
})
|
|
27
|
+
GroupHandler.__index = GroupHandler
|
|
28
|
+
function GroupHandler.new(...)
|
|
29
|
+
local self = setmetatable({}, GroupHandler)
|
|
30
|
+
return self:constructor(...) or self
|
|
31
|
+
end
|
|
32
|
+
function GroupHandler:constructor(handlers, bubble)
|
|
33
|
+
if bubble == nil then
|
|
34
|
+
bubble = true
|
|
35
|
+
end
|
|
36
|
+
super.constructor(self)
|
|
37
|
+
self.processors = {}
|
|
38
|
+
for _, handler in handlers do
|
|
39
|
+
if not isHandler(handler) then
|
|
40
|
+
error("The first argument of the GroupHandler must be an array of HandlerInterface instances.")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
self.handlers = handlers
|
|
44
|
+
self.bubble = bubble
|
|
45
|
+
end
|
|
46
|
+
function GroupHandler:isHandling(record)
|
|
47
|
+
for _, handler in self.handlers do
|
|
48
|
+
if handler:isHandling(record) then
|
|
49
|
+
return true
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
return false
|
|
53
|
+
end
|
|
54
|
+
function GroupHandler:handle(record)
|
|
55
|
+
local processed = record
|
|
56
|
+
if not (#self.processors == 0) then
|
|
57
|
+
processed = self:processRecord(processed)
|
|
58
|
+
end
|
|
59
|
+
for _, handler in self.handlers do
|
|
60
|
+
handler:handle(processed:clone())
|
|
61
|
+
end
|
|
62
|
+
return self.bubble == false
|
|
63
|
+
end
|
|
64
|
+
function GroupHandler:handleBatch(records)
|
|
65
|
+
local batch = records
|
|
66
|
+
if not (#self.processors == 0) then
|
|
67
|
+
-- ▼ ReadonlyArray.map ▼
|
|
68
|
+
local _newValue = table.create(#records)
|
|
69
|
+
local _callback = function(record)
|
|
70
|
+
return self:processRecord(record)
|
|
71
|
+
end
|
|
72
|
+
for _k, _v in records do
|
|
73
|
+
_newValue[_k] = _callback(_v, _k - 1, records)
|
|
74
|
+
end
|
|
75
|
+
-- ▲ ReadonlyArray.map ▲
|
|
76
|
+
batch = _newValue
|
|
77
|
+
end
|
|
78
|
+
for _, handler in self.handlers do
|
|
79
|
+
-- ▼ ReadonlyArray.map ▼
|
|
80
|
+
local _newValue = table.create(#batch)
|
|
81
|
+
local _callback = function(record)
|
|
82
|
+
return record:clone()
|
|
83
|
+
end
|
|
84
|
+
for _k, _v in batch do
|
|
85
|
+
_newValue[_k] = _callback(_v, _k - 1, batch)
|
|
86
|
+
end
|
|
87
|
+
-- ▲ ReadonlyArray.map ▲
|
|
88
|
+
handler:handleBatch(_newValue)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
function GroupHandler:pushProcessor(processor)
|
|
92
|
+
local _processors = self.processors
|
|
93
|
+
local _processor = processor
|
|
94
|
+
table.insert(_processors, 1, _processor)
|
|
95
|
+
return self
|
|
96
|
+
end
|
|
97
|
+
function GroupHandler:popProcessor()
|
|
98
|
+
return table.remove(self.processors, 1)
|
|
99
|
+
end
|
|
100
|
+
function GroupHandler:processRecord(record)
|
|
101
|
+
local processed = record
|
|
102
|
+
for _, processor in self.processors do
|
|
103
|
+
processed = runProcessor(processor, processed)
|
|
104
|
+
end
|
|
105
|
+
return processed
|
|
106
|
+
end
|
|
107
|
+
function GroupHandler:resetProcessors()
|
|
108
|
+
for _, processor in self.processors do
|
|
109
|
+
if isResettable(processor) then
|
|
110
|
+
processor:reset()
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
function GroupHandler:reset()
|
|
115
|
+
self:resetProcessors()
|
|
116
|
+
for _, handler in self.handlers do
|
|
117
|
+
if isResettable(handler) then
|
|
118
|
+
handler:reset()
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
function GroupHandler:close()
|
|
123
|
+
super.close(self)
|
|
124
|
+
for _, handler in self.handlers do
|
|
125
|
+
handler:close()
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
function GroupHandler:setFormatter(formatter)
|
|
129
|
+
for _, handler in self.handlers do
|
|
130
|
+
if isFormattable(handler) then
|
|
131
|
+
handler:setFormatter(formatter)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
return self
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
return {
|
|
138
|
+
GroupHandler = GroupHandler,
|
|
139
|
+
}
|
|
@@ -10,3 +10,13 @@ export interface HandlerInterface {
|
|
|
10
10
|
/** Closes the handler. */
|
|
11
11
|
close(): void;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* True when the given value implements `HandlerInterface`.
|
|
15
|
+
*
|
|
16
|
+
* PHP checks this with `instanceof` -- `GroupHandler`'s constructor and
|
|
17
|
+
* `FingersCrossedHandler::getHandler()` both reject a non-handler at runtime.
|
|
18
|
+
* There is no `instanceof` for an interface here, so this checks structurally
|
|
19
|
+
* for the four callable members, as `isResettable()`
|
|
20
|
+
* (`ResettableInterface.ts`) already does for its own interface.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isHandler(value: unknown): value is HandlerInterface;
|
|
@@ -1,3 +1,38 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
2
|
--* PHP: `Monolog\Handler\HandlerInterface`.
|
|
3
|
-
|
|
3
|
+
--[[
|
|
4
|
+
*
|
|
5
|
+
* True when the given value implements `HandlerInterface`.
|
|
6
|
+
*
|
|
7
|
+
* PHP checks this with `instanceof` -- `GroupHandler`'s constructor and
|
|
8
|
+
* `FingersCrossedHandler::getHandler()` both reject a non-handler at runtime.
|
|
9
|
+
* There is no `instanceof` for an interface here, so this checks structurally
|
|
10
|
+
* for the four callable members, as `isResettable()`
|
|
11
|
+
* (`ResettableInterface.ts`) already does for its own interface.
|
|
12
|
+
|
|
13
|
+
]]
|
|
14
|
+
local function isHandler(value)
|
|
15
|
+
local _value = value
|
|
16
|
+
if not (type(_value) == "table") then
|
|
17
|
+
return false
|
|
18
|
+
end
|
|
19
|
+
local candidate = value
|
|
20
|
+
local _isHandling = candidate.isHandling
|
|
21
|
+
local _condition = type(_isHandling) == "function"
|
|
22
|
+
if _condition then
|
|
23
|
+
local _handle = candidate.handle
|
|
24
|
+
_condition = type(_handle) == "function"
|
|
25
|
+
if _condition then
|
|
26
|
+
local _handleBatch = candidate.handleBatch
|
|
27
|
+
_condition = type(_handleBatch) == "function"
|
|
28
|
+
if _condition then
|
|
29
|
+
local _close = candidate.close
|
|
30
|
+
_condition = type(_close) == "function"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
return _condition
|
|
35
|
+
end
|
|
36
|
+
return {
|
|
37
|
+
isHandler = isHandler,
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { HandlerInterface } from "./HandlerInterface";
|
|
2
|
+
import type { Processor } from "../Processor/ProcessorInterface";
|
|
3
|
+
/**
|
|
4
|
+
* PHP: `Monolog\Handler\ProcessableHandlerInterface`.
|
|
5
|
+
*
|
|
6
|
+
* Upstream pairs this with `ProcessableHandlerTrait`, which carries the
|
|
7
|
+
* `$processors` stack and the `processRecord()`/`resetProcessors()` helpers.
|
|
8
|
+
* Luau has no traits, so every implementer in this port spells those members
|
|
9
|
+
* out itself -- `AbstractProcessingHandler`, `GroupHandler` and
|
|
10
|
+
* `FingersCrossedHandler` each carry their own copy, the same way
|
|
11
|
+
* `AbstractProcessingHandler` already folded the trait in before this
|
|
12
|
+
* interface existed.
|
|
13
|
+
*/
|
|
14
|
+
export interface ProcessableHandlerInterface extends HandlerInterface {
|
|
15
|
+
/** Adds a processor in the stack. */
|
|
16
|
+
pushProcessor(processor: Processor): this;
|
|
17
|
+
/**
|
|
18
|
+
* Removes the processor on top of the stack and returns it.
|
|
19
|
+
*
|
|
20
|
+
* Upstream throws `\LogicException` when the stack is empty; every
|
|
21
|
+
* pop-style method in this port (`Logger.popHandler()`,
|
|
22
|
+
* `AbstractProcessingHandler.popProcessor()`) returns `undefined` instead,
|
|
23
|
+
* and this signature follows them rather than upstream.
|
|
24
|
+
*/
|
|
25
|
+
popProcessor(): Processor | undefined;
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* PHP: `Monolog\Handler\ProcessableHandlerInterface`.
|
|
5
|
+
*
|
|
6
|
+
* Upstream pairs this with `ProcessableHandlerTrait`, which carries the
|
|
7
|
+
* `$processors` stack and the `processRecord()`/`resetProcessors()` helpers.
|
|
8
|
+
* Luau has no traits, so every implementer in this port spells those members
|
|
9
|
+
* out itself -- `AbstractProcessingHandler`, `GroupHandler` and
|
|
10
|
+
* `FingersCrossedHandler` each carry their own copy, the same way
|
|
11
|
+
* `AbstractProcessingHandler` already folded the trait in before this
|
|
12
|
+
* interface existed.
|
|
13
|
+
|
|
14
|
+
]]
|
|
15
|
+
return nil
|
|
@@ -1,55 +1,28 @@
|
|
|
1
1
|
import { AbstractProcessingHandler } from "./AbstractProcessingHandler";
|
|
2
2
|
import { Level } from "../Level";
|
|
3
|
-
import type { FormatterInterface } from "../Formatter/FormatterInterface";
|
|
4
3
|
import type { LogRecord } from "../LogRecord";
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* Writes formatted records to the Roblox output console.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* (`
|
|
18
|
-
* `
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
7
|
+
* No upstream ancestor: this is an original class for this platform.
|
|
8
|
+
*
|
|
9
|
+
* By shape it is this platform's `Monolog\Handler\StreamHandler`: hand
|
|
10
|
+
* `record.formatted` to the sink and nothing more. Roblox's console is that
|
|
11
|
+
* sink, and none of `StreamHandler`'s own API survives the swap -- there is
|
|
12
|
+
* no stream to open, no url/resource to accept, no file permissions, no
|
|
13
|
+
* `close()`, no buffering to flush. What is left is the level/bubble pair
|
|
14
|
+
* every handler has, plus the one choice the console does offer: records
|
|
15
|
+
* below `Level.Warning` go out through `print` (`MessageOutput`), the rest
|
|
16
|
+
* through `warn` (`MessageWarning`), so Studio colors them accordingly and
|
|
17
|
+
* `LogService` reports the right `Enum.MessageType`. `error` is deliberately
|
|
18
|
+
* not used for higher levels -- on Luau it throws and unwinds the caller
|
|
19
|
+
* instead of merely writing a line.
|
|
20
|
+
*
|
|
21
|
+
* The formatter is respected, unlike the PHP Console port that preceded this
|
|
22
|
+
* one: it is what turns the record into the printed text. The default is
|
|
23
|
+
* `AbstractProcessingHandler`'s own `LineFormatter`.
|
|
24
24
|
*/
|
|
25
|
-
export interface Options {
|
|
26
|
-
/** Whether this handler is active at all. */
|
|
27
|
-
enabled: boolean;
|
|
28
|
-
/** Context keys checked, in order, for a debug "tag" to prefix the message with. */
|
|
29
|
-
debugTagsKeysInContext: Array<string>;
|
|
30
|
-
}
|
|
31
25
|
export declare class RobloxConsoleHandler extends AbstractProcessingHandler {
|
|
32
|
-
|
|
33
|
-
constructor(options?: Partial<Options>, level?: Level, bubble?: boolean);
|
|
34
|
-
/** PHP: `PHPConsoleHandler::getOptions()`. */
|
|
35
|
-
getOptions(): Options;
|
|
36
|
-
/** PHP: `PHPConsoleHandler::handle()`. */
|
|
37
|
-
handle(record: LogRecord): boolean;
|
|
38
|
-
/** PHP: `PHPConsoleHandler::write()`. */
|
|
26
|
+
constructor(level?: Level, bubble?: boolean);
|
|
39
27
|
protected write(record: LogRecord): void;
|
|
40
|
-
/** PHP: `PHPConsoleHandler::handleDebugRecord()`. */
|
|
41
|
-
private writeDebugRecord;
|
|
42
|
-
/** PHP: `PHPConsoleHandler::handleExceptionRecord()`. */
|
|
43
|
-
private writeExceptionRecord;
|
|
44
|
-
/** PHP: `PHPConsoleHandler::handleErrorRecord()`. */
|
|
45
|
-
private writeErrorRecord;
|
|
46
|
-
/**
|
|
47
|
-
* PHP: `PHPConsoleHandler::getRecordTags()`. Upstream also checks
|
|
48
|
-
* `$filteredContext[0]`, PHP's implicit first-array-index -- Luau/TS have
|
|
49
|
-
* no positional index on a `RecordBag`, so only the named
|
|
50
|
-
* `debugTagsKeysInContext` keys are checked.
|
|
51
|
-
*/
|
|
52
|
-
private getRecordTags;
|
|
53
|
-
/** PHP: `PHPConsoleHandler::getDefaultFormatter()`. */
|
|
54
|
-
protected getDefaultFormatter(): FormatterInterface;
|
|
55
28
|
}
|
|
@@ -4,36 +4,29 @@ local AbstractProcessingHandler = TS.import(script, script.Parent, "AbstractProc
|
|
|
4
4
|
local _Level = TS.import(script, script.Parent.Parent, "Level")
|
|
5
5
|
local Level = _Level.Level
|
|
6
6
|
local Levels = _Level.Levels
|
|
7
|
-
local LineFormatter = TS.import(script, script.Parent.Parent, "Formatter", "LineFormatter").LineFormatter
|
|
8
|
-
local Utils = TS.import(script, script.Parent.Parent, "Utils").Utils
|
|
9
7
|
--[[
|
|
10
8
|
*
|
|
11
|
-
*
|
|
9
|
+
* Writes formatted records to the Roblox output console.
|
|
12
10
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* configure with them.
|
|
11
|
+
* No upstream ancestor: this is an original class for this platform.
|
|
12
|
+
*
|
|
13
|
+
* By shape it is this platform's `Monolog\Handler\StreamHandler`: hand
|
|
14
|
+
* `record.formatted` to the sink and nothing more. Roblox's console is that
|
|
15
|
+
* sink, and none of `StreamHandler`'s own API survives the swap -- there is
|
|
16
|
+
* no stream to open, no url/resource to accept, no file permissions, no
|
|
17
|
+
* `close()`, no buffering to flush. What is left is the level/bubble pair
|
|
18
|
+
* every handler has, plus the one choice the console does offer: records
|
|
19
|
+
* below `Level.Warning` go out through `print` (`MessageOutput`), the rest
|
|
20
|
+
* through `warn` (`MessageWarning`), so Studio colors them accordingly and
|
|
21
|
+
* `LogService` reports the right `Enum.MessageType`. `error` is deliberately
|
|
22
|
+
* not used for higher levels -- on Luau it throws and unwinds the caller
|
|
23
|
+
* instead of merely writing a line.
|
|
24
|
+
*
|
|
25
|
+
* The formatter is respected, unlike the PHP Console port that preceded this
|
|
26
|
+
* one: it is what turns the record into the printed text. The default is
|
|
27
|
+
* `AbstractProcessingHandler`'s own `LineFormatter`.
|
|
31
28
|
|
|
32
29
|
]]
|
|
33
|
-
local DEFAULT_OPTIONS = {
|
|
34
|
-
enabled = true,
|
|
35
|
-
debugTagsKeysInContext = { "tag" },
|
|
36
|
-
}
|
|
37
30
|
local RobloxConsoleHandler
|
|
38
31
|
do
|
|
39
32
|
local super = AbstractProcessingHandler
|
|
@@ -48,10 +41,7 @@ do
|
|
|
48
41
|
local self = setmetatable({}, RobloxConsoleHandler)
|
|
49
42
|
return self:constructor(...) or self
|
|
50
43
|
end
|
|
51
|
-
function RobloxConsoleHandler:constructor(
|
|
52
|
-
if options == nil then
|
|
53
|
-
options = {}
|
|
54
|
-
end
|
|
44
|
+
function RobloxConsoleHandler:constructor(level, bubble)
|
|
55
45
|
if level == nil then
|
|
56
46
|
level = Level.Debug
|
|
57
47
|
end
|
|
@@ -59,81 +49,20 @@ do
|
|
|
59
49
|
bubble = true
|
|
60
50
|
end
|
|
61
51
|
super.constructor(self, level, bubble)
|
|
62
|
-
local _object = {}
|
|
63
|
-
local _left = "enabled"
|
|
64
|
-
local _condition = options.enabled
|
|
65
|
-
if _condition == nil then
|
|
66
|
-
_condition = DEFAULT_OPTIONS.enabled
|
|
67
|
-
end
|
|
68
|
-
_object[_left] = _condition
|
|
69
|
-
_object.debugTagsKeysInContext = options.debugTagsKeysInContext or DEFAULT_OPTIONS.debugTagsKeysInContext
|
|
70
|
-
self.options = _object
|
|
71
|
-
end
|
|
72
|
-
function RobloxConsoleHandler:getOptions()
|
|
73
|
-
return self.options
|
|
74
|
-
end
|
|
75
|
-
function RobloxConsoleHandler:handle(record)
|
|
76
|
-
if self.options.enabled then
|
|
77
|
-
return super.handle(self, record)
|
|
78
|
-
end
|
|
79
|
-
-- Upstream also requires `connector.isActiveClient()` here; there is no
|
|
80
|
-
-- connector to ask, so `enabled` is the only gate left.
|
|
81
|
-
return not self.bubble
|
|
82
52
|
end
|
|
83
53
|
function RobloxConsoleHandler:write(record)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
self:writeErrorRecord(record)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
function RobloxConsoleHandler:writeDebugRecord(record)
|
|
93
|
-
local _binding = self:getRecordTags(record)
|
|
94
|
-
local tags = _binding[1]
|
|
95
|
-
local filteredContext = _binding[2]
|
|
96
|
-
local message = record.message
|
|
97
|
-
if (next(filteredContext)) ~= nil then
|
|
98
|
-
message = `{message} {Utils:jsonEncode(filteredContext)}`
|
|
54
|
+
-- `handle()` always fills `formatted` in before calling `write()`;
|
|
55
|
+
-- the fallback is for a direct call that did not go through it.
|
|
56
|
+
local _condition = record.formatted
|
|
57
|
+
if _condition == nil then
|
|
58
|
+
_condition = record.message
|
|
99
59
|
end
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
warn(tostring(record.context.exception))
|
|
104
|
-
end
|
|
105
|
-
function RobloxConsoleHandler:writeErrorRecord(record)
|
|
106
|
-
local context = record.context
|
|
107
|
-
local message = if context.message ~= nil then tostring(context.message) else record.message
|
|
108
|
-
if context.file == nil and context.line == nil then
|
|
109
|
-
warn(message)
|
|
60
|
+
local message = _condition
|
|
61
|
+
if Levels:isLowerThan(record.level, Level.Warning) then
|
|
62
|
+
print(message)
|
|
110
63
|
return nil
|
|
111
64
|
end
|
|
112
|
-
|
|
113
|
-
local line = if context.line ~= nil then tostring(context.line) else "?"
|
|
114
|
-
warn(`{message} ({file}:{line})`)
|
|
115
|
-
end
|
|
116
|
-
function RobloxConsoleHandler:getRecordTags(record)
|
|
117
|
-
local filteredContext = {}
|
|
118
|
-
for key, value in pairs(record.context) do
|
|
119
|
-
filteredContext[key] = value
|
|
120
|
-
end
|
|
121
|
-
local tag
|
|
122
|
-
for _, key in self.options.debugTagsKeysInContext do
|
|
123
|
-
if filteredContext[key] ~= nil then
|
|
124
|
-
tag = tostring(filteredContext[key])
|
|
125
|
-
filteredContext[key] = nil
|
|
126
|
-
break
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
local _condition = tag
|
|
130
|
-
if _condition == nil then
|
|
131
|
-
_condition = Levels:toPsrLogLevel(record.level)
|
|
132
|
-
end
|
|
133
|
-
return { _condition, filteredContext }
|
|
134
|
-
end
|
|
135
|
-
function RobloxConsoleHandler:getDefaultFormatter()
|
|
136
|
-
return LineFormatter.new("%message%")
|
|
65
|
+
warn(message)
|
|
137
66
|
end
|
|
138
67
|
end
|
|
139
68
|
return {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { GroupHandler } from "./GroupHandler";
|
|
2
|
+
import type { LogRecord } from "../LogRecord";
|
|
3
|
+
/**
|
|
4
|
+
* PHP: `Monolog\Handler\WhatFailureGroupHandler`.
|
|
5
|
+
*
|
|
6
|
+
* Forwards records to multiple handlers, suppressing failures of each handler
|
|
7
|
+
* and continuing through to give every handler a chance to succeed.
|
|
8
|
+
*
|
|
9
|
+
* Upstream wraps each call in `try { ... } catch (Throwable) {}`. Luau's
|
|
10
|
+
* error mechanism is `error()`/`pcall()`, not exceptions, so each call goes
|
|
11
|
+
* through `pcall()` and its failure result is discarded -- same "what
|
|
12
|
+
* failure?" semantics, same swallow-everything breadth.
|
|
13
|
+
*/
|
|
14
|
+
export declare class WhatFailureGroupHandler extends GroupHandler {
|
|
15
|
+
/** Handles a record, letting every grouped handler fail independently. */
|
|
16
|
+
handle(record: LogRecord): boolean;
|
|
17
|
+
/** Handles a set of records at once, ignoring any handler that fails. */
|
|
18
|
+
handleBatch(records: Array<LogRecord>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Closes every grouped handler, ignoring any that fails.
|
|
21
|
+
*
|
|
22
|
+
* Upstream deliberately does not call `parent::close()` here (unlike
|
|
23
|
+
* `GroupHandler::close()`), so neither does this.
|
|
24
|
+
*/
|
|
25
|
+
close(): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local GroupHandler = TS.import(script, script.Parent, "GroupHandler").GroupHandler
|
|
4
|
+
--[[
|
|
5
|
+
*
|
|
6
|
+
* PHP: `Monolog\Handler\WhatFailureGroupHandler`.
|
|
7
|
+
*
|
|
8
|
+
* Forwards records to multiple handlers, suppressing failures of each handler
|
|
9
|
+
* and continuing through to give every handler a chance to succeed.
|
|
10
|
+
*
|
|
11
|
+
* Upstream wraps each call in `try { ... } catch (Throwable) {}`. Luau's
|
|
12
|
+
* error mechanism is `error()`/`pcall()`, not exceptions, so each call goes
|
|
13
|
+
* through `pcall()` and its failure result is discarded -- same "what
|
|
14
|
+
* failure?" semantics, same swallow-everything breadth.
|
|
15
|
+
|
|
16
|
+
]]
|
|
17
|
+
local WhatFailureGroupHandler
|
|
18
|
+
do
|
|
19
|
+
local super = GroupHandler
|
|
20
|
+
WhatFailureGroupHandler = setmetatable({}, {
|
|
21
|
+
__tostring = function()
|
|
22
|
+
return "WhatFailureGroupHandler"
|
|
23
|
+
end,
|
|
24
|
+
__index = super,
|
|
25
|
+
})
|
|
26
|
+
WhatFailureGroupHandler.__index = WhatFailureGroupHandler
|
|
27
|
+
function WhatFailureGroupHandler.new(...)
|
|
28
|
+
local self = setmetatable({}, WhatFailureGroupHandler)
|
|
29
|
+
return self:constructor(...) or self
|
|
30
|
+
end
|
|
31
|
+
function WhatFailureGroupHandler:constructor(...)
|
|
32
|
+
super.constructor(self, ...)
|
|
33
|
+
end
|
|
34
|
+
function WhatFailureGroupHandler:handle(record)
|
|
35
|
+
local processed = record
|
|
36
|
+
if not (#self.processors == 0) then
|
|
37
|
+
processed = self:processRecord(processed)
|
|
38
|
+
end
|
|
39
|
+
for _, handler in self.handlers do
|
|
40
|
+
pcall(function()
|
|
41
|
+
return handler:handle(processed:clone())
|
|
42
|
+
end)
|
|
43
|
+
end
|
|
44
|
+
return self.bubble == false
|
|
45
|
+
end
|
|
46
|
+
function WhatFailureGroupHandler:handleBatch(records)
|
|
47
|
+
local batch = records
|
|
48
|
+
if not (#self.processors == 0) then
|
|
49
|
+
-- ▼ ReadonlyArray.map ▼
|
|
50
|
+
local _newValue = table.create(#records)
|
|
51
|
+
local _callback = function(record)
|
|
52
|
+
return self:processRecord(record)
|
|
53
|
+
end
|
|
54
|
+
for _k, _v in records do
|
|
55
|
+
_newValue[_k] = _callback(_v, _k - 1, records)
|
|
56
|
+
end
|
|
57
|
+
-- ▲ ReadonlyArray.map ▲
|
|
58
|
+
batch = _newValue
|
|
59
|
+
end
|
|
60
|
+
for _, handler in self.handlers do
|
|
61
|
+
pcall(function()
|
|
62
|
+
-- ▼ ReadonlyArray.map ▼
|
|
63
|
+
local _newValue = table.create(#batch)
|
|
64
|
+
local _callback = function(record)
|
|
65
|
+
return record:clone()
|
|
66
|
+
end
|
|
67
|
+
for _k, _v in batch do
|
|
68
|
+
_newValue[_k] = _callback(_v, _k - 1, batch)
|
|
69
|
+
end
|
|
70
|
+
-- ▲ ReadonlyArray.map ▲
|
|
71
|
+
return handler:handleBatch(_newValue)
|
|
72
|
+
end)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
function WhatFailureGroupHandler:close()
|
|
76
|
+
for _, handler in self.handlers do
|
|
77
|
+
pcall(function()
|
|
78
|
+
return handler:close()
|
|
79
|
+
end)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
return {
|
|
84
|
+
WhatFailureGroupHandler = WhatFailureGroupHandler,
|
|
85
|
+
}
|