Between talks at DjangoCon and conversations with Jeff Triplett @webology and others, I've been thinking a lot about git commits and logging over the past week, so I put together some notes on the topic.
gitmoji
gitmoji is "an emoji guide for your commit messages". It provides a set of emoji paired with descriptions, which can help to provide visual cues to more quickly understand the purpose of commits.
The first place I heard of gitmoji was the openfun git handbook, which has some great tips for using what they describe as "emoji-driven commit message format".
Jeff has used emojis in commits as well, and recommended this excellent style guide: github.com/slashsbin/styleguide-git-commit-..
A couple other good reads include:
The gitmoji website also has a page with related resources, including:
- Plugins for Jetbrains IDEs, VSCode, Sublime Text, etc
- Browser extension for gitmoji
- Desktop gitmoji GUIs
- etc
The Perfect Commit
When it comes to improving your Git Commits, also consider the advice from Simon Willison about the "Perfect Commit". A perfect commit includes the following:
- The implementation: a single, focused change
- Tests that demonstrate the implementation works
- Updated documentation reflecting the change
- A link to an issue thread providing further context
This is great advice for improving your contributions to software development, and it is something I am working to be more consistent on myself. You can read his post on this topic in detail at his blog.
Emojis in Logs
I have also begun using emojis in my logs for the same reasons one might use them in git commits.
In my primary django project, I added the following class to my project settings.
@dataclass
class Logmoji:
"""
Provides Emojis for more eye-catching logs
"""
curious: str = "๐คจ"
paused: str = "๐ค"
action_begin: str = "๐"
action_end: str = "๐"
money_related: str = "๐ต"
email_related: str = "๐จ"
time_related: str = "๐
"
statistics_related: str = "๐"
auth_related: str = "๐"
maintenance_related: str = "๐ง"
success: str = "๐"
denied: str = "โ"
potential_issue: str = "๐พ"
warning: str = "โ ๏ธ"
error: str = "๐"
critical: str = "๐ฃ"
Assuming you already have logging set up in your project, use this in the following ways:
from django.conf.settings import Logmoji
try:
item = ItemsModel.objects.get(id=1)
except ItemsModel.DoesNotExist as e:
logger.warning(f"{Logmoji.curious} {e}")
๐คจ Exception: ItemsModel matching query does not exist.
from django.conf.settings import Logmoji
logger.warning(f"{Logmoji.auth_related} User is not logged in. Redirect to login.")
๐ User is not logged in. Redirect to login.
You could, of course, directly add the emoji in the text of the log entry, but I like that if I change my mind about the emoji I want for a particular use, I can easily make one change in settings and the update propagates to all future log entries.
Conclusion
I hope you'll give these all a try and let me know how they work for you.