Search code examples
javascriptazureazure-communication-services

How to use AzureLogger in Azure Communication Services


The example code snippet @ https://learn.microsoft.com/en-us/azure/communication-services/concepts/troubleshooting-info?tabs=csharp%2Cjavascript%2Cdotnet is incomplete. I'm not familiar enough with JavaScript modules to get this working. I've added the module to package.json ("@azure/logger": "1.0.1"). When I execute my code example, I receive the following exception:

Uncaught TypeError: this._azureLogger.info is not a function

documentation example:

import { AzureLogger } from '@azure/logger';
AzureLogger.verbose = (...args) => { console.info(...args); } 
AzureLogger.info = (...args) => { console.info(...args); } 
AzureLogger.warning = (...args) => { console.info(...args); } 
AzureLogger.error = (...args) => { console.info(...args); } 
callClient = new CallClient({logger: AzureLogger});

my failed attempt:

import { AzureLogger } from '@azure/logger';
const logger = require('@azure/logger');
logger.setLogLevel('verbose');
const callClientOptions: CallClientOptions = { logger };

Can anyone share a working example of this code?


Solution

  • Scott, thank you for raising this up. The product group is working on updating the document you linked for a long term fix. In regards to a short term fix to get you unblocked, can you please try the below sample?

    We apologize for the inconvenience that this caused and look forward to your verification of the below sample.

    import { createClientLogger, setLogLevel } from '@azure/logger';
    
                const logger = createClientLogger('ACS');
                setLogLevel('verbose');
                logger.verbose.log = (...args) => { console.log(...args); };
                logger.info.log = (...args) => { console.info(...args) ; };
                logger.warning.log = (...args) => { console.warn(...args); };
                logger.error.log = (...args) => { console.error(...args); };
                const options = { logger: logger };
                this.callClient = new CallClient(options);