Тёмный

COLOURED logging in Python 

Carberra
Подписаться 21 тыс.
Просмотров 5 тыс.
50% 1

Опубликовано:

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 26   
@nan.a323
@nan.a323 2 года назад
After a little bit of research, I found out that you can actually use rgb values to set the colors. If the terminal supports true color you can use: This code: \33[38;2; ; ; m for foreground color and this code \33[48;2; ; ; m for background color. (don't put spaces, I put them there for easier visibility) Reset stays the same Where r, g and b can range from 0 to 255 depending on the rgb value of the color you want. Let's say you want Persian Green (code: 42, 157, 143) in logging.INFO You could do: logging.INFO: f"\33[38;2;42;157;143m{FMT}\33[0m" This gives you more control of what colors you wanna use, although it would be wise to check if the console supports true color before using them. I failed to find a way to check this automatically (through python) so if any of you have a solution and would like to share I'm sure everyone could benefit from it :) edit: my tests were made in windows terminal, in case someone wants to know
@Carberra
@Carberra 2 года назад
This is actually super cool info! I know there's a way to check if a terminal supports colour (though I don't know the way personally), but yeah not sure about the true colour thing. Would be cool to know though.
@Carberra
@Carberra 2 года назад
Just saw a notification for your comment -- looks like it got autoremoved cos it contained a link. If you wanna repost it with a modified like (like replacing the . with "dot") go for it haha.
@MrFlexNC
@MrFlexNC 2 года назад
clean & straight to the point like every tutorial should be 👍
@Carberra
@Carberra 2 года назад
Glad you enjoyed it!
@atomicman007
@atomicman007 2 года назад
Once, I asked about this in Hikari's Discord server. And here we are with a tutorial on. What a pleasant coincidence! (Or is it 👀)
@Carberra
@Carberra 2 года назад
Probably a bit of both -- I went to learn it for my own purposes, but I've seen a few people ask about it before. Pretty convenient either way though!
@oTerminal_
@oTerminal_ 2 года назад
Another great video!
@gamerdinbasarabia2093
@gamerdinbasarabia2093 2 года назад
Cool video 🤩 Just out of curiosity, it seems you mostly use your keyboard, have you ever tried the vim extension form vs? 🤔
@Carberra
@Carberra 2 года назад
Thanks! I haven't, but I have tried Vim itself before, and I just get muddled honestly. I'm so used to the ones I know haha.
@gamerdinbasarabia2093
@gamerdinbasarabia2093 2 года назад
@@Carberra Yeah, I believe it's harder to get rid of old habits than to make new ones :))
@sairamkumar6711
@sairamkumar6711 2 года назад
Really helpful
@Confusedcapybara8772
@Confusedcapybara8772 5 месяцев назад
So how would you use this in a different files and modules
@Carberra
@Carberra 5 месяцев назад
Once you've configued the logger, it'll work anywhere in your program. If you mean how to get it working across multiple programs, you would just want to import and run some function from a shared module that sets it all up.
@helish_88
@helish_88 2 года назад
найс :kappa:
@teagancollyer
@teagancollyer 2 года назад
This video gave me an idea for something I can add to my bots error handler. I've normally just dealt with standard error messages of 'Something broke becuase of xyz" however I had an idea to add in some more useful informaation such as the server ID/Name where the error occcured, the user ID/Name who caused the error (if it's triggered by a user), the command that was used, the time and date it occured (in UTC) and then the information about the error. Is it possible to add such features to a errror handler and if so would you mind making a video about it at some point as I'm not very famiar with what information I can get from errors (I do read docs about them).
@Carberra
@Carberra 2 года назад
Yeah that's definitely possible. If you're using discord.py, the context gets passed through (same context as the command used), and on Hikari, you have event.context. The non-command error handlers have similar mechanisms but I'm less familiar with those.
@GusPolinski13
@GusPolinski13 Год назад
How can you get the timestamp added to each of the logs?
@Carberra
@Carberra Год назад
Include `%(asctime)s` in the format.
@GusPolinski13
@GusPolinski13 Год назад
@@Carberra - tried adding here but it didn't work. I'm guessing format is somewhere else? handler = logging.StreamHandler() handler.setFormatter(CustomFormatter()) logging.basicConfig( level=logging.DEBUG, format='%(asctime)s', handlers=[handler], )
@JJGhostHunters
@JJGhostHunters 2 года назад
Hi...is the code for this available? I am not seeing it in the repository..."How its Done"
@Carberra
@Carberra 2 года назад
That repo isn't updated. You'll need to copy the code from the video.
@TangoClient
@TangoClient 2 года назад
Great video!. What is that VS theme?
@Carberra
@Carberra 2 года назад
Ayu Mirage Bordered + Fira Code as the font. I'm tempted to make a video about it cos a lot of people seem to really like it haha. Glad you liked the video!
@TangoClient
@TangoClient 2 года назад
@@Carberra Thanks you. Good idea haha but i'm still waiting for the hikari series hahahaha. I really like your way of coding so I think it will be very good
@Carberra
@Carberra 2 года назад
Me too! I'm waiting for the stable to release, just so no breaking changes come in half way through the series haha. ETA for that is April atm. I'll probably make some more supplementary videos in the meantime.
Далее
Pydantic is OP, here's why
18:10
Просмотров 23 тыс.
ИСТОРИЯ ПРО ШТАНЫ #shorts
00:32
Просмотров 298 тыс.
Loguru - Simplified Python Logging with Loguru!
28:56
Why you should ALWAYS use `if __name__ == "__main__"`
7:17
Make A Security Camera With Python
35:58
Просмотров 236 тыс.
Modern Python logging
21:32
Просмотров 196 тыс.
Why *ARGS and **KWARGS are Useful in Python
10:44
Просмотров 17 тыс.
Python SQLAlchemy ORM - 1 to MANY Relationships
14:10