This repository was archived by the owner on Jun 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogs.hx
More file actions
100 lines (88 loc) · 2.5 KB
/
Copy pathLogs.hx
File metadata and controls
100 lines (88 loc) · 2.5 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
package codename.backend.system;
import haxe.Log;
import haxe.PosInfos;
import lime.app.Application;
using codename.backend.system.Logs.LogTools;
class AlertParams
{
public var content:String = 'None';
public var title:Null<String> = null;
public function new(content:String = 'None', ?title:Null<String>)
{
this.content = content;
this.title = title;
}
}
class LogTools
{
@:deprecated('The level.toLevel() function will soon be removed from backend.LogTools.') public static inline function toLevel(level:Level):String
{
return levelToString(level);
}
public static inline function levelToString(level:Level):String
{
switch (level)
{
case INFO | NONE:
return '[ INFO ]';
case WARNING:
return '[ WARNING ]';
case ERROR:
return '[ ERROR ]';
default:
return '[ MISC ]';
}
}
public static inline function spawnAlertWindow(params:AlertParams, ?infos:haxe.PosInfos)
{
Logs.traceNew(params.content, ERROR, infos);
Application.current.window.alert(params.content, params.title);
}
}
class Logs
{
public static var nativeTrace = Log.trace;
public static function init()
{
Log.trace = traceOverride;
}
static function levelToInt(l:Level):Int
{
switch(l)
{
case INFO:
return 0;
case MISC:
return 1;
case NONE:
return 2;
case WARNING:
return 3;
case ERROR:
return 4;
}
}
static function traceOverride(v:Dynamic, ?infos:PosInfos):Void traceNew(v, NONE, infos);
public static function traceNew(v:Dynamic, level:Level, ?infos:PosInfos):Void
{
var str = '${level.toLevel()} : ' + Log.formatOutput(v, infos).replace('\n\n', '\n').replace('\n', '\n${level.toLevel()} : ${infos.fileName}:${infos.lineNumber}: ');
#if js
if (js.Syntax.typeof(untyped console) != "undefined" && (untyped console).log != null)
(untyped console).log(str);
#elseif lua
untyped __define_feature__("use._hx_print", _hx_print(str));
#elseif sys
Sys.println(str);
#else
throw new haxe.exceptions.NotImplementedException()
#end
}
}
enum abstract Level(Int)
{
var INFO = 0;
var MISC = 1;
var NONE = 2;
var WARNING = 3;
var ERROR = 4;
}