Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
lifewcody

Array value dissapearing

Question

This is my array:

local logEvents = {
	[ "EMERGENCY" ] = colors.red,
	[ "ALERT" ] = colors.red,
	[ "CRITICAL" ] = colors.orange,
	[ "ERROR" ] = colors.orange,
	[ "WARNING" ] = colors.yellow,
	[ "NOTICE" ] = colors.yellow,
	[ "DEBUG" ] = colors.blue,
    [ "INFORMATIONAL" ] = colors.lightBlue,
}

And then I check to see if the value is there (ex. emergency, alert, etc)

if logEvents[sev] ~= nil then

Here is the full code for my library:

local log = {}
local logFile = {}

local cache = require("IPv2/cache")
local os = require("os")
local component = require("component")
local colors = require("colors")
local term = require("term")

local gpu = component.gpu

-- LOCAL VARIABLES
local logLevel = 0

local logEvents = {
	[ "EMERGENCY" ] = colors.red,
	[ "ALERT" ] = colors.red,
	[ "CRITICAL" ] = colors.orange,
	[ "ERROR" ] = colors.orange,
	[ "WARNING" ] = colors.yellow,
	[ "NOTICE" ] = colors.yellow,
	[ "DEBUG" ] = colors.blue,
    [ "INFORMATIONAL" ] = colors.lightBlue,
}

local logLevels = {
	[0] = {
		"EMERG",
		"ALERT",
		"CRIT",
		"ERR",
		"WARN",
		"NOTICE",
		"INFO",
		"DEBUG",
	},
	[1] = {
		"EMERG",
		"ALERT",
		"CRIT",
		"ERR",
		"WARN",
		"NOTICE",
		"INFO",
	},
	[2] = {
		"EMERG",
		"ALERT",
		"CRIT",
		"ERR",
		"WARN",
		"NOTICE",
	},
	[3] = {
		"EMERG",
		"ALERT",
		"CRIT",
		"ERR",
		"WARN",
	},
	[4] = {
		"EMERG",
		"ALERT",
		"CRIT",
		"ERR",
	},
	[5] = {
		"EMERG",
		"ALERT",
		"CRIT",
	},
	[6] = {
		"EMERG",
		"ALERT",
	},
	[7] = {
		"EMERG",
	},
	[8] = {},

}

function log.log(...)
    local arguments = {...}

    if #arguments >= 2 then
        local sev = string.upper(arguments[1])
        local lString = "[" .. sev .. "] "
        for k, v in pairs(arguments) do
            lString = lString .. "[" .. v .. "] "
        end
        table.insert(logFile, os.clock() .. " >> " .. lString)
        for k, v in pairs(logEvents) do
            print(k .. " > " .. v)
        end
        print("SEV: " .. sev)
        print(tostring(logEvents[sev]))
        if logEvents[sev] ~= nil then
            local isInLogLevels = false
            for i=1, #logLevels[logLevel] do
                print(logLevels[logLevel][i] .. " <<>> " .. sev .. " <<>> " .. string.upper(arguments[1]))
                if logLevels[logLevel][i] == string.upper(arguments[1]) then
                    isInLogLevels = true
                end
            end
            if isInLogLevels then
                print("HERE!")
                gpu.setForeground(0x00FF00)
                gpu.set(1, 1, 'Hello, world!')
                print(gpu.setForeground(0x2E86C1) .. arguments[2])
            end
        end
    else
        return false
    end
end

function log.save()
    cache.set("log", logFile)
end

function log.get()
    return logFile
end

function log.init()
    logFile = cache.get("log")
end

return log

When I run it, I have a line where it prints every severity to see what it sees. And it shows every severity EXCEPT Informational. I even changed it from INFO to INFORMATIONAL. I have no clue why it keeps removing that value. Any other value works fine.

Thanks,

lifewcody

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.