Skip to content

Commit b49f666

Browse files
authored
Merge pull request #232826 from eric-urban/eur/javascript-logging
javascript logging etc
2 parents fccf8ca + 6ff3e79 commit b49f666

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

articles/cognitive-services/Speech-Service/how-to-use-logging.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,45 @@ Logging to file is an optional feature for the Speech SDK. During development lo
1818

1919
## Sample
2020

21-
The log file name is specified on a configuration object. Taking the `SpeechConfig` as an example and assuming that you have created an instance called `config`:
21+
The log file name is specified on a configuration object. Taking the `SpeechConfig` as an example and assuming that you've created an instance called `speechConfig`:
2222

2323
```csharp
24-
config.SetProperty(PropertyId.Speech_LogFilename, "LogfilePathAndName");
24+
speechConfig.SetProperty(PropertyId.Speech_LogFilename, "LogfilePathAndName");
2525
```
2626

2727
```java
28-
config.setProperty(PropertyId.Speech_LogFilename, "LogfilePathAndName");
28+
speechConfig.setProperty(PropertyId.Speech_LogFilename, "LogfilePathAndName");
2929
```
3030

3131
```C++
32-
config->SetProperty(PropertyId::Speech_LogFilename, "LogfilePathAndName");
32+
speechConfig->SetProperty(PropertyId::Speech_LogFilename, "LogfilePathAndName");
3333
```
3434
3535
```Python
36-
config.set_property(speechsdk.PropertyId.Speech_LogFilename, "LogfilePathAndName")
36+
speech_config.set_property(speechsdk.PropertyId.Speech_LogFilename, "LogfilePathAndName")
3737
```
3838

3939
```objc
40-
[config setPropertyTo:@"LogfilePathAndName" byId:SPXSpeechLogFilename];
40+
[speechConfig setPropertyTo:@"LogfilePathAndName" byId:SPXSpeechLogFilename];
4141
```
4242
4343
```go
4444
import ("github.com/Microsoft/cognitive-services-speech-sdk-go/common")
4545
46-
config.SetProperty(common.SpeechLogFilename, "LogfilePathAndName")
46+
speechConfig.SetProperty(common.SpeechLogFilename, "LogfilePathAndName")
4747
```
4848

49-
You can create a recognizer from the config object. This will enable logging for all recognizers.
49+
You can create a recognizer from the configuration object. This will enable logging for all recognizers.
5050

5151
> [!NOTE]
52-
> If you create a `SpeechSynthesizer` from the config object, it will not enable logging. If logging is enabled though, you will also receive diagnostics from the `SpeechSynthesizer`.
52+
> If you create a `SpeechSynthesizer` from the configuration object, it will not enable logging. If logging is enabled though, you will also receive diagnostics from the `SpeechSynthesizer`.
53+
54+
JavaScript is an exception where the logging is enabled via SDK diagnostics as shown in the following code snippet:
55+
56+
```javascript
57+
sdk.Diagnostics.SetLoggingLevel(sdk.LogLevel.Debug);
58+
sdk.Diagnostics.SetLogOutputPath("LogfilePathAndName");
59+
```
5360

5461
## Create a log file on different platforms
5562

@@ -62,15 +69,15 @@ UWP applications need to be places log files in one of the application data loca
6269
```csharp
6370
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
6471
StorageFile logFile = await storageFolder.CreateFileAsync("logfile.txt", CreationCollisionOption.ReplaceExisting);
65-
config.SetProperty(PropertyId.Speech_LogFilename, logFile.Path);
72+
speechConfig.SetProperty(PropertyId.Speech_LogFilename, logFile.Path);
6673
```
6774

6875
Within a Unity UWP application, a log file can be created using the application persistent data path folder as follows:
6976

7077
```csharp
7178
#if ENABLE_WINMD_SUPPORT
7279
string logFile = Application.persistentDataPath + "/logFile.txt";
73-
config.SetProperty(PropertyId.Speech_LogFilename, logFile);
80+
speechConfig.SetProperty(PropertyId.Speech_LogFilename, logFile);
7481
#endif
7582
```
7683
For more about file access permissions in UWP applications, see [File access permissions](/windows/uwp/files/file-access-permissions).
@@ -82,7 +89,7 @@ You can save a log file to either internal storage, external storage, or the cac
8289
```java
8390
File dir = context.getExternalFilesDir(null);
8491
File logFile = new File(dir, "logfile.txt");
85-
config.setProperty(PropertyId.Speech_LogFilename, logFile.getAbsolutePath());
92+
speechConfig.setProperty(PropertyId.Speech_LogFilename, logFile.getAbsolutePath());
8693
```
8794

8895
The code above will save a log file to the external storage in the root of an application-specific directory. A user can access the file with the file manager (usually in `Android/data/ApplicationName/logfile.txt`). The file will be deleted when the application is uninstalled.
@@ -101,7 +108,7 @@ Within a Unity Android application, the log file can be created using the applic
101108

102109
```csharp
103110
string logFile = Application.persistentDataPath + "/logFile.txt";
104-
config.SetProperty(PropertyId.Speech_LogFilename, logFile);
111+
speechConfig.SetProperty(PropertyId.Speech_LogFilename, logFile);
105112
```
106113
In addition, you need to also set write permission in your Unity Player settings for Android to "External (SDCard)". The log will be written
107114
to a directory you can get using a tool such as AndroidStudio Device File Explorer. The exact directory path may vary between Android devices,
@@ -131,7 +138,7 @@ To access a created file, add the below properties to the `Info.plist` property
131138
<true/>
132139
```
133140

134-
If you are using Swift on iOS, please use the following code snippet to enable logs:
141+
If you're using Swift on iOS, please use the following code snippet to enable logs:
135142
```swift
136143
let documentsDirectoryPathString = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
137144
let documentsDirectoryPath = NSURL(string: documentsDirectoryPathString)!
@@ -145,9 +152,9 @@ More about iOS File System is available [here](https://developer.apple.com/libra
145152

146153
Although a log file output path is specified as a configuration property into a `SpeechRecognizer` or other SDK object, SDK logging is a singleton, *process-wide* facility with no concept of individual instances. You can think of this as the `SpeechRecognizer` constructor (or similar) implicitly calling a static and internal "Configure Global Logging" routine with the property data available in the corresponding `SpeechConfig`.
147154

148-
This means that you cannot, as an example, configure six parallel recognizers to output simultaneously to six separate files. Instead, the latest recognizer created will configure the global logging instance to output to the file specified in its configuration properties and all SDK logging will be emitted to that file.
155+
This means that you can't, as an example, configure six parallel recognizers to output simultaneously to six separate files. Instead, the latest recognizer created will configure the global logging instance to output to the file specified in its configuration properties and all SDK logging will be emitted to that file.
149156

150-
This also means that the lifetime of the object that configured logging is not tied to the duration of logging. Logging will not stop in response to the release of an SDK object and will continue as long as no new logging configuration is provided. Once started, process-wide logging may be stopped by setting the log file path to an empty string when creating a new object.
157+
This also means that the lifetime of the object that configured logging isn't tied to the duration of logging. Logging will not stop in response to the release of an SDK object and will continue as long as no new logging configuration is provided. Once started, process-wide logging may be stopped by setting the log file path to an empty string when creating a new object.
151158

152159
To reduce potential confusion when configuring logging for multiple instances, it may be useful to abstract control of logging from objects doing real work. An example pair of helper routines:
153160

0 commit comments

Comments
 (0)