Basic Usage
Import and Use
Import the log object from devlog and start using it immediately. The logger automatically detects the calling file and line number.
typescript
import { log } from "@promise-inc/devlog";
// Different log levelslog.info("Application started");log.success("Database connected");log.warn("Cache miss, fetching from API");log.error("Failed to authenticate user");log.debug("Request payload:", { userId: 123 });Log Levels
Devlog provides five log levels, each with distinct visual styling:
- info - General informational messages (blue)
- success - Successful operations (green)
- warn - Warning messages (yellow)
- error - Error messages (red)
- debug - Debug information (magenta)
Output Format
Each log statement displays the file name, line number, timestamp, and message:
typescript
log.info("User logged in");// Output: [app.ts:15] [12:34:56] User logged inLogging Data
You can pass a second parameter to log additional data. This data will be formatted and displayed after the message:
typescript
const user = { id: 1, name: "Alice", email: "alice@example.com" };
log.info("User created", user);// Output:// [UserService.ts:42] [12:34:56] User created// { id: 1, name: "Alice", email: "alice@example.com" }
log.debug("API response", { status: 200, data: [...] });// Output:// [api.ts:89] [12:34:56] API response// { status: 200, data: [...] }The data parameter accepts any type and will be automatically formatted for display. Objects, arrays, and primitive values are all supported.