radareorg / r2ai

local language model for radare2
https://www.radare.org
MIT License
104 stars 17 forks source link

Use python's builtin logging instead of dirrectly printing #38

Closed nitanmarcel closed 2 months ago

nitanmarcel commented 2 months ago

Checklist

Description

Makes use of python's built-in logging library to control which logs get displayed based on an environment variable.

Right now it's a base, and it need to be revised based on what where should go.

Built-in commands are:

LOGGING.debug LOGGING.info LOGGING.warn LOGGING.error LOGGING.critical

The levels can be controlled at runtime via the -V command, or by R2API_LOG= environment.

Option to also push to a file exists with R2AI_LOGFILE=.

I'm thinking of making it push to both file and console by default and give r2ai it's own directory in .local. appdirs could make picking up directories easier but can be done manually too.

The logs will be structured/session with names like, r2ai.log (for last session), r2ai.log.1, r2ai.log.2 etc.

What do you think? Maybe also move everything else to it's own config file

nitanmarcel commented 2 months ago

I've added childers to the loggers. for example for openai requests it will show the prefix r2ai.openai r2ai being the base and openai the endpoint used. and I removed the KWSPLITRESPONSE completly. since it can be identified by the log tags

nitanmarcel commented 2 months ago

WAAAIT I just saw something

nitanmarcel commented 2 months ago

since we already have rich and it has a nice handler to make the logging pop more with colors based on their level

Screenshot from 2024-09-09 20-31-38

nitanmarcel commented 2 months ago

^

can you redo? for some reason they don't show up for me..