Skip to content

Commit

Permalink
Fixed Log on JS
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Sep 23, 2023
1 parent 0390843 commit cfa2040
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/dn/Log.hx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,15 @@ class Log {
var lines = raw.split("\n");
if( lines.length>maxLines ) {
lines = lines.splice(lines.length-maxLines, maxLines);
sys.io.File.saveContent( filePath, lines.join("\n") );
var output = lines.join("\n");
#if sys
sys.io.File.saveContent( filePath, output );
#elseif hxnodejs
js.node.Require.require("fs");
js.node.Fs.writeFileSync(filePath, output);
#else
// You're not supposed to be here
#end
}
return true;
}
Expand Down Expand Up @@ -330,4 +338,14 @@ class Log {


public dynamic function onAdd(e:LogEntry) {}


@:noCompletion
public static function __test() {
var l = new Log(5);
l.logFilePath = "tests/bin/test.log";
l.add("someTag", "text", 0xff00ff);
l.flushToFile();
l.trimFileLines();
}
}
1 change: 1 addition & 0 deletions tests/Tests.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Tests {
dn.struct.Stat.StatTest.__test();
dn.phys.Velocity.__test();
dn.Version.__test();
dn.Log.__test();



Expand Down

0 comments on commit cfa2040

Please sign in to comment.