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: https://github.com/slashsbin/styleguide-git-commit-message
A couple other good reads include:
- https://dev.to/javidjms/git-write-better-commits-with-gitmoji-3193
- https://engineeringfordatascience.com/posts/gitmoji/
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.