Forums

Can't get errors on log

Hi, I would like your help with an issue that I'm facing. I want to hold multiple telegram bots, but using a single source code, just changing the bot id. To do so, I'm using the following structure:

My wsgi loads a py file, as expected:

import sys    
project_home = '/home/xxxxxx/bots/telegramBot1'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

# import flask app but need to call it "application" for WSGI to work
from flask_app import app as application  # noqa

And inside of the flask_app, I call another py, which I'm using as a generic library, I have a folder called DEV, and another called PROD, and inside of this folder, I have a bot_source.py:

import json
import sys
import os
from flask import Flask
from flask import request

f = open(os.path.dirname(os.path.abspath(__file__)) + '/customer.json',)
customerData = json.load(f)
f.close()

project_home = '/home/xxxxx/telegram_bot_source/' + customerData['version'] + '/'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

import bot_source as bot_source

bot_source.setVariables(customerData)
bot_source.setWebhook()

app = Flask(__name__)

@app.route('/', methods=['POST'])
def doPost():
    return bot_source.doPost(request)

And inside of the bot_source, it's where I do my thing for the bot. My issue, it's that when a function inside of the bot_source.py has an issue, I don't see the error inside the com.error.log, but I can see prints inside com.server.log

For example, I have this setWebhook function, inside of the bot_source:

def setWebhook():
    print('setWebhook')

    response = rq.get(telegramUrl + "/deleteWebhook")
    print('deleteWebhook ' + json.dumps(response) )

    response = rq.get(telegramUrl + "/setWebhook?url=" + webAppUrl)
    print('setWebhook ' + json.dumps(response) )

I can see the "setWebhook" print, inside the com.server.log, but the next print (which is the one throwing me an error) I cannot see it, and there's no error inside the com.error.log

What am I doing wrong ? Can anybody, please, shed me some light ?

Thank you

You can get your prints to appear in the error log by printing to stderr and it might help if you flush the output. For example:

print('deleteWebhook ' + json.dumps(response), file=sys.stderr, flush=True)

Thanks Glenn, that solves my issue.. ;)

Great!