Real-time validation for mtlog message templates in Go code.
- 🔍 Real-time diagnostics - See template errors as you type
- 🎯 Precise error locations - Jump directly to problematic code
- 📊 Severity levels - Errors, warnings, and suggestions
- ⚡ Quick fixes - Automatic fixes for common issues
- ⚙️ Configurable - Customize analyzer path and flags
// ❌ Error: Template has 2 properties but 1 argument
logger.Information("User {UserId} logged in from {IP}", userId)
// ^^^^^^ Quick fix: Add 1 missing argument
// ⚠️ Warning: Using @ prefix with basic type
logger.Debug("Count is {@Count}", 42)
// 💡 Suggestion: Property name should be PascalCase
logger.Information("User {userId} completed action", "user123")
// ^^^^^^ Quick fix: Change to 'UserId'The extension provides automatic fixes for common issues:
- PascalCase property names - Converts
userIdtoUserId,user_idtoUserId, etc. - Argument mismatches - Adds placeholder arguments for missing properties or removes excess arguments
- Format specifier corrections - Fixes invalid format specifiers (e.g.,
{Count:d3}→{Count:000}) - Context key constants - Extracts repeated string literals to constants
- LogValue() method generation - Creates stub implementations for safe logging of complex types
Apply fixes by clicking the light bulb (💡) or pressing Ctrl+. (Windows/Linux) or Cmd+. (macOS) when your cursor is on the diagnostic.
- Go 1.21 or later
- mtlog-analyzer (automatically detected or can be installed via prompt)
-
Install this extension from the VS Code Marketplace
-
The extension will automatically find mtlog-analyzer if it's installed. If not found, you'll be prompted to install it with one click.
The extension searches for mtlog-analyzer in the following locations (in order):
- Configured path in settings
- System PATH
- Go binary locations:
$GOBIN$GOPATH/bin~/go/bin(default Go install location)- Platform-specific locations (e.g.,
/usr/local/go/binon macOS)
| Setting | Description | Default |
|---|---|---|
mtlog.analyzerPath |
Path to mtlog-analyzer executable | mtlog-analyzer |
mtlog.analyzerFlags |
Additional analyzer flags | [] |
Example configuration:
{
"mtlog.analyzerPath": "C:\\Go\\bin\\mtlog-analyzer.exe",
"mtlog.analyzerFlags": ["-strict"]
}The extension runs mtlog-analyzer when you save Go files, parsing the output and displaying diagnostics directly in the editor. It's designed to work alongside gopls without interference.
If the extension can't find mtlog-analyzer:
- Automatic Installation: Click "Install" when prompted by the extension
- Manual Installation: Run
go install github.com/willibrandon/mtlog/cmd/mtlog-analyzer@latest - PATH Issues:
- On macOS: If VS Code is launched from Dock/Spotlight, it may not inherit your shell PATH
- Solution: Launch VS Code from terminal with
code .or restart VS Code after installation
- Custom Location: Specify the full path in settings:
{ "mtlog.analyzerPath": "/full/path/to/mtlog-analyzer" }
- Check Output panel (View → Output → mtlog-analyzer) for errors
- Verify the analyzer works:
mtlog-analyzer your-file.go - Ensure you're saving the file (analysis runs on save)