| title | Logging Guide |
|---|---|
| description | Working with logs in Coreness. Log structure, log level configuration, Docker logs and debugging. |
| keywords | coreness logging, logs, debugging, docker logs, log levels |
The logging system uses named loggers with color highlighting by patterns. Each module gets its own named logger through the logger utility.
- Named loggers for each module
- Color highlighting by patterns (console)
- File logging (
logs/core.log) - Log file rotation
- Smart formatting with colors
Purpose: Brief and essential only about current function. Don't describe functionality "inside".
Examples:
[Tenant-137] Parsing scenarios...[Tenant-1] [Bot-1] Bot updatedSynchronizing {X} scenario groups...
Rules:
- ✅ Brief and concise
- ✅ Only about current function
- ✅ Each function is self-sufficient in logging
- ❌ Don't describe what happens inside other functions
Purpose: Requires attention but not critical.
Examples:
- GitHub update error but continue working
- Skip group without name
- Missing token, polling not started
Rules:
- Use when process can continue
- Specify reason and action
Purpose: Critical — process operation disrupted.
Examples:
[Tenant-137] Scenario parsing error: ...Scenario synchronization error: ...- Failed to create/update bot
Rules:
- Write on real errors
- Specify error reason
Purpose: Used only when investigating errors and issues.
Rules:
- ❌ Not used in production code
- ✅ Only by user request for debugging
System automatically highlights patterns in logs with colors. Available highlighting types:
Purpose: Context — entity IDs, modules, services.
Examples:
[Tenant-137]— tenant ID[Bot-1]— bot ID[Queue-action]— queue name[Service-name]— service name[Module-name]— module name
Rules:
-
Hierarchy: Tenant first, then Bot (if present)
# ✅ Correct self.logger.info(f"[Tenant-{tenant_id}] [Bot-{bot_id}] Bot updated") # ❌ Incorrect self.logger.info(f"[Bot-{bot_id}] [Tenant-{tenant_id}] Bot updated")
-
Format:
[Entity-ID]or[Entity-name][Tenant-137] # Entity ID [Queue-critical] # Entity name [Service-bot_hub] # Service name
-
Multiple contexts: Separate with spaces
[Tenant-1] [Bot-2] Command synchronization [Queue-system] Processing task
Purpose: Statuses, states, additional information.
Examples:
(error)— error status(warning)— warning(active)— activity state(3 groups)— group count
Rules:
self.logger.info(f"[Tenant-137] Synchronization (3 groups)")
self.logger.warning(f"[Bot-1] Missing token (polling not started)")Purpose: Data, configuration, values.
Examples:
{config}— configuration{tenant_id: 137}— data{status: active}— values
Rules:
# Usually used in placeholders
self.logger.info(f"Loading {count} scenarios")Purpose: HTTP status codes.
Examples:
HTTP 200— successHTTP 404— not foundHTTP 500— server error
| Pattern | Color | Purpose | Example |
|---|---|---|---|
[Entity-ID] |
Cyan | Context (Tenant, Bot, Service) | [Tenant-137] [Bot-1] |
(status) |
Yellow | Statuses, states | (active), (error) |
{data} |
Green | Data, values | {count}, {config} |
HTTP XXX |
Magenta | HTTP codes | HTTP 200, HTTP 404 |
- Use built-in logger color highlighting (automatic)
- Colors applied to logging levels
- Use patterns like
[Entity-ID]for structuring - Helps in log searching and filtering
- ❌ Don't use emojis in logs
- Have color highlighting and patterns
# ✅ Good: brief, about current function
self.logger.info(f"[Tenant-{tenant_id}] Parsing scenarios...")
# ✅ Good: process start and end
self.logger.info(f"[Tenant-{tenant_id}] Updating data from GitHub...")
# ... process ...
self.logger.info(f"[Tenant-{tenant_id}] GitHub data updated")
# ✅ Good: with count specified
self.logger.info(f"[Tenant-{tenant_id}] Synchronizing {groups_count} scenario groups...")
# ✅ Good: error with description
self.logger.error(f"[Tenant-{tenant_id}] Scenario synchronization error: {error}")
# ❌ Bad: too many internal process details
self.logger.info(f"[Tenant-{tenant_id}] Starting scenario parsing, checking files, reading configuration...")
# ❌ Bad: emojis
self.logger.info(f"✅ [Tenant-{tenant_id}] Scenarios successfully synchronized")- Conciseness: Only essentials, no excessive details
- Self-sufficiency: Each function logs its own work
- Hierarchy: Tenant first, then Bot/other entities
- No emojis: Use colors and patterns
- DEBUG: Only by request, not in prod