Skip to content

Commit

Permalink
Colored log.
Browse files Browse the repository at this point in the history
  • Loading branch information
MagerValp committed Dec 7, 2016
1 parent 10f250b commit eb7a020
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions AutoDMG/IEDLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
IEDLogLevelNotice = 5
IEDLogLevelInfo = 6
IEDLogLevelDebug = 7
IEDColorForLevel = [
NSColor.redColor(),
NSColor.redColor(),
NSColor.redColor(),
NSColor.redColor(),
NSColor.orangeColor(),
NSColor.blackColor(),
NSColor.blackColor(),
NSColor.grayColor(),
]

# Control which output channels are active.
IEDLogToController = True
Expand Down Expand Up @@ -226,13 +236,18 @@ def saveLog_(self, sender):
def numberOfRowsInTableView_(self, tableView):
return len(self.visibleLogLines)

def attrString_forRow_(self, s, row):
color = IEDColorForLevel[self.visibleLogLines[row].level()]
attr = {NSForegroundColorAttributeName: color}
return NSAttributedString.alloc().initWithString_attributes_(s, attr)

def tableView_objectValueForTableColumn_row_(self, tableView, column, row):
if column.identifier() == u"date":
return self.visibleLogLines[row].date()
elif column.identifier() == u"level":
return IEDLogLevelName(self.visibleLogLines[row].level())
return self.attrString_forRow_(IEDLogLevelName(self.visibleLogLines[row].level()), row)
elif column.identifier() == u"message":
return self.visibleLogLines[row].message()
return self.attrString_forRow_(self.visibleLogLines[row].message(), row)
else:
LogDebug(u"Unexpected column identifier '%@'", column.identifier())

Expand Down

0 comments on commit eb7a020

Please sign in to comment.