[Lldb-commits] [lldb] Logging setup for lldb-dap extension (PR #146884)

2025-07-03 Thread Bassam Khouri via lldb-commits


@@ -156,16 +157,34 @@ async function getDAPArguments(
 .get("arguments", []);
 }
 
+/**
+ * Formats the given date as a string in the form "MMdd".
+ *
+ * @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 + hour + minute + seconds;

bkhouri wrote:

suggestion: although I don't think it's a standard, I have see the following 
syntax used previously, `mmddThhmmss` where a hardcoded `T` is placed 
before the time.

e.g.: `20250107T140034` would represent January 7, 2027 at 2:00:34pm.  

This might help clarify the digits are are date/time, wherever they appear.

https://github.com/llvm/llvm-project/pull/146884
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Logging setup for lldb-dap extension (PR #146884)

2025-07-03 Thread Bassam Khouri via lldb-commits


@@ -0,0 +1,88 @@
+import * as vscode from "vscode";
+import * as winston from "winston";
+import * as Transport from "winston-transport";
+
+class OutputChannelTransport extends Transport {
+constructor(private readonly ouptutChannel: vscode.OutputChannel) {
+super();
+}
+
+public log(info: any, next: () => void): void {
+this.ouptutChannel.appendLine(info[Symbol.for('message')]);
+next();
+}
+}
+
+export class Logger implements vscode.Disposable {
+private disposables: vscode.Disposable[] = [];
+private logger: winston.Logger;
+
+constructor(public readonly logFilePath: (name: string) => string, 
ouptutChannel: vscode.OutputChannel) {
+const ouptutChannelTransport = new 
OutputChannelTransport(ouptutChannel);
+ouptutChannelTransport.level = this.outputChannelLevel();
+this.logger = winston.createLogger({
+transports: [
+new winston.transports.File({ filename: 
logFilePath("lldb-dap-extension.log"), level: "debug" }), // File logging at 
the 'debug' level
+ouptutChannelTransport
+],
+format: winston.format.combine(
+winston.format.errors({ stack: true }),
+winston.format.timestamp({ format: "-MM-DD HH:mm:ss" }),
+winston.format.printf(msg => `[${msg.timestamp}][${msg.level}] 
${msg.message} ${msg.stack ? msg.stack : ''}`),
+),
+});
+if (process.env.NODE_ENV !== 'production') {
+this.logger.add(new winston.transports.Console({
+level: "error"
+}));
+}
+this.disposables.push(
+{
+dispose: () => this.logger.close()
+},
+vscode.workspace.onDidChangeConfiguration(e => {
+if (e.affectsConfiguration("lldb-dap.verboseLogging")) {
+ouptutChannelTransport.level = this.outputChannelLevel();
+}
+})
+);
+}
+
+debug(message: any) {
+this.logger.debug(this.normalizeMessage(message));
+}
+
+info(message: any) {
+this.logger.info(this.normalizeMessage(message));
+}
+
+warn(message: any) {
+this.logger.warn(this.normalizeMessage(message));
+}
+
+error(message: any) {
+if (message instanceof Error) {
+this.logger.error(message);
+return;
+}
+this.logger.error(this.normalizeMessage(message));
+}
+
+private normalizeMessage(message: any) {
+if (typeof message === "string") {
+return message;
+} else if (typeof message === "object") {

bkhouri wrote:

question: can all objects be converted to JSON?  if no, consider include 
additional logic that would handle the case.

https://github.com/llvm/llvm-project/pull/146884
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits