Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
ee1025c8
Commit
ee1025c8
authored
Nov 04, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implmemted rabbitmq logging for user
parent
adbe068c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
23 deletions
+79
-23
__init__.py
drip_planner2/src/drip_logging/__init__.py
+0
-0
__init__.pyc
drip_planner2/src/drip_logging/__init__.pyc
+0
-0
drip_logging_handler.py
drip_planner2/src/drip_logging/drip_logging_handler.py
+75
-0
drip_logging_handler.pyc
drip_planner2/src/drip_logging/drip_logging_handler.pyc
+0
-0
drip_loggHandler.py
drip_planner2/src/logging/drip_loggHandler.py
+0
-23
rpc_server.py
drip_planner2/src/rpc_server.py
+4
-0
No files found.
drip_planner2/src/drip_logging/__init__.py
0 → 100644
View file @
ee1025c8
drip_planner2/src/drip_logging/__init__.pyc
0 → 100644
View file @
ee1025c8
File added
drip_planner2/src/drip_logging/drip_logging_handler.py
0 → 100644
View file @
ee1025c8
import
logging
import
pika
from
python_logging_rabbitmq
import
RabbitMQHandler
import
json
class
DRIPLoggingHandler
(
RabbitMQHandler
):
def
open_connection
(
self
):
self
.
sequenceNumber
=
0
"""
Connect to RabbitMQ.
"""
# Set logger for pika.
# See if something went wrong connecting to RabbitMQ.
handler
=
logging
.
StreamHandler
()
handler
.
setFormatter
(
self
.
formatter
)
rabbitmq_logger
=
logging
.
getLogger
(
'pika'
)
rabbitmq_logger
.
addHandler
(
handler
)
rabbitmq_logger
.
propagate
=
False
rabbitmq_logger
.
setLevel
(
logging
.
WARNING
)
if
not
self
.
connection
or
self
.
connection
.
is_closed
:
self
.
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
**
self
.
connection_params
))
if
not
self
.
channel
or
self
.
channel
.
is_closed
:
self
.
channel
=
self
.
connection
.
channel
()
self
.
channel
.
queue_declare
(
queue
=
'log_qeue_user'
,
durable
=
True
)
# Manually remove logger to avoid shutdown message.
rabbitmq_logger
.
removeHandler
(
handler
)
def
emit
(
self
,
record
):
self
.
acquire
()
try
:
if
not
self
.
connection
or
self
.
connection
.
is_closed
or
not
self
.
channel
or
self
.
channel
.
is_closed
:
self
.
open_connection
()
self
.
channel
.
basic_publish
(
exchange
=
''
,
routing_key
=
'log_qeue_user'
,
body
=
self
.
format
(
record
),
properties
=
pika
.
BasicProperties
(
delivery_mode
=
2
)
)
except
Exception
:
self
.
channel
,
self
.
connection
=
None
,
None
self
.
handleError
(
record
)
finally
:
if
self
.
close_after_emit
:
self
.
close_connection
()
self
.
release
()
def
format
(
self
,
record
):
drip_record
=
{}
drip_record
[
'timestamp'
]
=
record
.
created
drip_record
[
'owner'
]
=
'user'
drip_record
[
'level'
]
=
record
.
levelname
drip_record
[
'loggerName'
]
=
record
.
module
drip_record
[
'message'
]
=
record
.
message
drip_record
[
'millis'
]
=
record
.
created
self
.
sequenceNumber
+=
1
drip_record
[
'sequenceNumber'
]
=
self
.
sequenceNumber
drip_record
[
'sourceClassName'
]
=
record
.
module
drip_record
[
'sourceMethodName'
]
=
record
.
funcName
return
json
.
dumps
(
drip_record
)
\ No newline at end of file
drip_planner2/src/drip_logging/drip_logging_handler.pyc
0 → 100644
View file @
ee1025c8
File added
drip_planner2/src/logging/drip_loggHandler.py
deleted
100644 → 0
View file @
adbe068c
import
logging
class
DRIPLogHandler
(
logging
.
StreamHandler
):
def
emit
(
self
,
record
):
try
:
msg
=
self
.
format
(
record
)
stream
=
self
.
stream
same_line
=
hasattr
(
record
,
'same_line'
)
if
self
.
on_same_line
and
not
same_line
:
stream
.
write
(
self
.
terminator
)
stream
.
write
(
msg
)
if
same_line
:
stream
.
write
(
'... '
)
self
.
on_same_line
=
True
else
:
stream
.
write
(
self
.
terminator
)
self
.
on_same_line
=
False
self
.
flush
()
except
(
KeyboardInterrupt
,
SystemExit
):
raise
except
:
self
.
handleError
(
record
)
\ No newline at end of file
drip_planner2/src/rpc_server.py
View file @
ee1025c8
...
@@ -12,6 +12,7 @@ from planner.dum_planner import *
...
@@ -12,6 +12,7 @@ from planner.dum_planner import *
import
sys
import
sys
import
tempfile
import
tempfile
import
time
import
time
from
drip_logging.drip_logging_handler
import
*
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
if
not
getattr
(
logger
,
'handler_set'
,
None
):
if
not
getattr
(
logger
,
'handler_set'
,
None
):
...
@@ -31,6 +32,9 @@ def init_chanel(args):
...
@@ -31,6 +32,9 @@ def init_chanel(args):
else
:
else
:
rabbitmq_host
=
'127.0.0.1'
rabbitmq_host
=
'127.0.0.1'
rabbit
=
DRIPLoggingHandler
(
host
=
rabbitmq_host
,
port
=
5672
,
exchange
=
""
)
logger
.
addHandler
(
rabbit
)
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
rabbitmq_host
))
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
rabbitmq_host
))
channel
=
connection
.
channel
()
channel
=
connection
.
channel
()
channel
.
queue_declare
(
queue
=
queue_name
)
channel
.
queue_declare
(
queue
=
queue_name
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment