Documentation
Console Logging
Log messages, warnings, and errors to the server console for debugging and monitoring.
Console Logging
PixelScript provides standard console logging functions to output messages to the server console. Use these for debugging, monitoring script execution, and tracking errors.
Logging Messages
Log information with console.log(... messages)
Outputs informational messages to the console.
console.log("Server initialized"); console.log("Player count:", Bukkit.getOnlinePlayers().size()); console.log("Loading features...");
Log warnings with console.warn(...messages)
Outputs warning messages to the console, typically highlighted in yellow.
console.warn("Database connection is slow"); console.warn("Player", playerName, "attempted unauthorized action");
Log errors with console.error(...messages)
Outputs error messages to the console, typically highlighted in red.
console.error("Failed to load configuration file"); console.error("Critical error in payment system");
Convenience Aliases
PixelScript also provides shorter aliases for common logging operations:
log(... messages) - Alias for console.log()
log("This is easier to type"); log("Player joined:", player.getName());
warn(...messages) - Alias for console.warn()
warn("This operation may take a while");
error(...messages) - Alias for console.error()
error("Something went wrong!");
Logging Multiple Values
All logging functions accept multiple arguments:
const playerName = "Notch"; const coins = 150; log("Player:", playerName, "has", coins, "coins"); // Output: Player: Notch has 150 coins console.log("X:", location.getX(), "Y:", location.getY(), "Z:", location.getZ()); // Output: X: 100. 5 Y: 64.0 Z: -250.3
Logging Objects
You can log JavaScript objects directly, though they may not always format nicely.
For better object inspection, use JSON.stringify():
const playerData = { name: "Notch", level: 50, coins: 1000 }; // Basic object logging log(playerData); // Output: [object Object] // Better formatting with JSON.stringify log(JSON. stringify(playerData)); // Output: {"name":"Notch","level":50,"coins":1000}
Practical Examples
Debugging event handlers
registerListener($. PlayerJoinEvent, (event) => { const player = event.getPlayer(); log("Player joined:", player.getName()); log("Player UUID:", player.getUniqueId().toString()); log("First join:", ! player.hasPlayedBefore()); });
Tracking command execution
registerCommand('teleport', (sender, args) => { log("Teleport command executed by:", sender.getName()); log("Arguments:", args); if (args.length < 3) { error("Invalid teleport arguments"); return; } log("Teleporting to:", args[0], args[1], args[2]); });
Monitoring script lifecycle
log("Economy module loading..."); // Setup code here log("Economy module loaded successfully"); Script.addUnloadCallback(() => { log("Economy module unloading..."); });
Error handling with context
Scheduler.runAsync(() => { try { const response = fetch("https://api.example.com/data"); if (response.isSuccessful()) { log("API request successful"); const data = response.asObject(); log("Received data:", JSON.stringify(data)); } else { warn("API request failed with status:", response.getStatusCode()); } } catch (e) { error("Exception during API call:", e. message); } });
Make HTTP requests to external APIs and web services with built-in error handling and JSON parsing.
Parse and serialize JSON data for storage, API communication, and data interchange.