python - logging file does not exist when running in celery -
first, i'm sorry low level english
i create website study
i create send sms feature using django + redis + celery
tasks/send_buy_sms.py
from celery import task items.utils import sendsms class sendbuymessagetask(task): def run(self, buyer_nickname, buyer_phone, saler_phone, selected_bookname): sms = sendsms() sms.send_sms(buyer_nickname, buyer_phone, saler_phone, selected_bookname)
items/utils.py
import os import requests import json class sendsms(): def send_sms(self, buyer_nickname, buyer_phone, saler_phone, selected_bookname): appid = [...] apikey = [...] sender = '...' receivers = [saler_phone, ] content = '...' url = os.environ.get("url") params = { 'sender': sender, 'receivers': receivers, 'content': content, } headers = {...} r = '...' return params
when send sms using code has no problem
[2017-09-12 17:20:43,532: warning/worker-6] task success
and want make log file , insert log "success send sms" when user click "send sms button"
wef/wef/decorators.py
from django.utils import timezone import logging def log_decorator(func): logging.basicconfig(filename='../../sendsms.log', level=logging.info) def wrap_func(self, *args, **kwargs): time_stamp = timezone.localtime(timezone.now()).strftime('%y-%m-%d %h:%m') logging.info('[{}] success send sms'.format(time_stamp)) print(logging) return func(self, *args, **kwargs) return wrap_func
but when click 'send sms' button task ok , log file doesn't created...
so want know 'what problem?'
i change code create logfile
-> print log
wef/wef/decorators.py
from django.utils import timezone def log_decorator(func): def wrap_func(self, *args, **kwargs): time_stamp = timezone.localtime(timezone.now()).strftime('%y-%m-%d %h:%m') ## print log print('[{}] succes send sms'.format(timestamp)) ## print log return func(self, *args, **kwargs) return wrap_func
when click 'send sms button' log print in celery
i'm confused because print() working create log file doesn't working...
i think code(create logging file) no problem because when practice create log file without django,celery,redis, log file created successfully
same code, same feature not working in django , celery
please give me advise thank you
i guess have add logger -
# import logging library import logging # instance of logger logger = logging.getlogger(__name__) def my_view(request, arg1, arg): ... if bad_mojo: # log error message logger.error('something went wrong!')
here assuming have configured loggers, handlers, filters , formatters
for more information visit url
Comments
Post a Comment