pentest-distro-builder/filesystem/root/.vscode/extensions/ms-vscode.go-0.6.89/node_modules/vscode-debug-logger
2018-10-17 15:35:13 -06:00
..
.vscode Parrot preseed changes 2018-10-17 15:35:13 -06:00
out Parrot preseed changes 2018-10-17 15:35:13 -06:00
src Parrot preseed changes 2018-10-17 15:35:13 -06:00
.npmignore Parrot preseed changes 2018-10-17 15:35:13 -06:00
LICENSE Parrot preseed changes 2018-10-17 15:35:13 -06:00
package.json Parrot preseed changes 2018-10-17 15:35:13 -06:00
README.md Parrot preseed changes 2018-10-17 15:35:13 -06:00
tsconfig.json Parrot preseed changes 2018-10-17 15:35:13 -06:00

vscode-debug-logger

This library provides easy logging for VS Code debug adapters. It has a few features that any debug adapter needs:

  • Logs to console.log only when running in server mode. Debug adapters communicate with the client over stdin/out during normal operation, and using console.log will disrupt that stream.
  • Produces OutputEvents with the proper category to display logs in the user's debug console.
  • A debug adapter doesn't get the user's launch config settings until the launch/attach events are received, so this library queues events received until that time and flushes them when possible.
  • Writes logs to a file.
  • Truncates very long messages that can hang VS Code.

Examples

Consider this all temporary - someday I'll rewrite it to use the winston logging library, or something else.

import * as logger from 'vscode-debug-logger';

import { DebugProtocol } from 'vscode-debugprotocol';
import { DebugSession } from 'vscode-debugadapter';

class MyDebugSession extends DebugSession {
    constructor(debuggerLinesStartAt1: boolean, isServer: boolean = false) {
        /**
         * init takes
         * - a callback for OutputEvents
         * - an optional path to the log file
         * - isServer, which determines whether to also use console.log
         */
        logger.init(e => this.sendEvent(e), logPath, isServer);
    }

    protected launchRequest(response: DebugProtocol.LaunchResponse, args: any): void {
        const logLevel =
            args.trace === 'verbose' ?
                logger.LogLevel.Verbose :
                args.trace === 'log' ?
                    logger.LogLevel.Log :
                    logger.LogLevel.Error;

        // Logs collected after 'init' will be flushed at this point.
        // Verbose logs always go to the file. minLogLevel determines the level of log messages that go to the console.
        logger.setMinLogLevel(logLevel);
    }

    protected stepInRequest(response: DebugProtocol.StepInResponse): void {
        logger.log('StepInRequest');

        // ...

        logger.error('some error');
    }
}

In other files, you can simply import logger again - you never need to pass a logging object around.