
- ~Add `winston` dependency (MIT license) to handle logging setup~ - Have an `LogOutputChannel` to log user facing information, errors, warnings - Write a debug session logs under the provided `logUri` to capture further diagnostics when the `lldb-dap.captureSessionLogs` setting is enabled. *Note* the `lldb-dap.log-path` setting takes precedence when set Issue: #146880 --------- Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import * as path from "path";
|
|
import * as vscode from "vscode";
|
|
|
|
/**
|
|
* Formats the given date as a string in the form "YYYYMMddTHHMMSS".
|
|
*
|
|
* @param date The date to format as a string.
|
|
* @returns The formatted date.
|
|
*/
|
|
function formatDate(date: Date): string {
|
|
const year = date.getFullYear().toString().padStart(4, "0");
|
|
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
|
const day = date.getDate().toString().padStart(2, "0");
|
|
const hour = date.getHours().toString().padStart(2, "0");
|
|
const minute = date.getMinutes().toString().padStart(2, "0");
|
|
const seconds = date.getSeconds().toString().padStart(2, "0");
|
|
return `${year}${month}${day}T${hour}${minute}${seconds}`;
|
|
}
|
|
|
|
export enum LogType {
|
|
DEBUG_SESSION,
|
|
}
|
|
|
|
export class LogFilePathProvider {
|
|
private logFolder: string = "";
|
|
|
|
constructor(
|
|
private context: vscode.ExtensionContext,
|
|
private logger: vscode.LogOutputChannel,
|
|
) {
|
|
this.updateLogFolder();
|
|
context.subscriptions.push(
|
|
vscode.workspace.onDidChangeConfiguration(e => {
|
|
if (
|
|
e.affectsConfiguration("lldb-dap.logFolder")
|
|
) {
|
|
this.updateLogFolder();
|
|
}
|
|
})
|
|
);
|
|
}
|
|
|
|
get(type: LogType): string {
|
|
const logFolder = this.logFolder || this.context.logUri.fsPath;
|
|
switch(type) {
|
|
case LogType.DEBUG_SESSION:
|
|
return path.join(logFolder, `lldb-dap-session-${formatDate(new Date())}.log`);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private updateLogFolder() {
|
|
const config = vscode.workspace.getConfiguration("lldb-dap");
|
|
let logFolder =
|
|
config.get<string>("logFolder") || this.context.logUri.fsPath;
|
|
vscode.workspace.fs
|
|
.createDirectory(vscode.Uri.file(logFolder))
|
|
.then(undefined, (error) => {
|
|
this.logger.error(`Failed to create log folder ${logFolder}: ${error}`);
|
|
logFolder = this.context.logUri.fsPath;
|
|
})
|
|
.then(() => {
|
|
this.logFolder = logFolder;
|
|
this.logger.info(`Persisting lldb-dap logs to ${logFolder}`);
|
|
});
|
|
}
|
|
}
|