Skip to content

Commit

Permalink
Add logger class (#12)
Browse files Browse the repository at this point in the history
* Fix to loggingconsole to ensure it actually strips out the html header during replays
* Add the loginator.lua file and add it to the README
* Fix to self updating gauges so they no longer accidentally set the second and successive gauges created to inactive
* update for 2.2.0 release
  • Loading branch information
demonnic committed May 5, 2021
1 parent 471ca3c commit 715e904
Show file tree
Hide file tree
Showing 6 changed files with 476 additions and 22 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ You should maybe also include demontools.lua, as it notes below several other of
* loggingconsole.lua
* Self logging extension to the mini console. Works just like a Geyser.MiniConsole but adds a templated path and fileName constraint, as well as logFormat so it can log what is echod or appended to it. Requires demontools.lua in order to work.

* loginator.lua
* Creates objects for logging messages to disk. <https://github.com/demonnic/MDK/wiki/Loginator>

* mastermindsolver.lua
* A class which will help you solve Master Mind puzzles. <https://github.com/demonnic/MDK/wiki/MasterMindSolver>

Expand Down
12 changes: 9 additions & 3 deletions src/resources/demontools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- @copyright 2020 Damian Monogue
-- @license MIT, see LICENSE.lua
local DemonTools = {}
local cheatConsole = Geyser.MiniConsole:new({name = "DemonnicCheatConsole", width = 4000, wrapWidth = 10000})
local cheatConsole = Geyser.MiniConsole:new({name = "DemonnicCheatConsole", width = 4000, wrapWidth = 10000, color = "black"})
cheatConsole:hide()
local function exists(path)
local ok, err, code = os.rename(path, path)
Expand All @@ -19,6 +19,7 @@ local function isWindows()
end

local function isDir(path)
path = path:gsub("\\", "/")
if not path:ends("/") then
path = path .. "/"
end
Expand Down Expand Up @@ -64,7 +65,8 @@ local htmlHeader = [=[ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitiona
}
</style>
</head>
<body><span>]=]
<body><span>
]=]

local htmlHeaderPattern = [=[ <!DOCTYPE HTML PUBLIC "%-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
Expand All @@ -81,7 +83,8 @@ local htmlHeaderPattern = [=[ <!DOCTYPE HTML PUBLIC "%-//W3C//DTD HTML 4.01 Tra
}
</style>
</head>
<body><span>]=]
<body><span>
]=]

-- internal function, recursively digs for a value within subtables if possible
local function digForValue(dataFrom, tableTo)
Expand Down Expand Up @@ -1292,4 +1295,7 @@ function DemonTools.mkdir_p(path)
return mkdir_p(path)
end

DemonTools.htmlHeader = htmlHeader
DemonTools.htmlHeaderPattern = htmlHeaderPattern

return DemonTools
23 changes: 6 additions & 17 deletions src/resources/loggingconsole.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,7 @@
local homedir = getMudletHomeDir():gsub("\\", "/")
local pathOfThisFile = (...):match("(.-)[^%.]+$")
local dt = require(pathOfThisFile .. "demontools")
local exists, isDir = dt.exists, dt.isDir
local htmlHeader = [=[ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
<style type="text/css">
body {
background-color: black;
font-family: 'Droid Sans Mono';
white-space: pre-wrap;
font-size: 12px;
}
</style>
</head>
<body><span>]=]
local exists, htmlHeader, htmlHeaderPattern = dt.exists, dt.htmlHeader, dt.htmlHeaderPattern

local LoggingConsole = {log = true, logFormat = "h", path = "|h/log/consoleLogs/|y/|m/|d/", fileName = "|n.|e"}

Expand Down Expand Up @@ -442,6 +426,11 @@ function LoggingConsole:replay(numberOfLines)
local file = io.open(fileName, "r")
local lines = file:read("*a")
if self:getExtension() == "html" then
for _, line in ipairs(htmlHeaderPattern:split("\n")) do
if line ~= "" then
lines = lines:gsub(line .. "\n", "")
end
end
lines = dt.html2decho(lines)
else
lines = ansi2decho(lines)
Expand Down
Loading

0 comments on commit 715e904

Please sign in to comment.