@mastra/core
Version:
186 lines (185 loc) • 4.82 kB
JavaScript
import { Transform } from "stream";
//#region ../_internal-core/dist/logger/index.js
const RegisteredLogger = {
AGENT: "AGENT",
OBSERVABILITY: "OBSERVABILITY",
AUTH: "AUTH",
BROWSER: "BROWSER",
NETWORK: "NETWORK",
WORKFLOW: "WORKFLOW",
LLM: "LLM",
TTS: "TTS",
VOICE: "VOICE",
VECTOR: "VECTOR",
BUNDLER: "BUNDLER",
DEPLOYER: "DEPLOYER",
MEMORY: "MEMORY",
STORAGE: "STORAGE",
EMBEDDINGS: "EMBEDDINGS",
MCP_SERVER: "MCP_SERVER",
SERVER_CACHE: "SERVER_CACHE",
SERVER: "SERVER",
WORKSPACE: "WORKSPACE",
CHANNEL: "CHANNEL"
};
const LogLevel = {
DEBUG: "debug",
INFO: "info",
WARN: "warn",
ERROR: "error",
NONE: "silent"
};
var LoggerTransport = class extends Transform {
constructor(opts = {}) {
super({
...opts,
objectMode: true
});
}
async listLogsByRunId(_args) {
return {
logs: [],
total: 0,
page: _args?.page ?? 1,
perPage: _args?.perPage ?? 100,
hasMore: false
};
}
async listLogs(_args) {
return {
logs: [],
total: 0,
page: _args?.page ?? 1,
perPage: _args?.perPage ?? 100,
hasMore: false
};
}
};
const createCustomTransport = (stream, listLogs, listLogsByRunId) => {
let transport = stream;
if (listLogs) transport.listLogs = listLogs;
if (listLogsByRunId) transport.listLogsByRunId = listLogsByRunId;
return transport;
};
var MastraLogger = class {
name;
level;
transports;
constructor(options = {}) {
this.name = options.name || "Mastra";
this.level = options.level || LogLevel.ERROR;
this.transports = new Map(Object.entries(options.transports || {}));
}
getTransports() {
return this.transports;
}
trackException(_error, _metadata) {}
async listLogs(transportId, params) {
if (!transportId || !this.transports.has(transportId)) return {
logs: [],
total: 0,
page: params?.page ?? 1,
perPage: params?.perPage ?? 100,
hasMore: false
};
return this.transports.get(transportId).listLogs?.(params) ?? {
logs: [],
total: 0,
page: params?.page ?? 1,
perPage: params?.perPage ?? 100,
hasMore: false
};
}
async listLogsByRunId({ transportId, runId, fromDate, toDate, logLevel, filters, page, perPage }) {
if (!transportId || !this.transports.has(transportId) || !runId) return {
logs: [],
total: 0,
page: page ?? 1,
perPage: perPage ?? 100,
hasMore: false
};
return this.transports.get(transportId).listLogsByRunId?.({
runId,
fromDate,
toDate,
logLevel,
filters,
page,
perPage
}) ?? {
logs: [],
total: 0,
page: page ?? 1,
perPage: perPage ?? 100,
hasMore: false
};
}
};
var ConsoleLogger = class ConsoleLogger extends MastraLogger {
component;
filter;
constructor(options = {}) {
super(options);
this.component = options.component;
this.filter = options.filter;
}
child(componentOrBindings) {
const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
return new ConsoleLogger({
name: this.name,
level: this.level,
component,
filter: this.filter
});
}
shouldLog(level, message, args) {
if (!this.filter) return true;
try {
return this.filter({
component: this.component,
level,
message,
args
});
} catch (e) {
console.error(`[Logger] Filter error for component=${this.component} level=${level}:`, e);
return true;
}
}
prefix() {
return this.component ? `[${this.component}] ` : "";
}
debug(message, ...args) {
if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) console.info(`${this.prefix()}${message}`, ...args);
}
info(message, ...args) {
if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) console.info(`${this.prefix()}${message}`, ...args);
}
warn(message, ...args) {
if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) console.warn(`${this.prefix()}${message}`, ...args);
}
error(message, ...args) {
if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) console.error(`${this.prefix()}${message}`, ...args);
}
async listLogs(_transportId, _params) {
return {
logs: [],
total: 0,
page: _params?.page ?? 1,
perPage: _params?.perPage ?? 100,
hasMore: false
};
}
async listLogsByRunId(_args) {
return {
logs: [],
total: 0,
page: _args.page ?? 1,
perPage: _args.perPage ?? 100,
hasMore: false
};
}
};
//#endregion
export { RegisteredLogger as a, MastraLogger as i, LogLevel as n, createCustomTransport as o, LoggerTransport as r, ConsoleLogger as t };
//# sourceMappingURL=logger-B_aQzjbm.js.map