mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 01:25:39 -05:00
* Initial VS Code 1.21 file copy with patches * A few more merges * Post npm install * Fix batch of build breaks * Fix more build breaks * Fix more build errors * Fix more build breaks * Runtime fixes 1 * Get connection dialog working with some todos * Fix a few packaging issues * Copy several node_modules to package build to fix loader issues * Fix breaks from master * A few more fixes * Make tests pass * First pass of license header updates * Second pass of license header updates * Fix restore dialog issues * Remove add additional themes menu items * fix select box issues where the list doesn't show up * formatting * Fix editor dispose issue * Copy over node modules to correct location on all platforms
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { OutputChannel, window, workspace } from 'vscode';
|
|
|
|
enum Trace {
|
|
Off,
|
|
Verbose
|
|
}
|
|
|
|
namespace Trace {
|
|
export function fromString(value: string): Trace {
|
|
value = value.toLowerCase();
|
|
switch (value) {
|
|
case 'off':
|
|
return Trace.Off;
|
|
case 'verbose':
|
|
return Trace.Verbose;
|
|
default:
|
|
return Trace.Off;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function isString(value: any): value is string {
|
|
return Object.prototype.toString.call(value) === '[object String]';
|
|
}
|
|
|
|
export class Logger {
|
|
private trace?: Trace;
|
|
private _output?: OutputChannel;
|
|
|
|
constructor() {
|
|
this.updateConfiguration();
|
|
}
|
|
|
|
public log(message: string, data?: any): void {
|
|
if (this.trace === Trace.Verbose) {
|
|
this.output.appendLine(`[Log - ${(new Date().toLocaleTimeString())}] ${message}`);
|
|
if (data) {
|
|
this.output.appendLine(Logger.data2String(data));
|
|
}
|
|
}
|
|
}
|
|
|
|
public updateConfiguration() {
|
|
this.trace = this.readTrace();
|
|
}
|
|
|
|
private get output(): OutputChannel {
|
|
if (!this._output) {
|
|
this._output = window.createOutputChannel('Markdown');
|
|
}
|
|
return this._output;
|
|
}
|
|
|
|
private readTrace(): Trace {
|
|
return Trace.fromString(workspace.getConfiguration().get<string>('markdown.trace', 'off'));
|
|
}
|
|
|
|
private static data2String(data: any): string {
|
|
if (data instanceof Error) {
|
|
if (isString(data.stack)) {
|
|
return data.stack;
|
|
}
|
|
return (data as Error).message;
|
|
}
|
|
if (isString(data)) {
|
|
return data;
|
|
}
|
|
return JSON.stringify(data, undefined, 2);
|
|
}
|
|
} |