Log Viewing
Cloud Development provides a flexible log printing feature to help developers with debugging and monitoring.
SDK Import and Initialization
Install SDK
npm install @cloudbase/node-sdk
Initialize the SDK
const cloudbase = require("@cloudbase/node-sdk");
const app = cloudbase.init({
env: 'your-env-id'
});
Environment Note
- The examples in this document are based on the Node.js environment.
- In cloud functions, the SDK automatically obtains the environment configuration.
- During local development, manual initialization of the environment ID may be required.
Logging Methods in Detail
log - General Log
Used to log general debugging information and program execution status.
SDK Method
// Basic Usage
app.logger().log({
name: "this is a log"
});
// Structured logging
app.logger().log({
action: "user_login",
userId: "12345",
timestamp: Date.now(),
success: true
});
Console Method
// Simple text
console.log("this is a log");
// Object output
console.log("User login", {
userId: "12345",
success: true
});

info - Information Log
Used to record important business information and system status.
SDK Method
// Business information logging
app.logger().info({
event: "order_created",
orderId: "ORD123456",
userId: "USER789",
amount: 99.99
});
Console Method
console.info("Order created successfully", {
orderId: "ORD123456"
});
warn - Warning Log
Used to log potential issues and abnormal situations that require attention.
SDK Method
// Performance Warning
app.logger().warn({
type: "performance_warning",
executionTime: 5000,
threshold: 3000,
message: "Function execution time exceeds the threshold"
});
Console Method
console.warn("API call frequency is too high", {
userId: "USER123",
callCount: 100
});
error - Error Log
Used to log system errors and exceptions for troubleshooting purposes.
SDK Method
// Error Logging
app.logger().error({
errorType: "database_connection_failed",
errorMessage: errorMessage: "Database connection timed out",
errorCode: "DB_TIMEOUT",
userId: "USER123",
retryCount: 3
});
Console Method
// Simple error logging
console.error("Database connection failed");
// Error object logging
try {
//Business logic.
} catch (error) {
console.error("Processing failed:", error.message);
}