mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Support to configure logging levels for sqltools services (#2731)
* Adding support for configuring SqlTools log levels from user configuration. This also adds changes to see the tail of the sqltoolsservicelayer log file in the newly created 'Output->Log (SqlTools)' channel * Three new user settings control how logging happens. tracingLevel, logRetentionMinutes & logFilesRemovalLimit. Default tracingLevel is set to 'Critical'. * The logfiles include ui Extension host process id in their log file names. This ensures that filenames from multiple instances of Azure Data Studio running do not collide with each other. Furthermore log directory for being used for the tools service backend processes. This ensures that there is no name conflict when multiple instances of azuredatastudio are running on the same box. Also when azuredatastudio is started from vscode under debugger the log directory is set to %APPDATA%\Code\mssql while the official location is %APPDATA%\azuredatastudio\mssql. So dev environment should not affect other running instances. Kindly note that all debug runs of azuredatastudio share the same directory and all non debug runs share a directory different from those running under debugger. * Log files older than a week get cleaned up upon start-up. The log file cleanup behavior can be controlled at user level by logRetentionMinutes & logFilesRemovalLimit settings.
This commit is contained in:
@@ -7,6 +7,13 @@
|
||||
import * as path from 'path';
|
||||
import * as crypto from 'crypto';
|
||||
import * as os from 'os';
|
||||
import {workspace, WorkspaceConfiguration} from 'vscode';
|
||||
import * as findRemoveSync from 'find-remove';
|
||||
|
||||
const configTracingLevel = 'tracingLevel';
|
||||
const configLogRetentionMinutes = 'logRetentionMinutes';
|
||||
const configLogFilesRemovalLimit = 'logFilesRemovalLimit';
|
||||
const extensionConfigSectionName = 'mssql';
|
||||
|
||||
// The function is a duplicate of \src\paths.js. IT would be better to import path.js but it doesn't
|
||||
// work for now because the extension is running in different process.
|
||||
@@ -20,8 +27,69 @@ export function getAppDataPath() {
|
||||
}
|
||||
}
|
||||
|
||||
export function getDefaultLogLocation() {
|
||||
return path.join(getAppDataPath(), 'azuredatastudio');
|
||||
export function removeOldLogFiles(prefix: string) : JSON {
|
||||
return findRemoveSync(getDefaultLogDir(), {prefix: `${prefix}_`, age: {seconds: getConfigLogRetentionSeconds()}, limit: getConfigLogFilesRemovalLimit()});
|
||||
}
|
||||
|
||||
export function getConfiguration(config: string = extensionConfigSectionName) : WorkspaceConfiguration {
|
||||
return workspace.getConfiguration(extensionConfigSectionName);
|
||||
}
|
||||
|
||||
export function getConfigLogFilesRemovalLimit() : number {
|
||||
let config = getConfiguration();
|
||||
if (config) {
|
||||
return Number((config[configLogFilesRemovalLimit]).toFixed(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function getConfigLogRetentionSeconds() : number {
|
||||
let config = getConfiguration();
|
||||
if (config) {
|
||||
return Number((config[configLogRetentionMinutes] * 60).toFixed(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function getConfigTracingLevel() : string {
|
||||
let config = getConfiguration();
|
||||
if (config) {
|
||||
return config[configTracingLevel];
|
||||
}
|
||||
else
|
||||
{
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function getDefaultLogDir() : string {
|
||||
return path.join(process.env['VSCODE_LOGS'], '..', '..','mssql');
|
||||
}
|
||||
|
||||
export function getDefaultLogFile(prefix: string, pid: number) : string {
|
||||
return path.join(getDefaultLogDir(), `${prefix}_${pid}.log`);
|
||||
}
|
||||
|
||||
export function getCommonLaunchArgsAndCleanupOldLogFiles(prefix: string, executablePath: string) : string [] {
|
||||
let launchArgs = [];
|
||||
launchArgs.push('--log-file');
|
||||
let logFile = getDefaultLogFile(prefix, process.pid);
|
||||
launchArgs.push(logFile);
|
||||
|
||||
console.log(`logFile for ${path.basename(executablePath)} is ${logFile}`);
|
||||
console.log(`This process (ui Extenstion Host) is pid: ${process.pid}`);
|
||||
// Delete old log files
|
||||
let deletedLogFiles = removeOldLogFiles(prefix);
|
||||
console.log(`Old log files deletion report: ${JSON.stringify(deletedLogFiles)}`);
|
||||
launchArgs.push('--tracing-level');
|
||||
launchArgs.push(getConfigTracingLevel());
|
||||
return launchArgs;
|
||||
}
|
||||
|
||||
export function ensure(target: object, key: string): any {
|
||||
|
||||
Reference in New Issue
Block a user