-
Notifications
You must be signed in to change notification settings - Fork 0
Logging ColorKeywords
The logging system automatically detects log levels from message content using keywords. This allows you to write natural log messages without explicitly specifying severity levels.
RevitDevTool scans your log messages for specific keywords and automatically assigns the appropriate log level with color coding:
| Level | Color | Keywords |
|---|---|---|
| Information | Blue |
info, success, completed, finished, done, started
|
| Warning | Yellow |
warning, warn, caution, deprecated
|
| Error | Red |
error, failed, exception, crash
|
| Critical | Dark Red |
fatal, critical, panic
|
| Debug | Gray |
debug, verbose
|
Add a bracketed prefix to your message for explicit level control:
Trace.WriteLine("[INFO] This will be Information level (blue)");
Trace.WriteLine("[WARN] This will be Warning level (yellow)");
Trace.WriteLine("[ERROR] This will be Error level (red)");
Trace.WriteLine("[FATAL] This will be Critical level (dark red)");
Trace.WriteLine("[DEBUG] This will be Debug level (gray)");
// Also works with Console
Console.WriteLine("[INFO] Console output as Information level");
Debug.WriteLine("[DEBUG] Debug output as Debug level");Supported prefixes:
-
[INFO],[INFORMATION]β Information (blue) -
[WARN],[WARNING]β Warning (yellow) -
[ERROR],[ERR]β Error (red) -
[FATAL],[CRITICAL]β Critical (dark red) -
[DEBUG]β Debug (gray)
If no prefix is found, the system scans the entire message for keywords:
Trace.WriteLine("Operation completed successfully"); // "completed" β Info (blue)
Trace.WriteLine("Warning: Memory usage is high"); // "warning" β Warning (yellow)
Trace.WriteLine("Error occurred during processing"); // "error" β Error (red)
Trace.WriteLine("Fatal crash detected in system"); // "fatal" β Critical (dark red)
Console.WriteLine("Task succeeded without issues"); // "succeeded" β Info (blue)
Debug.WriteLine("This is just a debug message"); // "debug" β Debug (gray)// Using prefixes - most explicit
Trace.WriteLine("[INFO] Application started");
Trace.WriteLine("[WARN] Configuration file not found, using defaults");
Trace.WriteLine("[ERROR] Database connection failed");
Trace.WriteLine("[FATAL] Critical system failure");
// Using keywords - more natural
Trace.WriteLine("Successfully loaded 150 elements"); // β Info
Trace.WriteLine("Warning: High memory usage detected"); // β Warning
Trace.WriteLine("Failed to process element 123456"); // β Error
Trace.WriteLine("Fatal: Cannot initialize Revit API"); // β Critical
// No keywords - defaults to Information
Trace.WriteLine("Processing elements..."); // β Info (default)For pyRevit/RevitPythonShell/Dynamo:
import clr
# For Revit 2025+ (.NET 8):
clr.AddReference("System.Diagnostics.TraceSource")
clr.AddReference("System.Console")
from System.Diagnostics import Trace
from System import Console
# Using prefixes
Trace.WriteLine("[INFO] Python script started")
Trace.WriteLine("[WARN] Element not found")
Trace.WriteLine("[ERROR] Export failed")
# Using keywords
Trace.WriteLine("Successfully created 50 walls") # β Info
Trace.WriteLine("Warning: Door width exceeds limit") # β Warning
Trace.WriteLine("Error: Invalid room boundary") # β Error
# Console output also works
Console.WriteLine("[INFO] Analysis complete")For RevitDevTool Python scripts:
# RevitDevTool automatically captures print() output
print("[INFO] Script started")
print("Successfully created 50 walls") # β Info
print("Warning: Door width exceeds limit") # β Warning
print("Error: Invalid room boundary") # β Error
# No import needed - works out of the box-
info,information -
success,successful,succeeded -
completed,complete -
finished,done -
started,begin,beginning -
loaded,created
-
warning,warn -
caution,careful -
deprecated,obsolete -
high,low(when referring to resources)
-
error,err -
failed,fail,failure exception-
invalid,incorrect -
not found,missing timeout-
crash,crashed
fatalcriticalpanicsevere
debugverbose-
trace(as a noun, not the class name)
- Information: Blue text
- Warning: Yellow text
- Error: Red text
- Critical: Dark red text
- Debug: Gray text
- Information: Light blue text
- Warning: Orange text
- Error: Light red text
- Critical: Bright red text
- Debug: Light gray text
All keyword matching is case-insensitive:
// All of these are detected as Error level:
Trace.WriteLine("ERROR: Failed");
Trace.WriteLine("error: failed");
Trace.WriteLine("Error: Failed");
Trace.WriteLine("An error occurred");When log level is critical, use explicit prefixes:
Trace.WriteLine("[ERROR] Transaction rolled back"); // Clear intentFor user-friendly messages, use natural language:
Trace.WriteLine("Successfully exported 100 families"); // Reads naturallyPrefix for level, keywords for context:
Trace.WriteLine("[WARN] Operation succeeded but with warnings");Don't mix level keywords in one message:
// β Bad - ambiguous
Trace.WriteLine("Error handling succeeded"); // Is this error or success?
// β
Good - clear
Trace.WriteLine("[INFO] Error handling succeeded"); // Explicit prefixNote: Keywords are currently fixed in the codebase. Future versions may support user-customizable keyword sets in settings.
Current keywords are optimized for:
- English language messages
- Common development terminology
- Standard log level conventions
Trace.WriteLine("[INFO] Starting element processing");
Trace.WriteLine("Processing 50 elements...");
foreach (var element in elements)
{
try
{
ProcessElement(element);
Trace.WriteLine($"Successfully processed {element.Id}"); // β Info
}
catch (Exception ex)
{
Trace.WriteLine($"Failed to process {element.Id}: {ex.Message}"); // β Error
}
}
Trace.WriteLine("Processing completed with 3 warnings"); // β Warningfrom System.Diagnostics import Trace
Trace.WriteLine("[INFO] Wall analysis script started")
walls = collect_walls()
Trace.WriteLine(f"Successfully found {len(walls)} walls") # β Info
for wall in walls:
if wall.Width < 0.1:
Trace.WriteLine(f"Warning: Wall {wall.Id} is too thin") # β Warning
if not wall.IsValidObject:
Trace.WriteLine(f"Error: Invalid wall {wall.Id}") # β Error
Trace.WriteLine("Analysis completed") # β Info- Logging Overview - Main logging documentation
- Python Stack Traces - Enhanced Python error formatting