Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ Many web/mobile applications generate huge amount of event logs (c,f. login, log

**fluent-logger-python** is a Python library, to record the events from Python application.

## Requirements

* Python 2.6 or greater including 3.x

## Installation

This library is distributed as 'fluent-logger' python package. Please execute the following command to install it.

$ pip install fluent-logger

On Python 2.5, you have to install 'simplejson' in addition.

## Configuration

Fluent daemon must be lauched with the following configuration:
Expand Down
2 changes: 1 addition & 1 deletion fluent/handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
import sys, urllib
import sys
import msgpack
import socket
import threading
Expand Down
3 changes: 2 additions & 1 deletion fluent/sender.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import msgpack
import socket
import threading
Expand Down Expand Up @@ -57,7 +58,7 @@ def _make_packet(self, label, timestamp, data):
tag = self.tag
packet = (tag, timestamp, data)
if self.verbose:
print packet
print(packet)
return self.packer.pack(packet)

def _send(self, bytes):
Expand Down
9 changes: 3 additions & 6 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys
sys.path = ['..'] + sys.path

from test_event import *
from test_sender import *
from test_handler import *
from tests.test_event import *
from tests.test_sender import *
from tests.test_handler import *
11 changes: 8 additions & 3 deletions tests/mockserver.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import socket
import threading
import time
from cStringIO import StringIO
from msgpack import Unpacker

try:
from cStringIO import StringIO as BytesIO
except ImportError:
from io import BytesIO

class MockRecvServer(threading.Thread):
"""
Single threaded server accepts one connection and recv until EOF.
"""
def __init__(self, port):
self._sock = socket.socket()
self._sock.bind(('localhost', port))
self._buf = StringIO()
self._buf = BytesIO()

threading.Thread.__init__(self)
self.start()
Expand All @@ -36,4 +40,5 @@ def wait(self):
def get_recieved(self):
self.wait()
self._buf.seek(0)
return list(Unpacker(self._buf))
# TODO: have to process string encoding properly. currently we assume that all encoding is utf-8.
return list(Unpacker(self._buf, encoding='utf-8'))
6 changes: 3 additions & 3 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import unittest
import mockserver
from tests import mockserver
import logging
import fluent.handler
import msgpack

class TestLogger(unittest.TestCase):
def setUp(self):
super(TestLogger, self).setUp()
for port in xrange(10000, 20000):
for port in range(10000, 20000):
try:
self._server = mockserver.MockRecvServer(port)
self._port = port
break
except IOError, e:
except IOError as e:
pass

def get_data(self):
Expand Down
9 changes: 5 additions & 4 deletions tests/test_sender.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from __future__ import print_function
import unittest
import mockserver
from tests import mockserver
import fluent.sender
import msgpack

class TestSender(unittest.TestCase):
def setUp(self):
super(TestSender, self).setUp()
for port in xrange(10000, 20000):
for port in range(10000, 20000):
try:
self._server = mockserver.MockRecvServer(port)
break
except IOError, e:
print e
except IOError as e:
print(e)
pass
self._sender = fluent.sender.FluentSender(
tag='test',
Expand Down
10 changes: 6 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[tox]
envlist = py25, py26, py27
envlist = py26, py27, py32

[testenv]
commands=python setup.py test

[testenv:py25]
deps = simplejson

[testenv:py26]
basepython = python2.6

[testenv:py27]
basepython = python2.7

[testenv:py32]
basepython = python3.2