From dcd747b34005a76c4160791f9ce03a3485d83922 Mon Sep 17 00:00:00 2001 From: bghira Date: Sun, 28 Jan 2024 17:02:41 -0600 Subject: [PATCH] logging --- discord_tron_master/cogs/image/generate.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/discord_tron_master/cogs/image/generate.py b/discord_tron_master/cogs/image/generate.py index 674338a..a529a57 100644 --- a/discord_tron_master/cogs/image/generate.py +++ b/discord_tron_master/cogs/image/generate.py @@ -5,6 +5,8 @@ from discord_tron_master.models.user_history import UserHistory import discord_tron_master.classes.discord.message_helpers as helper import logging, traceback +logger = logging.getLogger("discord_tron.image.generate") +logger.setLevel('DEBUG') from discord_tron_master.bot import DiscordBot from discord_tron_master.classes.jobs.image_generation_job import ImageGenerationJob from discord_tron_master.bot import clean_traceback @@ -51,7 +53,7 @@ async def generate_range_random(self, ctx, arg_count = None, *, theme = None): return gpt = GPT() prompt = await gpt.random_image_prompt(out_theme) - logging.info(f"Random prompt generated by GPT: {prompt}") + logger.info(f"Random prompt generated by GPT: {prompt}") await self.generate(ctx, prompt=prompt) @@ -94,7 +96,7 @@ async def generate(self, ctx, *, prompt): # We are going to ask OpenAI which model to use for this user. gpt = GPT() auto_resolution, auto_model = await gpt.auto_model_select(_prompt) - logging.info(f"Auto-model selected by GPT: {auto_model}") + logger.info(f"Auto-model selected by GPT: {auto_model}") extra_payload["user_config"]["model"] = auto_model extra_payload["user_config"]["resolution"] = auto_resolution discord_first_message = await DiscordBot.send_large_message(ctx=ctx, text=f"Job queuing: `" + _prompt + "`") @@ -112,10 +114,10 @@ async def generate(self, ctx, *, prompt): user_history = UserHistory.add_entry(user=ctx.author.id, message=int(f"{ctx.id if hasattr(ctx, 'id') else ctx.message.id}{idx}"), prompt=_prompt, config_blob=extra_payload["user_config"]) idx += 1 except Exception as e: - logging.warning(f"Had trouble adding the user history entry: {e}") + logger.warning(f"Had trouble adding the user history entry: {e}") # Generate a "Job" object that will be put into the queue. await discord_first_message.edit(content=f"Job {job.id} queued on {worker.worker_id}: `" + _prompt + "`") - logging.info("Worker selected for job: " + str(worker.worker_id)) + logger.info("Worker selected for job: " + str(worker.worker_id)) # Add it to the queue await discord.queue_manager.enqueue_job(worker, job) except Exception as e: @@ -153,7 +155,7 @@ async def get_statistics(self, ctx, user_id = None): f"\n -> {common_terms}" ) except Exception as e: - logging.error("Caught error when getting user history: " + str(e)) + logger.error("Caught error when getting user history: " + str(e)) await ctx.send( f"{ctx.author.mention} Statistics are not currently available at this time, try again later." ) @@ -167,7 +169,7 @@ async def search_prompts(self, ctx, search_string: str): # Shuffle the list: import random random.shuffle(discovered_prompts) - logging.info(f"Discovered prompts: {discovered_prompts}") + logger.info(f"Discovered prompts: {discovered_prompts}") if not discovered_prompts: # We didn't discover any prompts. Let the user know their search was bonkers. return await ctx.send( @@ -181,7 +183,7 @@ async def search_prompts(self, ctx, search_string: str): output_string = f"{output_string}\n- `{prompt[0]}`" await ctx.send(output_string) except Exception as e: - logging.error("Caught error when searching prompts: " + str(e)) + logger.error("Caught error when searching prompts: " + str(e)) await ctx.send( f"{ctx.author.mention} Search is not currently available at this time, try again later." ) @@ -201,7 +203,7 @@ async def invite_to_thread(self, ctx): f"{ctx.author.mention} is now in the party." ) except Exception as e: - logging.error("Caught error when inviting to thread: " + str(e)) + logger.error("Caught error when inviting to thread: " + str(e)) await ctx.send( f"{ctx.author.mention} {self.generic_error}." ) @@ -232,8 +234,8 @@ async def generate_from_user_config(self, ctx, user_config, user_id, prompt): user_history = UserHistory.add_entry(user=user_id, message=int(f"{ctx.id if hasattr(ctx, 'id') else ctx.message.id}{idx}"), prompt=_prompt, config_blob=user_config) idx += 1 except Exception as e: - logging.warning(f"Had trouble adding the user history entry: {e}") - logging.info("Worker selected for job: " + str(worker.worker_id)) + logger.warning(f"Had trouble adding the user history entry: {e}") + logger.info("Worker selected for job: " + str(worker.worker_id)) # Add it to the queue await discord.queue_manager.enqueue_job(worker, job) except Exception as e: