@langchain/langgraph-sdk
Version:
Client library for interacting with the LangGraph API
1 lines • 2.3 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/logging/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\ninterface LeveledLogMethod {\n (message: string, ...meta: any[]): Logger;\n (message: any): Logger;\n (infoObject: object): Logger;\n}\n\ninterface Logger {\n error: LeveledLogMethod;\n warn: LeveledLogMethod;\n help: LeveledLogMethod;\n data: LeveledLogMethod;\n info: LeveledLogMethod;\n debug: LeveledLogMethod;\n prompt: LeveledLogMethod;\n http: LeveledLogMethod;\n verbose: LeveledLogMethod;\n input: LeveledLogMethod;\n silly: LeveledLogMethod;\n}\n\nconst GLOBAL_LOGGER = Symbol.for(\"langgraph.api.sdk-logger\");\ntype GLOBAL_LOGGER = typeof GLOBAL_LOGGER;\n\n/**\n * Retrieves the global logger instance for LangGraph Platform.\n *\n * The logger provides structured logging capabilities with\n * various log levels (error, warn, info, debug, etc.) and extra metadata such as node name etc.\n *\n * @returns {Logger} The global logger instance with leveled logging methods\n *\n * @throws {Error} When the logger is not available in the current environment\n *\n * @example\n * ```typescript\n * // Safe usage with fallback\n * const logger = getLogger();\n * logger.info(\"This will only work in LangGraph Platform environment\");\n * ```\n *\n * @remarks\n * This method is designed to work specifically within the LangGraph Platform\n * environment where a global logger is automatically registered. If you're\n * developing locally or in an environment where LangGraph Platform is not\n * available, this function will throw an error.\n */\nexport const getLogger = (): Logger => {\n const maybeGlobal = globalThis as unknown as { [GLOBAL_LOGGER]: Logger };\n if (GLOBAL_LOGGER in maybeGlobal) return maybeGlobal[GLOBAL_LOGGER];\n\n throw new Error(\n \"Logger not available in current environment. \" +\n \"This method requires LangGraph Platform environment where a global logger is automatically registered. \" +\n \"If you're developing locally, consider using `console.log` or a local logging library instead.\"\n );\n};\n"],"mappings":";;AAqBA,MAAM,gBAAgB,OAAO,IAAI,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;AA0B5D,MAAa,kBAA0B;CACrC,MAAM,cAAc;AACpB,KAAI,iBAAiB,YAAa,QAAO,YAAY;AAErD,OAAM,IAAI,MACR,qPAGD"}