Python Forum

Full Version: how to log ip addresses in loguru
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I want to keep track in the logs as well as time message level etc, I want to log down the clients ip address

Is this possible

Thanks,
Rob
ie when i run the software and in console i get the ip address of the pc accessing the web server

127.0.0.1 - - [21/Jul/2024 20:40:11] "POST /password HTTP/1.1" 200 -
obviously im accessing the web server from the same host but i do get different ips when i try to access the webserver from another LAN pc
worked it out

@app.route('/password', methods=['GET', 'POST'])
def password():
ip_addr = request.remote_addr
form = PasswordForm()
if request.method == 'POST' and form.validate():
logger.warning(f'{ip_addr} {form.un.data} your current password is wrong, please click back and try again')
and in log file i get this

2024-07-22-12-55-27 | WARNING | 127.0.0.1 robert.wild your current password is wrong, please click back and try again