@larablox/monolog 0.1.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/out/Monolog/Attribute/AsMonologProcessor.d.ts +30 -0
- package/out/Monolog/Attribute/AsMonologProcessor.luau +59 -0
- package/out/Monolog/Attribute/WithMonologChannel.d.ts +18 -0
- package/out/Monolog/Attribute/WithMonologChannel.luau +33 -0
- package/out/Monolog/Formatter/FormatterInterface.d.ts +8 -0
- package/out/Monolog/Formatter/FormatterInterface.luau +3 -0
- package/out/Monolog/Formatter/HtmlFormatter.d.ts +23 -0
- package/out/Monolog/Formatter/HtmlFormatter.luau +128 -0
- package/out/Monolog/Formatter/JsonFormatter.d.ts +34 -0
- package/out/Monolog/Formatter/JsonFormatter.luau +114 -0
- package/out/Monolog/Formatter/LineFormatter.d.ts +52 -0
- package/out/Monolog/Formatter/LineFormatter.luau +228 -0
- package/out/Monolog/Formatter/NormalizerFormatter.d.ts +87 -0
- package/out/Monolog/Formatter/NormalizerFormatter.luau +214 -0
- package/out/Monolog/Formatter/ScalarFormatter.d.ts +19 -0
- package/out/Monolog/Formatter/ScalarFormatter.luau +53 -0
- package/out/Monolog/Handler/AbstractHandler.d.ts +22 -0
- package/out/Monolog/Handler/AbstractHandler.luau +50 -0
- package/out/Monolog/Handler/AbstractProcessingHandler.d.ts +30 -0
- package/out/Monolog/Handler/AbstractProcessingHandler.luau +79 -0
- package/out/Monolog/Handler/Handler.d.ts +15 -0
- package/out/Monolog/Handler/Handler.luau +25 -0
- package/out/Monolog/Handler/HandlerInterface.d.ts +12 -0
- package/out/Monolog/Handler/HandlerInterface.luau +3 -0
- package/out/Monolog/Handler/NullHandler.d.ts +10 -0
- package/out/Monolog/Handler/NullHandler.luau +36 -0
- package/out/Monolog/Handler/RobloxConsoleHandler.d.ts +55 -0
- package/out/Monolog/Handler/RobloxConsoleHandler.luau +141 -0
- package/out/Monolog/Handler/TestHandler.d.ts +90 -0
- package/out/Monolog/Handler/TestHandler.luau +288 -0
- package/out/Monolog/Level.d.ts +38 -0
- package/out/Monolog/Level.luau +119 -0
- package/out/Monolog/LogRecord.d.ts +43 -0
- package/out/Monolog/LogRecord.luau +77 -0
- package/out/Monolog/Logger.d.ts +93 -0
- package/out/Monolog/Logger.luau +248 -0
- package/out/Monolog/LoggerInterface.d.ts +33 -0
- package/out/Monolog/LoggerInterface.luau +15 -0
- package/out/Monolog/Processor/ClosureContextProcessor.d.ts +13 -0
- package/out/Monolog/Processor/ClosureContextProcessor.luau +76 -0
- package/out/Monolog/Processor/IntrospectionProcessor.d.ts +33 -0
- package/out/Monolog/Processor/IntrospectionProcessor.luau +69 -0
- package/out/Monolog/Processor/MemoryPeakUsageProcessor.d.ts +17 -0
- package/out/Monolog/Processor/MemoryPeakUsageProcessor.luau +49 -0
- package/out/Monolog/Processor/MemoryProcessor.d.ts +20 -0
- package/out/Monolog/Processor/MemoryProcessor.luau +41 -0
- package/out/Monolog/Processor/MemoryUsageProcessor.d.ts +12 -0
- package/out/Monolog/Processor/MemoryUsageProcessor.luau +38 -0
- package/out/Monolog/Processor/ProcessIdProcessor.d.ts +13 -0
- package/out/Monolog/Processor/ProcessIdProcessor.luau +33 -0
- package/out/Monolog/Processor/ProcessorInterface.d.ts +13 -0
- package/out/Monolog/Processor/ProcessorInterface.luau +20 -0
- package/out/Monolog/Processor/PsrLogMessageProcessor.d.ts +12 -0
- package/out/Monolog/Processor/PsrLogMessageProcessor.luau +62 -0
- package/out/Monolog/Processor/TagProcessor.d.ts +12 -0
- package/out/Monolog/Processor/TagProcessor.luau +46 -0
- package/out/Monolog/Processor/UidProcessor.d.ts +18 -0
- package/out/Monolog/Processor/UidProcessor.luau +53 -0
- package/out/Monolog/Registry.d.ts +21 -0
- package/out/Monolog/Registry.luau +86 -0
- package/out/Monolog/ResettableInterface.d.ts +11 -0
- package/out/Monolog/ResettableInterface.luau +21 -0
- package/out/Monolog/Test/MonologTestCase.d.ts +26 -0
- package/out/Monolog/Test/MonologTestCase.luau +73 -0
- package/out/Monolog/Test/TestCase.d.ts +4 -0
- package/out/Monolog/Test/TestCase.luau +25 -0
- package/out/Monolog/Utils.d.ts +21 -0
- package/out/Monolog/Utils.luau +181 -0
- package/out/index.d.ts +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* PHP: `Monolog\Processor\ProcessIdProcessor`.
|
|
5
|
+
*
|
|
6
|
+
* There is no OS process id on Roblox. `game.JobId` is the closest identifier
|
|
7
|
+
* for "which running process is this" -- a string, not the int
|
|
8
|
+
* `getmypid()` returns, and empty outside a real server (e.g. Studio Play
|
|
9
|
+
* testing), where it falls back to `"studio"`.
|
|
10
|
+
|
|
11
|
+
]]
|
|
12
|
+
local ProcessIdProcessor
|
|
13
|
+
do
|
|
14
|
+
ProcessIdProcessor = setmetatable({}, {
|
|
15
|
+
__tostring = function()
|
|
16
|
+
return "ProcessIdProcessor"
|
|
17
|
+
end,
|
|
18
|
+
})
|
|
19
|
+
ProcessIdProcessor.__index = ProcessIdProcessor
|
|
20
|
+
function ProcessIdProcessor.new(...)
|
|
21
|
+
local self = setmetatable({}, ProcessIdProcessor)
|
|
22
|
+
return self:constructor(...) or self
|
|
23
|
+
end
|
|
24
|
+
function ProcessIdProcessor:constructor()
|
|
25
|
+
end
|
|
26
|
+
function ProcessIdProcessor:process(record)
|
|
27
|
+
record.extra.process_id = if game.JobId ~= "" then game.JobId else "studio"
|
|
28
|
+
return record
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
return {
|
|
32
|
+
ProcessIdProcessor = ProcessIdProcessor,
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LogRecord } from "../LogRecord";
|
|
2
|
+
/**
|
|
3
|
+
* PHP: `Monolog\Processor\ProcessorInterface`, whose instances are invoked
|
|
4
|
+
* through `__invoke`. Luau has no callable objects, so a processor is either a
|
|
5
|
+
* plain function or an object with a `process` method.
|
|
6
|
+
*/
|
|
7
|
+
export interface ProcessorInterface {
|
|
8
|
+
process(record: LogRecord): LogRecord;
|
|
9
|
+
}
|
|
10
|
+
/** What `pushProcessor()` accepts. */
|
|
11
|
+
export type Processor = ProcessorInterface | ((record: LogRecord) => LogRecord);
|
|
12
|
+
/** Run a processor whichever shape it has. */
|
|
13
|
+
export declare function runProcessor(processor: Processor, record: LogRecord): LogRecord;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* PHP: `Monolog\Processor\ProcessorInterface`, whose instances are invoked
|
|
5
|
+
* through `__invoke`. Luau has no callable objects, so a processor is either a
|
|
6
|
+
* plain function or an object with a `process` method.
|
|
7
|
+
|
|
8
|
+
]]
|
|
9
|
+
--* What `pushProcessor()` accepts.
|
|
10
|
+
--* Run a processor whichever shape it has.
|
|
11
|
+
local function runProcessor(processor, record)
|
|
12
|
+
local _processor = processor
|
|
13
|
+
if type(_processor) == "function" then
|
|
14
|
+
return processor(record)
|
|
15
|
+
end
|
|
16
|
+
return processor:process(record)
|
|
17
|
+
end
|
|
18
|
+
return {
|
|
19
|
+
runProcessor = runProcessor,
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LogRecord } from "../LogRecord";
|
|
2
|
+
import type { ProcessorInterface } from "./ProcessorInterface";
|
|
3
|
+
/**
|
|
4
|
+
* PHP: `Monolog\Processor\PsrLogMessageProcessor`.
|
|
5
|
+
*
|
|
6
|
+
* Replaces `{placeholder}` in the message with the matching context value.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PsrLogMessageProcessor implements ProcessorInterface {
|
|
9
|
+
protected readonly removeUsedContextFields: boolean;
|
|
10
|
+
constructor(removeUsedContextFields?: boolean);
|
|
11
|
+
process(record: LogRecord): LogRecord;
|
|
12
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* PHP: `Monolog\Processor\PsrLogMessageProcessor`.
|
|
5
|
+
*
|
|
6
|
+
* Replaces `{placeholder}` in the message with the matching context value.
|
|
7
|
+
|
|
8
|
+
]]
|
|
9
|
+
local PsrLogMessageProcessor
|
|
10
|
+
do
|
|
11
|
+
PsrLogMessageProcessor = setmetatable({}, {
|
|
12
|
+
__tostring = function()
|
|
13
|
+
return "PsrLogMessageProcessor"
|
|
14
|
+
end,
|
|
15
|
+
})
|
|
16
|
+
PsrLogMessageProcessor.__index = PsrLogMessageProcessor
|
|
17
|
+
function PsrLogMessageProcessor.new(...)
|
|
18
|
+
local self = setmetatable({}, PsrLogMessageProcessor)
|
|
19
|
+
return self:constructor(...) or self
|
|
20
|
+
end
|
|
21
|
+
function PsrLogMessageProcessor:constructor(removeUsedContextFields)
|
|
22
|
+
if removeUsedContextFields == nil then
|
|
23
|
+
removeUsedContextFields = false
|
|
24
|
+
end
|
|
25
|
+
self.removeUsedContextFields = removeUsedContextFields
|
|
26
|
+
end
|
|
27
|
+
function PsrLogMessageProcessor:process(record)
|
|
28
|
+
if (string.find(record.message, "{", 1, true)) == nil then
|
|
29
|
+
return record
|
|
30
|
+
end
|
|
31
|
+
local message = record.message
|
|
32
|
+
local context = {}
|
|
33
|
+
for key, value in pairs(record.context) do
|
|
34
|
+
context[key] = value
|
|
35
|
+
end
|
|
36
|
+
for key, value in pairs(record.context) do
|
|
37
|
+
local placeholder = `\{{key}\}`
|
|
38
|
+
if (string.find(message, placeholder, 1, true)) == nil then
|
|
39
|
+
continue
|
|
40
|
+
end
|
|
41
|
+
local _exp = string.split(message, placeholder)
|
|
42
|
+
local _arg0 = tostring(value)
|
|
43
|
+
-- ▼ ReadonlyArray.join ▼
|
|
44
|
+
local _arg0_1 = _arg0
|
|
45
|
+
if _arg0_1 == nil then
|
|
46
|
+
_arg0_1 = ", "
|
|
47
|
+
end
|
|
48
|
+
-- ▲ ReadonlyArray.join ▲
|
|
49
|
+
message = table.concat(_exp, _arg0_1)
|
|
50
|
+
if self.removeUsedContextFields then
|
|
51
|
+
context[key] = nil
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
return record:with({
|
|
55
|
+
message = message,
|
|
56
|
+
context = context,
|
|
57
|
+
})
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
return {
|
|
61
|
+
PsrLogMessageProcessor = PsrLogMessageProcessor,
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LogRecord } from "../LogRecord";
|
|
2
|
+
import type { ProcessorInterface } from "./ProcessorInterface";
|
|
3
|
+
/** PHP: `Monolog\Processor\TagProcessor`. */
|
|
4
|
+
export declare class TagProcessor implements ProcessorInterface {
|
|
5
|
+
private tags;
|
|
6
|
+
constructor(tags?: Array<string>);
|
|
7
|
+
/** Adds to the existing tag list. */
|
|
8
|
+
addTags(tags?: Array<string>): this;
|
|
9
|
+
/** Replaces the tag list. */
|
|
10
|
+
setTags(tags?: Array<string>): this;
|
|
11
|
+
process(record: LogRecord): LogRecord;
|
|
12
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--* PHP: `Monolog\Processor\TagProcessor`.
|
|
3
|
+
local TagProcessor
|
|
4
|
+
do
|
|
5
|
+
TagProcessor = setmetatable({}, {
|
|
6
|
+
__tostring = function()
|
|
7
|
+
return "TagProcessor"
|
|
8
|
+
end,
|
|
9
|
+
})
|
|
10
|
+
TagProcessor.__index = TagProcessor
|
|
11
|
+
function TagProcessor.new(...)
|
|
12
|
+
local self = setmetatable({}, TagProcessor)
|
|
13
|
+
return self:constructor(...) or self
|
|
14
|
+
end
|
|
15
|
+
function TagProcessor:constructor(tags)
|
|
16
|
+
if tags == nil then
|
|
17
|
+
tags = {}
|
|
18
|
+
end
|
|
19
|
+
self.tags = {}
|
|
20
|
+
self:setTags(tags)
|
|
21
|
+
end
|
|
22
|
+
function TagProcessor:addTags(tags)
|
|
23
|
+
if tags == nil then
|
|
24
|
+
tags = {}
|
|
25
|
+
end
|
|
26
|
+
for _, tag in tags do
|
|
27
|
+
local _exp = self.tags
|
|
28
|
+
table.insert(_exp, tag)
|
|
29
|
+
end
|
|
30
|
+
return self
|
|
31
|
+
end
|
|
32
|
+
function TagProcessor:setTags(tags)
|
|
33
|
+
if tags == nil then
|
|
34
|
+
tags = {}
|
|
35
|
+
end
|
|
36
|
+
self.tags = tags
|
|
37
|
+
return self
|
|
38
|
+
end
|
|
39
|
+
function TagProcessor:process(record)
|
|
40
|
+
record.extra.tags = self.tags
|
|
41
|
+
return record
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
return {
|
|
45
|
+
TagProcessor = TagProcessor,
|
|
46
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { LogRecord } from "../LogRecord";
|
|
2
|
+
import type { ProcessorInterface } from "./ProcessorInterface";
|
|
3
|
+
import type { ResettableInterface } from "../ResettableInterface";
|
|
4
|
+
/**
|
|
5
|
+
* PHP: `Monolog\Processor\UidProcessor`.
|
|
6
|
+
*
|
|
7
|
+
* `bin2hex(random_bytes())` has no equivalent here; the uid instead comes from
|
|
8
|
+
* `HttpService:GenerateGUID(false)`, with dashes stripped, lowercased, and cut
|
|
9
|
+
* to `length` characters.
|
|
10
|
+
*/
|
|
11
|
+
export declare class UidProcessor implements ProcessorInterface, ResettableInterface {
|
|
12
|
+
private readonly length;
|
|
13
|
+
private uid;
|
|
14
|
+
constructor(length?: number);
|
|
15
|
+
process(record: LogRecord): LogRecord;
|
|
16
|
+
getUid(): string;
|
|
17
|
+
reset(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local HttpService = game:GetService("HttpService")
|
|
3
|
+
local function generateUid(length)
|
|
4
|
+
local guid = string.gsub(HttpService:GenerateGUID(false), "-", "")
|
|
5
|
+
local _exp = string.lower(guid)
|
|
6
|
+
local _length = length
|
|
7
|
+
return string.sub(_exp, 1, _length)
|
|
8
|
+
end
|
|
9
|
+
--[[
|
|
10
|
+
*
|
|
11
|
+
* PHP: `Monolog\Processor\UidProcessor`.
|
|
12
|
+
*
|
|
13
|
+
* `bin2hex(random_bytes())` has no equivalent here; the uid instead comes from
|
|
14
|
+
* `HttpService:GenerateGUID(false)`, with dashes stripped, lowercased, and cut
|
|
15
|
+
* to `length` characters.
|
|
16
|
+
|
|
17
|
+
]]
|
|
18
|
+
local UidProcessor
|
|
19
|
+
do
|
|
20
|
+
UidProcessor = setmetatable({}, {
|
|
21
|
+
__tostring = function()
|
|
22
|
+
return "UidProcessor"
|
|
23
|
+
end,
|
|
24
|
+
})
|
|
25
|
+
UidProcessor.__index = UidProcessor
|
|
26
|
+
function UidProcessor.new(...)
|
|
27
|
+
local self = setmetatable({}, UidProcessor)
|
|
28
|
+
return self:constructor(...) or self
|
|
29
|
+
end
|
|
30
|
+
function UidProcessor:constructor(length)
|
|
31
|
+
if length == nil then
|
|
32
|
+
length = 7
|
|
33
|
+
end
|
|
34
|
+
self.length = length
|
|
35
|
+
if length > 32 or length < 1 then
|
|
36
|
+
error("The uid length must be an integer between 1 and 32")
|
|
37
|
+
end
|
|
38
|
+
self.uid = generateUid(length)
|
|
39
|
+
end
|
|
40
|
+
function UidProcessor:process(record)
|
|
41
|
+
record.extra.uid = self.uid
|
|
42
|
+
return record
|
|
43
|
+
end
|
|
44
|
+
function UidProcessor:getUid()
|
|
45
|
+
return self.uid
|
|
46
|
+
end
|
|
47
|
+
function UidProcessor:reset()
|
|
48
|
+
self.uid = generateUid(#self.uid)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
return {
|
|
52
|
+
UidProcessor = UidProcessor,
|
|
53
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Logger } from "./Logger";
|
|
2
|
+
/**
|
|
3
|
+
* PHP: `Monolog\Registry`.
|
|
4
|
+
*
|
|
5
|
+
* `__callStatic` (`Registry::api()` reading back as a named accessor) is not
|
|
6
|
+
* ported -- Luau has no magic static-method dispatch. Callers use
|
|
7
|
+
* `Registry.getInstance(name)` explicitly instead.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Registry {
|
|
10
|
+
private static loggers;
|
|
11
|
+
/** PHP: `Registry::addLogger()`. */
|
|
12
|
+
static addLogger(logger: Logger, name?: string, overwrite?: boolean): void;
|
|
13
|
+
/** PHP: `Registry::hasLogger()`. */
|
|
14
|
+
static hasLogger(logger: string | Logger): boolean;
|
|
15
|
+
/** PHP: `Registry::removeLogger()`. */
|
|
16
|
+
static removeLogger(logger: string | Logger): void;
|
|
17
|
+
/** PHP: `Registry::clear()`. */
|
|
18
|
+
static clear(): void;
|
|
19
|
+
/** PHP: `Registry::getInstance()`. */
|
|
20
|
+
static getInstance(name: string): Logger;
|
|
21
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* PHP: `Monolog\Registry`.
|
|
5
|
+
*
|
|
6
|
+
* `__callStatic` (`Registry::api()` reading back as a named accessor) is not
|
|
7
|
+
* ported -- Luau has no magic static-method dispatch. Callers use
|
|
8
|
+
* `Registry.getInstance(name)` explicitly instead.
|
|
9
|
+
|
|
10
|
+
]]
|
|
11
|
+
local Registry
|
|
12
|
+
do
|
|
13
|
+
Registry = setmetatable({}, {
|
|
14
|
+
__tostring = function()
|
|
15
|
+
return "Registry"
|
|
16
|
+
end,
|
|
17
|
+
})
|
|
18
|
+
Registry.__index = Registry
|
|
19
|
+
function Registry.new(...)
|
|
20
|
+
local self = setmetatable({}, Registry)
|
|
21
|
+
return self:constructor(...) or self
|
|
22
|
+
end
|
|
23
|
+
function Registry:constructor()
|
|
24
|
+
end
|
|
25
|
+
function Registry:addLogger(logger, name, overwrite)
|
|
26
|
+
if overwrite == nil then
|
|
27
|
+
overwrite = false
|
|
28
|
+
end
|
|
29
|
+
local _condition = name
|
|
30
|
+
if _condition == nil then
|
|
31
|
+
_condition = logger:getName()
|
|
32
|
+
end
|
|
33
|
+
local key = _condition
|
|
34
|
+
if Registry.loggers[key] ~= nil and not overwrite then
|
|
35
|
+
error("Logger with the given name already exists")
|
|
36
|
+
end
|
|
37
|
+
local _loggers = Registry.loggers
|
|
38
|
+
local _logger = logger
|
|
39
|
+
_loggers[key] = _logger
|
|
40
|
+
end
|
|
41
|
+
function Registry:hasLogger(logger)
|
|
42
|
+
local _logger = logger
|
|
43
|
+
if type(_logger) == "string" then
|
|
44
|
+
local _loggers = Registry.loggers
|
|
45
|
+
local _logger_1 = logger
|
|
46
|
+
return _loggers[_logger_1] ~= nil
|
|
47
|
+
end
|
|
48
|
+
for _, value in Registry.loggers do
|
|
49
|
+
if value == logger then
|
|
50
|
+
return true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
return false
|
|
54
|
+
end
|
|
55
|
+
function Registry:removeLogger(logger)
|
|
56
|
+
local _logger = logger
|
|
57
|
+
if type(_logger) == "string" then
|
|
58
|
+
local _loggers = Registry.loggers
|
|
59
|
+
local _logger_1 = logger
|
|
60
|
+
_loggers[_logger_1] = nil
|
|
61
|
+
return nil
|
|
62
|
+
end
|
|
63
|
+
for key, value in Registry.loggers do
|
|
64
|
+
if value == logger then
|
|
65
|
+
Registry.loggers[key] = nil
|
|
66
|
+
return nil
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
function Registry:clear()
|
|
71
|
+
table.clear(Registry.loggers)
|
|
72
|
+
end
|
|
73
|
+
function Registry:getInstance(name)
|
|
74
|
+
local _loggers = Registry.loggers
|
|
75
|
+
local _name = name
|
|
76
|
+
local logger = _loggers[_name]
|
|
77
|
+
if logger == nil then
|
|
78
|
+
error(`Requested "{name}" logger instance is not in the registry`)
|
|
79
|
+
end
|
|
80
|
+
return logger
|
|
81
|
+
end
|
|
82
|
+
Registry.loggers = {}
|
|
83
|
+
end
|
|
84
|
+
return {
|
|
85
|
+
Registry = Registry,
|
|
86
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** PHP: `Monolog\ResettableInterface`. Handlers/processors reset by `Logger::reset()`. */
|
|
2
|
+
export interface ResettableInterface {
|
|
3
|
+
reset(): void;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* True when the given value implements `ResettableInterface`.
|
|
7
|
+
*
|
|
8
|
+
* PHP checks this with `instanceof`; Luau/TypeScript have no `instanceof` for
|
|
9
|
+
* interfaces, so this checks structurally for a callable `reset` member instead.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isResettable(value: unknown): value is ResettableInterface;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--* PHP: `Monolog\ResettableInterface`. Handlers/processors reset by `Logger::reset()`.
|
|
3
|
+
--[[
|
|
4
|
+
*
|
|
5
|
+
* True when the given value implements `ResettableInterface`.
|
|
6
|
+
*
|
|
7
|
+
* PHP checks this with `instanceof`; Luau/TypeScript have no `instanceof` for
|
|
8
|
+
* interfaces, so this checks structurally for a callable `reset` member instead.
|
|
9
|
+
|
|
10
|
+
]]
|
|
11
|
+
local function isResettable(value)
|
|
12
|
+
local _value = value
|
|
13
|
+
if not (type(_value) == "table") then
|
|
14
|
+
return false
|
|
15
|
+
end
|
|
16
|
+
local _reset = value.reset
|
|
17
|
+
return type(_reset) == "function"
|
|
18
|
+
end
|
|
19
|
+
return {
|
|
20
|
+
isResettable = isResettable,
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Level } from "../Level";
|
|
2
|
+
import { LogRecord } from "../LogRecord";
|
|
3
|
+
import type { FormatterInterface } from "../Formatter/FormatterInterface";
|
|
4
|
+
import type { LogLevel } from "../LoggerInterface";
|
|
5
|
+
import type { RecordBag } from "../LogRecord";
|
|
6
|
+
/**
|
|
7
|
+
* PHP: `Monolog\Test\MonologTestCase`.
|
|
8
|
+
*
|
|
9
|
+
* Lets you easily generate log records and a dummy formatter for testing
|
|
10
|
+
* purposes. Upstream extends PHPUnit's `TestCase`; there is no test-framework
|
|
11
|
+
* ancestor on this platform (`CLAUDE.md`: "Tests: none") to extend instead, so
|
|
12
|
+
* these are plain `public static` methods on a class that extends nothing.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MonologTestCase {
|
|
15
|
+
/** PHP: `MonologTestCase::getRecord()`. */
|
|
16
|
+
static getRecord(level?: Level | LogLevel, message?: string, context?: RecordBag, channel?: string, extra?: RecordBag): LogRecord;
|
|
17
|
+
/** PHP: `MonologTestCase::getMultipleRecords()`. */
|
|
18
|
+
static getMultipleRecords(): Array<LogRecord>;
|
|
19
|
+
/**
|
|
20
|
+
* PHP: `MonologTestCase::getIdentityFormatter()`. Upstream builds this
|
|
21
|
+
* with PHPUnit's `createMock()`; there is no mocking library here to
|
|
22
|
+
* replicate that with, and none is needed for something this trivial --
|
|
23
|
+
* this is a plain object literal implementing `FormatterInterface`.
|
|
24
|
+
*/
|
|
25
|
+
static getIdentityFormatter(): FormatterInterface;
|
|
26
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local Level = TS.import(script, script.Parent.Parent, "Level").Level
|
|
4
|
+
local Logger = TS.import(script, script.Parent.Parent, "Logger").Logger
|
|
5
|
+
local LogRecord = TS.import(script, script.Parent.Parent, "LogRecord").LogRecord
|
|
6
|
+
--[[
|
|
7
|
+
*
|
|
8
|
+
* PHP: `Monolog\Test\MonologTestCase`.
|
|
9
|
+
*
|
|
10
|
+
* Lets you easily generate log records and a dummy formatter for testing
|
|
11
|
+
* purposes. Upstream extends PHPUnit's `TestCase`; there is no test-framework
|
|
12
|
+
* ancestor on this platform (`CLAUDE.md`: "Tests: none") to extend instead, so
|
|
13
|
+
* these are plain `public static` methods on a class that extends nothing.
|
|
14
|
+
|
|
15
|
+
]]
|
|
16
|
+
local MonologTestCase
|
|
17
|
+
do
|
|
18
|
+
MonologTestCase = setmetatable({}, {
|
|
19
|
+
__tostring = function()
|
|
20
|
+
return "MonologTestCase"
|
|
21
|
+
end,
|
|
22
|
+
})
|
|
23
|
+
MonologTestCase.__index = MonologTestCase
|
|
24
|
+
function MonologTestCase.new(...)
|
|
25
|
+
local self = setmetatable({}, MonologTestCase)
|
|
26
|
+
return self:constructor(...) or self
|
|
27
|
+
end
|
|
28
|
+
function MonologTestCase:constructor()
|
|
29
|
+
end
|
|
30
|
+
function MonologTestCase:getRecord(level, message, context, channel, extra)
|
|
31
|
+
if level == nil then
|
|
32
|
+
level = Level.Warning
|
|
33
|
+
end
|
|
34
|
+
if message == nil then
|
|
35
|
+
message = "test"
|
|
36
|
+
end
|
|
37
|
+
if context == nil then
|
|
38
|
+
context = {}
|
|
39
|
+
end
|
|
40
|
+
if channel == nil then
|
|
41
|
+
channel = "test"
|
|
42
|
+
end
|
|
43
|
+
if extra == nil then
|
|
44
|
+
extra = {}
|
|
45
|
+
end
|
|
46
|
+
return LogRecord.new(os.time(), channel, Logger:toMonologLevel(level), message, context, extra)
|
|
47
|
+
end
|
|
48
|
+
function MonologTestCase:getMultipleRecords()
|
|
49
|
+
return { MonologTestCase:getRecord(Level.Debug, "debug message 1"), MonologTestCase:getRecord(Level.Debug, "debug message 2"), MonologTestCase:getRecord(Level.Info, "information"), MonologTestCase:getRecord(Level.Warning, "warning"), MonologTestCase:getRecord(Level.Error, "error") }
|
|
50
|
+
end
|
|
51
|
+
function MonologTestCase:getIdentityFormatter()
|
|
52
|
+
return {
|
|
53
|
+
format = function(self, record)
|
|
54
|
+
return record.message
|
|
55
|
+
end,
|
|
56
|
+
formatBatch = function(self, records)
|
|
57
|
+
-- ▼ ReadonlyArray.map ▼
|
|
58
|
+
local _newValue = table.create(#records)
|
|
59
|
+
local _callback = function(record)
|
|
60
|
+
return record.message
|
|
61
|
+
end
|
|
62
|
+
for _k, _v in records do
|
|
63
|
+
_newValue[_k] = _callback(_v, _k - 1, records)
|
|
64
|
+
end
|
|
65
|
+
-- ▲ ReadonlyArray.map ▲
|
|
66
|
+
return table.concat(_newValue, "\n")
|
|
67
|
+
end,
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
return {
|
|
72
|
+
MonologTestCase = MonologTestCase,
|
|
73
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local MonologTestCase = TS.import(script, script.Parent, "MonologTestCase").MonologTestCase
|
|
4
|
+
--* PHP: `Monolog\Test\TestCase`, a deprecated alias for `MonologTestCase`.
|
|
5
|
+
local TestCase
|
|
6
|
+
do
|
|
7
|
+
local super = MonologTestCase
|
|
8
|
+
TestCase = setmetatable({}, {
|
|
9
|
+
__tostring = function()
|
|
10
|
+
return "TestCase"
|
|
11
|
+
end,
|
|
12
|
+
__index = super,
|
|
13
|
+
})
|
|
14
|
+
TestCase.__index = TestCase
|
|
15
|
+
function TestCase.new(...)
|
|
16
|
+
local self = setmetatable({}, TestCase)
|
|
17
|
+
return self:constructor(...) or self
|
|
18
|
+
end
|
|
19
|
+
function TestCase:constructor(...)
|
|
20
|
+
super.constructor(self, ...)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
return {
|
|
24
|
+
TestCase = TestCase,
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LogRecord } from "./LogRecord";
|
|
2
|
+
/**
|
|
3
|
+
* Marks a table so `jsonEncode` renders it as a JSON object (`{}`) rather than
|
|
4
|
+
* an array (`[]`) when it is empty. Luau tables can't tell an empty array from
|
|
5
|
+
* an empty object apart the way PHP's `\stdClass` vs `[]` can -- see
|
|
6
|
+
* `JsonFormatter.ts`, which is the one caller that needs this.
|
|
7
|
+
*/
|
|
8
|
+
export declare function markAsJsonObject<T extends object>(value: T): T;
|
|
9
|
+
export declare class Utils {
|
|
10
|
+
/**
|
|
11
|
+
* PHP: `Utils::jsonEncode()`/`Utils::handleJsonError()`. There is no
|
|
12
|
+
* `json_encode` on this platform, so this is a small deterministic encoder
|
|
13
|
+
* instead: Luau tables carry no key order, so object keys are sorted before
|
|
14
|
+
* being written, and there is nothing that can fail the way `json_encode`
|
|
15
|
+
* can (invalid UTF-8, unsupported resource types) -- so there is nothing to
|
|
16
|
+
* recover from and no `handleJsonError` equivalent.
|
|
17
|
+
*/
|
|
18
|
+
static jsonEncode(data: unknown, pretty?: boolean): string;
|
|
19
|
+
/** PHP: `Utils::getRecordMessageForException()`. */
|
|
20
|
+
static getRecordMessageForException(record: LogRecord): string;
|
|
21
|
+
}
|