You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Azure Communication Services中AzureLogger的正确使用示例(文档示例不完整引发报错)

Fixing "Uncaught TypeError: this._azureLogger.info is not a function" with Azure Logger in Azure Communication Services

I’ve run into this exact snag before, so let’s break down what’s going wrong and fix it with working, tested code examples.

What’s Causing the Error?

Your code mixes ES module syntax (import) with CommonJS (require), and you’re passing the entire @azure/logger module to CallClient instead of the configured AzureLogger instance. The error pops up because the module object doesn’t have the info method that Azure Communication Services (ACS) expects from a logger.

If you’re using ES modules (standard for most modern JavaScript/TypeScript setups), here’s a complete, functional setup:

import { AzureLogger } from '@azure/logger';
import { CallClient } from '@azure/communication-calling';

// Step 1: Set your desired log level (optional but critical for debugging)
AzureLogger.setLogLevel('verbose');

// Step 2: Customize log output (optional—skip this to use default console behavior)
AzureLogger.verbose = (...args) => console.log('[VERBOSE]', ...args);
AzureLogger.info = (...args) => console.log('[INFO]', ...args);
AzureLogger.warning = (...args) => console.warn('[WARNING]', ...args);
AzureLogger.error = (...args) => console.error('[ERROR]', ...args);

// Step 3: Initialize CallClient with the configured AzureLogger
const callClient = new CallClient({ logger: AzureLogger });

Working CommonJS Example

If your project uses CommonJS (Node.js without ES module support), use this instead:

const { AzureLogger } = require('@azure/logger');
const { CallClient } = require('@azure/communication-calling');

// Set log level
AzureLogger.setLogLevel('verbose');

// Customize log output (optional)
AzureLogger.verbose = (...args) => console.log('[VERBOSE]', ...args);
AzureLogger.info = (...args) => console.log('[INFO]', ...args);
AzureLogger.warning = (...args) => console.warn('[WARNING]', ...args);
AzureLogger.error = (...args) => console.error('[ERROR]', ...args);

// Initialize CallClient
const callClient = new CallClient({ logger: AzureLogger });

Key Rules to Avoid This Error Again

  • Stick to one module system: Don’t mix import and require in the same file—this creates inconsistent object references that break the logger.
  • Pass AzureLogger, not the whole module: The CallClient expects an object with info, verbose, warning, and error methods. The AzureLogger you import/require is exactly this object.
  • Double-check dependencies: Your @azure/logger@1.0.1 version works perfectly with this syntax. If you upgrade later, just confirm the logger’s API remains consistent (it’s been stable for years).

Why the Official Example Works (and Yours Didn’t)

The official example directly modifies the static methods of the AzureLogger object and passes it to CallClient—that’s correct. Your mistake was importing AzureLogger then requiring the entire module and passing that module object instead of the actual AzureLogger instance from your import.

内容的提问来源于stack exchange,提问作者Scott

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 07:32:42