forked from dotnet/vscode-dotnet-runtime
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDebugging.ts
50 lines (42 loc) · 1.6 KB
/
Debugging.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*---------------------------------------------------------------------------------------------
* Licensed to the .NET Foundation under one or more agreements.
* The .NET Foundation licenses this file to you under the MIT license.
*--------------------------------------------------------------------------------------------*/
import path = require('path');
import { IEventStream } from '../EventStream/EventStream';
import {
DotnetDebuggingMessage,
} from '../EventStream/EventStreamEvents';
import * as fs from 'fs';
/**
* A simple wrapper around console logging that can disable / enable all debugging or logging messages.
* Use EventStreamEvents for user facing debugging logs.
*/
export class Debugging
{
static logFile = path.join(__dirname, 'VsDotnetDebuggingLog.txt');
static debugOn = false;
static logToTerminal = true;
static logToFile = true;
public static log(message : string, eventStream : IEventStream | null = null)
{
if(Debugging.debugOn)
{
if(Debugging.logToTerminal)
{
eventStream?.post(new DotnetDebuggingMessage(message));
}
console.log(message);
if(Debugging.logFile)
{
console.log(`Writing to ${Debugging.logFile}`);
if(Debugging.logToTerminal)
{
eventStream?.post(new DotnetDebuggingMessage(`Writing to ${Debugging.logFile}`));
}
const file = fs.createWriteStream(Debugging.logFile, { flags: 'a+' });
file.write(message);
}
}
}
};