Beispiel #1
0
def test_log():
    logdir = make_test_dir()
    port = run_server()

    celstash.configure(logdir=logdir, logstash_port=port)
    log = celstash.new_logger('celstash-test')
    msg = 'Let sleeping dogs lie.'
    log.error(msg)

    # Let the message propagate
    sleep(0.1)

    logfile = join(logdir, 'celstash-test.json')
    assert isfile(logfile), 'no log file at %s' % logfile
    with open(logfile) as fo:
        record = json.loads(fo.readline())
    assert record['msg'] == msg, 'bad message in file'

    assert len(messages) == 1, 'no message in UDP'
    record = json.loads(messages[0])
    assert record['@message'] == msg, 'bad message in UDP'
Beispiel #2
0
import logging

from celery import Celery
import celstash

# Celery configuration
CELERY_BROKER_URL = 'amqp://*****:*****@rabbit:5672/'
CELERY_RESULT_BACKEND = 'rpc://'

# Celstash Initialization
celstash.configure(logstash_host='logstash', logstash_port=9999)
logger = celstash.new_logger('flask-celery')
logger.setLevel(logging.INFO)

# Initialize Celery
celery = Celery('workerA',
                broker=CELERY_BROKER_URL,
                backend=CELERY_RESULT_BACKEND)
print(celery, "<== celery worker A")


@celery.task()
def add_nums(a, b):
    print(a, "<====>", b)
    return a + b
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__date__= 'Aug 25, 2015 '
__author__= 'samuel'
from celery import Celery, platforms

#logstash logger
import celstash
import logging

celstash.configure(logstash_host='logstash', logstash_port=9999)
logger = celstash.new_logger('worker1')
logger.setLeve=(logging.INFO)

app = Celery('tasks', backend='redis://redis/2', broker='redis://redis/1')
platforms.C_FORCE_ROOT = True

@app.task(name='tasks.add')
def add(x, y):
    logger.info('parameters (x,y): (%s, %s)' % (x,y))
    logger.info('return: %s' % str(x+y))
    return x + y