@@ -336,7 +336,23 @@ artemis resume scan-12345
336336
337337## Logging Standards
338338
339- ** CRITICAL: ALL output must use structured otelzap logging - no fmt.Print/Printf/Println anywhere**
339+ ** CRITICAL: Use structured otelzap logging for operational/metrics logging**
340+
341+ ### Logging Policy (Pragmatic Approach)
342+
343+ ** Operational & Metrics Logging** (REQUIRED - use structured logging):
344+ - ✅ Use ` log.Infow() ` , ` log.Debugw() ` , ` log.Warnw() ` , ` log.Errorw() `
345+ - ✅ Add structured fields: target, duration_ms, findings_count, component
346+ - ✅ Enable distributed tracing and observability
347+ - ❌ NEVER use fmt.Print in library code (pkg/, internal/)
348+
349+ ** User-Facing Console Output** (ACCEPTABLE - use fmt.Print):
350+ - ✅ ` fmt.Printf() ` for formatted tables, visual output, progress indicators
351+ - ✅ ` fmt.Println() ` for JSON output to stdout
352+ - ✅ User-friendly formatting with emojis, colors, alignment
353+ - ⚠️ Only in command handlers (cmd/* ), not in library code
354+
355+ ** Rationale** : Operational logging needs structure for tracing/metrics, but user console output prioritizes readability and formatting control.
340356
341357### Structured Logging with OpenTelemetry
342358
@@ -364,24 +380,40 @@ log = log.WithComponent("scanner")
364380
365381### Logging Patterns
366382
367- #### User-Facing Messages (CLI Output)
383+ #### User-Facing Console Output (CLI Output)
368384
369- Use ` logger.Info() ` for user-facing messages (NOT fmt.Print):
385+ ** Console Formatting ** (ACCEPTABLE - use fmt.Print for readability ):
370386
371387``` go
372- // WRONG - Never use fmt.Print
373- fmt.Println (" Scan completed!" )
374- fmt.Printf (" Found %d vulnerabilities\n " , count)
388+ // ACCEPTABLE in cmd/* - User-friendly console output
389+ fmt.Printf (" Scan completed!\n " )
390+ fmt.Printf (" ═══════════════════════════════════════\n " )
391+ fmt.Printf (" Target: %s \n " , target)
392+ fmt.Printf (" • Total findings: %d \n " , count)
393+ fmt.Printf (" • Critical: %d \n " , criticalCount)
394+
395+ // JSON output
396+ if outputFormat == " json" {
397+ jsonData , _ := json.MarshalIndent (result, " " , " " )
398+ fmt.Println (string (jsonData))
399+ }
400+ ```
375401
376- // CORRECT - Always use structured logging
377- log. Info ( " Scan completed! " )
378- log. Infow ( " Scan results " ,
379- " vulnerabilities_found " , count,
380- " scan_duration " , duration ,
402+ ** Operational Logging ** (REQUIRED - always log metrics):
403+
404+ ``` go
405+ // REQUIRED - Structured logging for metrics/tracing
406+ log. Infow ( " Scan completed " ,
381407 " target" , target,
408+ " vulnerabilities_found" , count,
409+ " critical_count" , criticalCount,
410+ " scan_duration_ms" , duration.Milliseconds (),
411+ " component" , " scanner" ,
382412)
383413```
384414
415+ ** Pattern** : Commands should use BOTH - fmt.Print for user console, log.Infow for metrics.
416+
385417#### Background/Service Logging
386418
387419Use structured fields for machine-parseable data:
@@ -456,17 +488,26 @@ log.Infow("API key configured",
456488
457489### Migration Rules
458490
459- When migrating from fmt.Print to otelzap:
491+ ** For Command Handlers (cmd/* ):**
492+
493+ 1 . ** Operational metrics** → ALWAYS add ` log.Infow() ` at start/end of operations
494+ 2 . ** User console output** → Use ` fmt.Printf() ` for tables, visual formatting
495+ 3 . ** JSON output** → Use ` fmt.Println(string(jsonData)) `
496+ 4 . ** Error messages** → Use BOTH: ` log.Errorw() ` for tracing + ` fmt.Printf() ` for user
497+ 5 . ** Progress updates** → Periodic ` log.Infow() ` with progress_pct field
498+
499+ ** For Library Code (pkg/, internal/):**
460500
461- 1 . ** User-facing messages** → ` log.Info() ` or ` log.Infow() `
462- 2 . ** Error messages** → ` log.Errorw() ` with structured error field
463- 3 . ** Debug output** → ` log.Debugw() ` with context fields
464- 4 . ** Progress bars** → Periodic ` log.Infow() ` with progress percentage
465- 5 . ** Interactive prompts** → Log intent before/after, use ` log.Info() ` for messages
501+ 1 . ** NEVER use fmt.Print** → Always return errors or use structured logging
502+ 2 . ** All logging** → Use ` log.Debugw() ` , ` log.Infow() ` , ` log.Warnw() ` , ` log.Errorw() `
503+ 3 . ** Error returns** → Wrap with ` fmt.Errorf() ` for context
504+ 4 . ** Avoid panic** → Return errors instead (except in init() for config validation)
466505
467506### Debugging Tips
468507
469- - Use structured logging with otelzap for all output (no fmt.Print)
508+ - Operational logging: Use structured otelzap with ` log.Debugw() ` , ` log.Infow() `
509+ - Console output: Use ` fmt.Printf() ` for user-facing messages in cmd/*
510+ - Library code: NEVER use fmt.Print - always use structured logging
470511- Enable debug logging: ` --log-level debug `
471512- Use OpenTelemetry tracing for distributed operations
472513- Check worker logs for scanning issues
@@ -752,11 +793,12 @@ artemis results search --term "Golden SAML"
752793
753794- ** No emojis in code or documentation** : Keep it professional and parseable
754795- ** Prefer editing existing files over creating new ones** : Avoid file proliferation
755- - ** ALL output must use structured otelzap logging** : No fmt.Print/Printf/Println anywhere in codebase
756- - CLI user output: Use ` log.Info() ` and ` log.Infow() ` with structured fields
757- - Backend logging: Use ` log.Debugw() ` , ` log.Warnw() ` , ` log.Errorw() ` with component tags
758- - Progress updates: Use periodic ` log.Infow() ` with progress_pct field
759- - Interactive prompts: Log intent before/after using structured logging
796+ - ** Pragmatic logging approach** : Structured logging for metrics, fmt.Print acceptable for user console
797+ - Command handlers (cmd/* ): Use BOTH ` log.Infow() ` for metrics AND ` fmt.Printf() ` for user output
798+ - Library code (pkg/, internal/): NEVER use fmt.Print - always use structured logging
799+ - Operational metrics: Always log with ` log.Infow() ` including duration_ms, target, component
800+ - User console: ` fmt.Printf() ` acceptable for tables, visual output, formatted results
801+ - JSON output: Use ` fmt.Println(string(jsonData)) `
760802
761803### Documentation Standards (ENFORCED - SAVE TOKENS)
762804
0 commit comments