Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Logging to a file is supported.
  • Loading branch information
mooshu1x2 committed Jul 26, 2016
1 parent cb0756b commit e2f6de8578f88b0c9d18c06b883a794a3763f211
Showing 3 changed files with 24 additions and 31 deletions.
@@ -12,10 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from userale.logger import Logger
from userale.version import __version__
from PyQt5.QtCore import QObject, QEvent
import datetime
import time
import logging
from userale.format import StructuredMessage

_ = StructuredMessage

class Ale (QObject):
"""
@@ -24,7 +28,7 @@ class Ale (QObject):
(a.k.a. system and signals sent between QObjects).
"""
def __init__(self,
url="",
output="userale.log",
autostart=True,
interval=5000,
user=None,
@@ -33,7 +37,7 @@ def __init__(self,
resolution=500,
shutoff=[]):
"""
:param url: [str] The URL to which logs will be sent (can either be file:// or http://)
:param output: [str] The file or url path to which logs will be sent
:param autostart: [bool] Should UserAle start auotmatically on app rendering
:param interval: [int] The minimum time interval in ms betweeen batch transmission of logs
:param user: [str] Identifier for the user of the application
@@ -63,7 +67,7 @@ def __init__(self,
QObject.__init__(self)

# UserAle Configuration
self.url = url
self.output = output
self.autostart = autostart
self.interval = interval
self.user = user
@@ -74,6 +78,12 @@ def __init__(self,
# Store logs
self.logs = []

# Configure logging
self.logger = logging
self.logger.basicConfig(level=logging.INFO,
filename=self.output,
format='%(message)s')

# Drag/Drop - track duration
self.dd = datetime.datetime.now ()

@@ -86,7 +96,7 @@ def eventFilter(self, object, event):
Filters events for the watched object (in this case, QApplication)
'''

data = {}
data = None

if (event.type () == QEvent.MouseButtonPress):
data = self.handleMouseEvents ("mousedown", event, object)
@@ -117,9 +127,9 @@ def eventFilter(self, object, event):
else:
pass

if data:
Logger.stdout (data)

# self.logs.append (data)
if data is not None:
self.logger.info (_(data))
# return super(Ale, self).eventFilter(object, event)
return False

@@ -24,28 +24,11 @@
# Logger will need to optinally handle authorization
# through basic http auth, proxy, and SOCKS

class Logger (object):
class StructuredMessage (object):
"""
"""
def __init__(self, data):
self.data = data

# def __init__(self, url="", data={}):
# self.url = url
# self.data = data

# write to file

# send over url
# @staticmethod
# def emit (url, data):
# """
# """
# # url = self.url
# # payload = self.data
# r = requests.post (url, json=data)
# r.status_code

# print to stdout
@staticmethod
def stdout (data):
print (json.dumps (data, sort_keys=False, indent=4))

def __str__(self):
return '%s' % (json.dumps (self.data, sort_keys=False, indent=4))
@@ -44,7 +44,7 @@ def test_app ():
app = QApplication(sys.argv)
app.setObjectName ("testApplication")
ex = TestApplication()
ale = Ale ()
ale = Ale (output="mouse.log", user="testUser", version="0.0.1")
# install globally
app.installEventFilter (ale)

0 comments on commit e2f6de8

Please sign in to comment.