Skip to content

Commit

Permalink
Merge pull request Hexxeh#10 from pebble/feature-app-logging
Browse files Browse the repository at this point in the history
Add app-logging endpoint
  • Loading branch information
nick-ford committed Jun 14, 2013
2 parents ff85f17 + 78d2ea1 commit ad5e065
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions pebble/pebble.py
Expand Up @@ -27,6 +27,7 @@
DEFAULT_PEBBLE_ID = None #Triggers autodetection on unix-like systems
DEBUG_PROTOCOL = False


class PebbleBundle(object):
MANIFEST_FILENAME = 'manifest.json'

Expand Down Expand Up @@ -180,12 +181,23 @@ class Pebble(object):
"LOG_DUMP": 2002,
"RESET": 2003,
"APP": 2004,
"APP_LOGS": 2006,
"NOTIFICATION": 3000,
"RESOURCE": 4000,
"APP_MANAGER": 6000,
"PUTBYTES": 48879
}

log_levels = {
0: "*",
1: "E",
50: "W",
100: "I",
200: "D",
250: "V"
}


@staticmethod
def AutodetectDevice():
if os.name != "posix": #i.e. Windows
Expand Down Expand Up @@ -221,6 +233,7 @@ def __init__(self, id = None, using_lightblue = True, pair_first = False):
self.endpoints["LAUNCHER"]: self._application_message_response,
self.endpoints["LOGS"]: self._log_response,
self.endpoints["PING"]: self._ping_response,
self.endpoints["APP_LOGS"]: self._app_log_response,
self.endpoints["APP_MANAGER"]: self._appbank_status_response
}

Expand Down Expand Up @@ -710,24 +723,29 @@ def _system_message_response(self, endpoint, data):
def _log_response(self, endpoint, data):
if (len(data) < 8):
log.warn("Unable to decode log message (length %d is less than 8)" % len(data))
return;
return

timestamp, level, msgsize, linenumber = unpack("!Ibbh", data[:8])
timestamp, level, msgsize, linenumber = unpack("!IBBH", data[:8])
filename = data[8:24].decode('utf-8')
message = data[24:24+msgsize].decode('utf-8')

log_levels = {
0: "*",
1: "E",
50: "W",
100: "I",
200: "D",
250: "V"
}
str_level = log_levels[level] if level in log_levels else "?"

print timestamp, str_level, filename, linenumber, message

def _app_log_response(self, endpoint, data):
if (len(data) < 8):
log.warn("Unable to decode log message (length %d is less than 8)" % len(data))
return

app_uuid = uuid.UUID(bytes=data[0:16])
timestamp, level, msgsize, linenumber = unpack("!IBBH", data[16:24])
filename = data[24:40].decode('utf-8')
message = data[40:40+msgsize].decode('utf-8')

level = log_levels[level] if level in log_levels else "?"
str_level = log_levels[level] if level in log_levels else "?"

print timestamp, level, filename, linenumber, message
print timestamp, str_level, app_uuid, filename, linenumber, message

def _appbank_status_response(self, endpoint, data):
apps = {}
Expand Down

0 comments on commit ad5e065

Please sign in to comment.