Skip to main content

Command Palette

Search for a command to run...

Ideas for Improving Git Commits and Application Logs

Updated
β€’3 min read
J

Jack Linke tends to learn the hard way - and shares the lessons from those experiences with others through blogging, tweets, and speaking engagements. He has been developing software and hardware projects off-and-on for most of his life, but much of his relevant web development experience has been hard-earned over the past four years during development of Watervize - a B2B2B SaaS web application to help irrigation water utility companies improve efficiency, analysis, and communication with staff and agriculture customers.

Jack's technology interests include Python, the Django project, HTMX, GIS, graph theory, data storytelling, and visualization. He is a frequent contributor to the open source community and a contributing member of the Python Software Foundation.

Outside of coding, Jack serves as a Marine Corps Officer, solves unusual math and logic problems, and makes a mess in the kitchen.

Open Source Projects:

  • django-postgresql-dag - Directed Acyclic Graphs with a variety of methods for both Nodes and Edges, and multiple exports
  • django-calendardate - A Django calendar model with date metadata for querying against
  • django-htmx-todo-list - An example of todo list application using Django and HTMX

Mastodon (@jack@jacklinke.com)

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:

  1. The implementation: a single, focused change
  2. Tests that demonstrate the implementation works
  3. Updated documentation reflecting the change
  4. 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.

D

I really like that idea and we use it our project :) Also, shared it with my colleagues in one of our monthly digests.