Permalink
Browse files

reorg: Inheritace instead of callbacks for makeObjectGroupt + makeSta…

…ckTraceGroup
  • Loading branch information...
MikeMitterer committed Dec 11, 2017
1 parent 5edb9cd commit 5c78652dab7185956970b89d85a7cd1c74b3b901
Showing with 27 additions and 24 deletions.
  1. +7 −13 lib/console_log_handler.dart
  2. +5 −11 lib/print_log_handler.dart
  3. +15 −0 lib/shared/log_handler.dart
@@ -50,8 +50,6 @@ class LogConsoleHandler extends LogHandler {

final TransformLogRecord _transformer;

final MakeConsoleGroup _makeGroup = _defaultGroupMaker;

LogConsoleHandler( { final TransformLogRecord transformer: defaultTransformer } )
: _transformer = transformer;

@@ -73,12 +71,11 @@ class LogConsoleHandler extends LogHandler {
window.console.error(transformer(logRecord));
}

_makeGroup(logRecord);
makeGroup(logRecord);
}

// -- private -------------------------------------------------------------

static void _makeObjectGroup(final String groupName, final LogRecord logRecord) {
@override
void makeObjectGroup(final String groupName, final LogRecord logRecord) {

void makeGroupWithString(final String groupName,final String objectAsString) {
window.console.groupCollapsed(groupName);
@@ -110,21 +107,18 @@ class LogConsoleHandler extends LogHandler {
}
}

static void _makeStackTraceGroup(final String groupName, final LogRecord logRecord) {

@override
void makeStackTraceGroup(final String groupName, final LogRecord logRecord) {
if (logRecord.stackTrace != null) {
window.console.group(groupName);
window.console.log(logRecord.stackTrace.toString());
window.console.groupEnd();
}
}

// -- private -------------------------------------------------------------

/// Called after console output is done (via makeGroup - can be overwritten)
static void _defaultGroupMaker(final LogRecord logRecord) {

_makeStackTraceGroup(" ○ StackTrace",logRecord);
_makeObjectGroup(" ○ Dart-Object",logRecord);
}
}


@@ -52,8 +52,6 @@ class LogPrintHandler extends LogHandler {
/// Converts [LogRecord] to String
final TransformLogRecord _transformer;

final MakeConsoleGroup _makeGroup = _defaultGroupMaker;

final AnsiPen _penInfo = new AnsiPen()..blue();
final AnsiPen _penWarning = new AnsiPen()..yellow();
final AnsiPen _penError = new AnsiPen()..red();
@@ -82,10 +80,11 @@ class LogPrintHandler extends LogHandler {
print(_penError(transformer(logRecord)));
}

_makeGroup(logRecord);
makeGroup(logRecord);
}

static void _makeObjectGroup(final String groupName, final LogRecord logRecord) {
@override
void makeObjectGroup(final String groupName, final LogRecord logRecord) {

void makeGroupWithString(final String groupName,final String objectAsString) {
print(groupName);
@@ -116,7 +115,8 @@ class LogPrintHandler extends LogHandler {
}
}

static void _makeStackTraceGroup(final String groupName, final LogRecord logRecord) {
@override
void makeStackTraceGroup(final String groupName, final LogRecord logRecord) {
if (logRecord.stackTrace != null) {
print(groupName);
print(logRecord.stackTrace.toString());
@@ -127,12 +127,6 @@ class LogPrintHandler extends LogHandler {

// -- private -------------------------------------------------------------

/// Called after console output is done (via makeGroup - can be overwritten)
static void _defaultGroupMaker(final LogRecord logRecord) {

_makeStackTraceGroup(" ○ StackTrace",logRecord);
_makeObjectGroup(" ○ Dart-Object",logRecord);
}
}


@@ -61,8 +61,23 @@ String defaultTransformer(final LogRecord logRecord,{ final int nameWidth = 20 }
}

abstract class LogHandler {
static const String GROUP_STACK_TRACE = ' ○ StackTrace';
static const String GROUP_OBJECT = ' ○ Dart-Object';

void toConsole(final LogRecord logRecord,{ TransformLogRecord transformer });
void call(final LogRecord logRecord) => toConsole(logRecord);

/// [groupName] is for example [GROUP_STACK_TRACE]
void makeStackTraceGroup(final String groupName, final LogRecord logRecord);

/// [groupName] is for example [GROUP_OBJECT]
void makeObjectGroup(final String groupName, final LogRecord logRecord);

/// Called after console output is done (via makeGroup - can be overwritten)
void makeGroup(final LogRecord logRecord) {
makeStackTraceGroup(GROUP_STACK_TRACE,logRecord);
makeObjectGroup(GROUP_OBJECT,logRecord);
}
}

String prettyPrintJson(final json) {

0 comments on commit 5c78652

Please sign in to comment.