-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
126 lines (109 loc) · 3.87 KB
/
main.lua
File metadata and controls
126 lines (109 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--
-- Abstract: logger Library Plugin Test Project
--
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license
-- Copyright (C) 2016 Yoger Games AB. All Rights Reserved.
--
------------------------------------------------------------
local widget = require "widget"
-- Require the plugin
local logger = require("plugin.logger")
-- Create the options table
local options = {}
-- Set a different table depending on the environment / device
if system.getInfo( "environment" ) == "simulator" then
options.highlight_errors = true
options.highlight_warnings = true
options.log_levels = {
global = logger.LEVELS.DEBUG,
main = logger.LEVELS.DUMP
}
elseif system.getInfo("deviceID") == "xxx" then
options.highlight_errors = true
options.highlight_warnings = false
options.log_levels = {
global = logger.LEVELS.LOG,
crosspromo = logger.LEVELS.DUMP
}
else
options.highlight_errors = true
options.highlight_warnings = false
options.log_levels = {
global = logger.LEVELS.ERROR
}
end
-- Initialize logger with the options table
logger.init(options)
-- Additional log levels can be set after init
----------------------------------------------
-- logger.setLogLevel(logger.LEVELS.DUMP, "main")
-- logger.setGlobalLogLevel(logger.LEVELS.DEBUG, false)
display.setDefault( "background", 1, 1, 1 )
local xPos, yPos = display.contentCenterX, display.contentCenterY
local widthBtn, heightBtn = display.contentWidth * 0.8, 50
local btnFontSize = 12
local numButtons = 7
local currentBtn = 0
local function createButton(textLabel, callback)
currentBtn = currentBtn + 1
return widget.newButton{
x = xPos, y = currentBtn * display.contentHeight / (numButtons + 1),
width = widthBtn, height = heightBtn,
label = textLabel,
labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0 } },
fontSize = btnFontSize,
onRelease = callback,
-- Properties for a rounded rectangle button
shape = "roundedRect",
cornerRadius = 2,
fillColor = { default={1/255,87/255,155/255,1}, over={128/255,216/255,255/255,0.4} },
strokeColor = { default={0/255,145/255,234/255,1}, over={0/255,176/255,255/255,1} },
strokeWidth = 4
}
end
-- Set log level for channel "main" to LOG
----------------------------------------------
local btn1 = createButton("setLogLevel ( LOG, 'main' )", function()
logger.setLogLevel(logger.LEVELS.LOG, "main")
logger.printLogLevels()
end
)
-- Set log level for channel "main" to DEBUG
----------------------------------------------
createButton("setLogLevel ( DEBUG, 'main' )", function()
logger.setLogLevel(logger.LEVELS.DEBUG, "main")
logger.printLogLevels()
end
)
-- Set log level for channel "main" to DUMP
----------------------------------------------
createButton("setLogLevel ( DUMP, 'main' )", function()
logger.setLogLevel(logger.LEVELS.DUMP, "main")
logger.printLogLevels()
end
)
-- Log a highlighted error
----------------------------------------------
createButton("logger.error ('main', 'an error occurred')", function()
logger.error("main", "an error occurred")
end
)
-- Log a highlighted warning
----------------------------------------------
createButton("logger.warning ('main', 'a warning message')", function()
logger.warning("main", "a warning message")
end
)
-- Log a dump message
----------------------------------------------
createButton("logger.dump ('main', 'a dump message')", function()
logger.dump("main", "a dump message")
end
)
-- Log complex AND multiple parameters
----------------------------------------------
local myComplexTable = { param = "key", param2 = { nestedKey = "nestedValue"}}
createButton("logger.log ( 'main', myComplexTable, ...)", function()
logger.log("main", myComplexTable, 1, true, "stringValue")
end
)