8000 make fluent/__init__.py empty · socrateslee/fluent-logger-python@dd80477 · GitHub
[go: up one dir, main page]

Skip to content

Commit dd80477

Browse files
committed
make fluent/__init__.py empty
1 parent 38cdbea commit dd80477

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

fluent/__init__.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +0,0 @@
1-
import json
2-
import urllib2
3-
4-
from fluent import logger
5-
6-
global_logger = None
7-
8-
def setup(tag, **kwargs):
9-
host = kwargs.has_key("host") and kwargs['host'] or 'localhost'
10-
port = kwargs.has_key("port") and kwargs['port'] or 24224
11-
12-
global global_logger
13-
global_logger = logger.FluentLogger(tag, host=host, port=port)
14-
15-
class Event:
16-
def __init__(self, label, data, **kwargs):
17-
global global_logger
18-
self.logger = kwargs.has_key("logger") and kwargs['logger'] or global_logger
19-
20-
if not isinstance(data, dict) :
21-
raise Exception("data must be dict")
22-
23-
self.logger.emit(label, data)

fluent/logger.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
import json
88
import time
99

10+
global_logger = None
11+
12+
def setup(tag, **kwargs):
13+
host = kwargs.has_key("host") and kwargs['host'] or 'localhost'
14+
port = kwargs.has_key("port") and kwargs['port'] or 24224
15+
16+
global global_logger
17+
global_logger = FluentLogger(tag, host=host, port=port)
18+
19+
def get_global_logger():
20+
global global_logger
21+
return global_logger
22+
1023
class FluentLogger:
1124
def __init__(self,
1225
tag,
@@ -32,9 +45,6 @@ def __init__(self,
3245
# will be retried in emit()
3346
self.socket = None
3447

35-
def __del__(self):
36-
self._close()
37-
3848
def emit(self, label, data):
3949
bytes = self._make_packet(label, data)
4050
self._send(bytes)
@@ -50,6 +60,7 @@ def _connect(self):
5060
return sock
5161

5262
def _close(self):
63+
print self.socket
5364
if self.socket:
5465
self.socket.close()
5566
self.socket = None

tests/test_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import unittest
22

33
import fluent
4-
from fluent import Event
4+
from fluent import event, logger
55

6-
fluent.setup(server='localhost', tag='app')
6+
logger.setup(server='localhost', tag='app')
77

88
class TestHandler(unittest.TestCase):
99
def testLogging(self):
1010
# send event with tag app.follow
11-
Event('follow', {
11+
event.Event('follow', {
1212
'from': 'userA',
1313
'to': 'userB'
1414
})

0 commit comments

Comments
 (0)
0