Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/ufront/tasks/UFTaskSet.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ufront.tasks;

#if sys
import mcli.CommandLine;
import mcli.Dispatch;
import minject.Injector;
Expand All @@ -12,6 +11,7 @@ import ufront.log.MessageList;
import ufront.api.UFApi;
import haxe.PosInfos;
using haxe.io.Path;
using StringTools;

class UFTaskSet extends CommandLine {

Expand Down Expand Up @@ -47,23 +47,36 @@ class UFTaskSet extends CommandLine {
**/
@:skip
public function useCLILogging( ?logFile:String ):UFTaskSet {
var logFilePath = null;
var file:FileOutput = null;
if ( logFile!=null ) {
var contentDir:String = injector.getInstance( String, "contentDirectory" );
var logFilePath = contentDir.addTrailingSlash()+logFile;
logFilePath = contentDir.addTrailingSlash()+logFile;
var logFileDirectory = logFilePath.directory();
if ( FileSystem.exists(logFileDirectory)==false )
FileSystem.createDirectory( logFileDirectory );
file = File.append( logFilePath );

var line = '${Date.now()} [UFTask Runner] ${Sys.args()}';
file.writeString( '$line\n' );

#if nodejs
// hxnodejs has no FileInput implemention (yet)
js.node.Fs.appendFileSync( logFilePath, '$line\n' );
#else
file = File.append( logFilePath );
file.writeString( '$line\n' );
#end

}
function onMessage( msg:Message ) {
var line = FileLogger.format( msg );

Sys.println( line );
if ( file!=null ) {
file.writeString( '\t$line\n' );
}
#if nodejs
// hxnodejs has no FileInput implemention (yet)
if ( logFilePath!=null ) js.node.Fs.appendFileSync( logFilePath, '\t$line\n' );
#else
if ( file!=null ) file.writeString( '\t$line\n' );
#end
}
haxe.Log.trace = function(msg:Dynamic,?pos:PosInfos) onMessage({ msg: msg, pos: pos, type:MTrace });
injector.map( MessageList ).toValue( new MessageList(onMessage) );
Expand Down Expand Up @@ -141,4 +154,3 @@ class UFTaskSet extends CommandLine {
**/
@:noCompletion inline function ufError( msg:Dynamic, ?pos:PosInfos ) messages.push({ msg: msg, pos: pos, type:MError });
}
#end