Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve log positions #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 12 additions & 10 deletions com/smartfoxserver/v2/logging/Logger.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.smartfoxserver.v2.logging;

import flash.events.EventDispatcher;
import haxe.PosInfos;

//--------------------------------------
// Events
Expand Down Expand Up @@ -140,33 +141,33 @@ class Logger extends EventDispatcher
}

/** @private */
public function debug(msg:String):Void
public function debug(msg:String, ?pos:PosInfos):Void
{
log(LogLevel.DEBUG, msg);
log(LogLevel.DEBUG, msg, pos);
}

/** @private */
public function info(msg:String):Void
public function info(msg:String, ?pos:PosInfos):Void
{
log(LogLevel.INFO, msg);
log(LogLevel.INFO, msg, pos);
}

/** @private */
public function warn(msg:String):Void
public function warn(msg:String, ?pos:PosInfos):Void
{
log(LogLevel.WARN, msg);
log(LogLevel.WARN, msg, pos);
}

/** @private */
public function error(msg:String):Void
public function error(msg:String, ?pos:PosInfos):Void
{
log(LogLevel.ERROR, msg);
log(LogLevel.ERROR, msg, pos);
}

/**
* Traces a log message in the console and dispatches the related event.
*/
private function log(level:Int, message:String):Void
private function log(level:Int, message:String, pos:PosInfos):Void
{
if(level<_loggingLevel)
return;
Expand All @@ -175,13 +176,14 @@ class Logger extends EventDispatcher

// Trace message in console
if(_enableConsoleTrace)
trace("[" + _loggingPrefix + "|" + levelStr + "]", message);
haxe.Log.trace("[" + _loggingPrefix + "|" + levelStr + "] " + message, pos);

if(_enableEventDispatching)
{
// Dispatch event
var params:Dynamic = { };
params.message = message;
params.pos = pos;

var evt:LoggerEvent = new LoggerEvent(levelStr.toLowerCase(), params);
dispatchEvent(evt);
Expand Down