Skip to main content

MemoryHandler

An implementation of Handler which stores Records in a buffer. When the buffer fills, it passes the stored Records to another target Handler, then the buffer is cleared.

Properties

buffer

since 0.1.0
</>
MemoryHandler.buffer: table

An array-like table which stores Records.

capacity

since 0.1.0
</>
MemoryHandler.capacity: number

The number of Record that can be stored in the buffer before MemoryHandler:flush is called.

flushLevel

since 0.1.0
</>
MemoryHandler.flushLevel: Level

If a Record with a level greater than or equal to this level is handled, then MemoryHandler:flush is called immediately.

target

since 0.1.0
</>
MemoryHandler.target: Handler

Another handler to handle stored Record when MemoryHandler:flush is called.

flushOnClose

since 0.1.0
</>
MemoryHandler.flushOnClose: boolean

Determines whether MemoryHandler:flush is called when MemoryHandler:close is called.

Functions

new

since 0.1.0
</>
MemoryHandler.new(
capacity: number,
flushLevel: Level,
target: Handler,
flushOnClose: boolean
) → MemoryHandler

Creates a new MemoryHandler of a given capacity.

emit

since 0.1.0
</>
MemoryHandler:emit(record: Record) → ()

Adds the given record to the buffer. Then, if MemoryHandler:shouldFlush returns true, MemoryHandler:flush is called.

getLastRecord

since 0.1.0
</>
MemoryHandler:getLastRecord() → Record

Returns the last record emit to the MemoryHandler.

size

since 0.1.0
</>
MemoryHandler:size() → number

Returns the number of records that the MemoryHandler has stored in the buffer.

space

since 0.1.0
</>
MemoryHandler:space() → number

Returns the number of records that the MemoryHandler can store in its buffer before filling.

isFull

since 0.1.0
</>
MemoryHandler:isFull() → boolean

Returns whether the MemoryHandler's buffer has run out of space.

flush

since 0.1.0
</>
MemoryHandler:flush() → ()

If a MemoryHandler.target is set, this passes all of the Records stored in the buffer to Handler:handle. Then, the buffer is empted (MemoryHandler:emptyBuffer).

emptyBuffer

since 0.1.0
</>
MemoryHandler:emptyBuffer() → ()

Clears the buffer of all Records.

setTarget

since 0.1.0
</>
MemoryHandler:setTarget(target: Handler) → ()

Sets the target Handler for when the MemoryHandler is flushed.

shouldFlush

since 0.1.0
</>
MemoryHandler:shouldFlush(record: Record) → boolean

Determines whether the MemoryHandler should flush its contents based on the given record and the state of the buffer. If the given record is at or above the MemoryHandler.flushLevel, or if the buffer is full (MemoryHandler:isFull), this method returns true. This method can be overwritten to provide a different flush strategy.

close

since 0.1.0
</>
MemoryHandler:close() → ()

If MemoryHandler.flushOnClose is true, then MemoryHandler:flush is called.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new MemoryHandler of a given capacity.",
            "params": [
                {
                    "name": "capacity",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "flushLevel",
                    "desc": "",
                    "lua_type": "Level"
                },
                {
                    "name": "target",
                    "desc": "",
                    "lua_type": "Handler"
                },
                {
                    "name": "flushOnClose",
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "MemoryHandler"
                }
            ],
            "function_type": "static",
            "since": "0.1.0",
            "source": {
                "line": 76,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "emit",
            "desc": "Adds the given record to the buffer. Then, if [MemoryHandler:shouldFlush]\nreturns true, [MemoryHandler:flush] is called.",
            "params": [
                {
                    "name": "record",
                    "desc": "",
                    "lua_type": "Record"
                }
            ],
            "returns": [],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 98,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "getLastRecord",
            "desc": "Returns the last record emit to the MemoryHandler.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Record"
                }
            ],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 112,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "size",
            "desc": "Returns the number of records that the MemoryHandler has stored in the buffer.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 121,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "space",
            "desc": "Returns the number of records that the MemoryHandler can store in its buffer before filling.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 130,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "isFull",
            "desc": "Returns whether the MemoryHandler's buffer has run out of space.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 139,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "flush",
            "desc": "If a [MemoryHandler.target] is set, this passes all of the [Record]s stored in the buffer\nto [Handler:handle]. Then, the buffer is empted ([MemoryHandler:emptyBuffer]).",
            "params": [],
            "returns": [],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 148,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "emptyBuffer",
            "desc": "Clears the buffer of all [Record]s.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 161,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "setTarget",
            "desc": "Sets the target [Handler] for when the MemoryHandler is flushed.",
            "params": [
                {
                    "name": "target",
                    "desc": "",
                    "lua_type": "Handler"
                }
            ],
            "returns": [],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 171,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "shouldFlush",
            "desc": "Determines whether the MemoryHandler should flush its contents based on the given record\nand the state of the buffer. If the given record is at or above the [MemoryHandler.flushLevel],\nor if the buffer is full ([MemoryHandler:isFull]), this method returns true.\nThis method can be overwritten to provide a different flush strategy.",
            "params": [
                {
                    "name": "record",
                    "desc": "",
                    "lua_type": "Record"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 184,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "close",
            "desc": "If [MemoryHandler.flushOnClose] is true, then [MemoryHandler:flush] is called.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "since": "0.1.0",
            "source": {
                "line": 192,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "buffer",
            "desc": "An array-like table which stores [Record]s.",
            "lua_type": "table",
            "since": "0.1.0",
            "source": {
                "line": 21,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "i",
            "desc": "The index where the next [Record] is to be stored in the [MemoryHandler.buffer]",
            "lua_type": "number",
            "since": "0.1.0",
            "private": true,
            "source": {
                "line": 29,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "capacity",
            "desc": "The number of [Record] that can be stored in the buffer before [MemoryHandler:flush] is called.",
            "lua_type": "number",
            "since": "0.1.0",
            "source": {
                "line": 36,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "flushLevel",
            "desc": "If a [Record] with a level greater than or equal to this level is handled, then [MemoryHandler:flush]\nis called immediately.",
            "lua_type": "Level",
            "since": "0.1.0",
            "source": {
                "line": 44,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "target",
            "desc": "Another handler to handle stored [Record] when [MemoryHandler:flush] is called.",
            "lua_type": "Handler",
            "since": "0.1.0",
            "source": {
                "line": 51,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "flushOnClose",
            "desc": "Determines whether [MemoryHandler:flush] is called when [MemoryHandler:close] is called.",
            "lua_type": "boolean",
            "since": "0.1.0",
            "source": {
                "line": 58,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        },
        {
            "name": "lastRecord",
            "desc": "The most recently handled record.",
            "lua_type": "Record",
            "since": "0.1.0",
            "private": true,
            "source": {
                "line": 66,
                "path": "Logging/Handler/MemoryHandler.lua"
            }
        }
    ],
    "types": [],
    "name": "MemoryHandler",
    "desc": "An implementation of [Handler] which stores [Record]s in a buffer. When\nthe buffer fills, it passes the stored [Record]s to another target\n[Handler], then the buffer is cleared.",
    "source": {
        "line": 8,
        "path": "Logging/Handler/MemoryHandler.lua"
    }
}