Use vscode log path (#6599)

* use vscode log file

* remove log

* remove sqltools output log and add command to open log
This commit is contained in:
Anthony Dresser
2019-08-12 11:44:27 -07:00
committed by GitHub
parent 2d2b61a001
commit d733525f2c
8 changed files with 56 additions and 30 deletions

View File

@@ -11,6 +11,7 @@ import * as os from 'os';
import * as findRemoveSync from 'find-remove';
import * as constants from './constants';
import * as fs from 'fs';
import { promisify } from 'util';
const configTracingLevel = 'tracingLevel';
const configLogRetentionMinutes = 'logRetentionMinutes';
@@ -30,6 +31,17 @@ export function getAppDataPath() {
}
}
export namespace pfs {
export function exists(path: string): Promise<boolean> {
return promisify(fs.exists)(path);
}
export function mkdir(path: string, mode?: number): Promise<void> {
return promisify(fs.mkdir)(path, mode);
}
}
/**
* Get a file name that is not already used in the target directory
* @param filePath source notebook file name
@@ -57,8 +69,8 @@ export function copyFile(source: string, target: string): void {
fs.copyFileSync(source, target);
}
export function removeOldLogFiles(prefix: string): JSON {
return findRemoveSync(getDefaultLogDir(), { prefix: `${prefix}_`, age: { seconds: getConfigLogRetentionSeconds() }, limit: getConfigLogFilesRemovalLimit() });
export function removeOldLogFiles(logPath: string, prefix: string): JSON {
return findRemoveSync(logPath, { age: { seconds: getConfigLogRetentionSeconds() }, limit: getConfigLogFilesRemovalLimit() });
}
export function getConfiguration(config: string = extensionConfigSectionName): vscode.WorkspaceConfiguration {
@@ -95,24 +107,20 @@ export function getConfigTracingLevel(): string {
}
}
export function getDefaultLogDir(): string {
return path.join(process.env['ADS_LOGS'], '..', '..', 'mssql');
export function getLogFileName(prefix: string, pid: number): string {
return `${prefix}_${pid}.log`;
}
export function getDefaultLogFile(prefix: string, pid: number): string {
return path.join(getDefaultLogDir(), `${prefix}_${pid}.log`);
}
export function getCommonLaunchArgsAndCleanupOldLogFiles(prefix: string, executablePath: string): string[] {
export function getCommonLaunchArgsAndCleanupOldLogFiles(logPath: string, fileName: string, executablePath: string): string[] {
let launchArgs = [];
launchArgs.push('--log-file');
let logFile = getDefaultLogFile(prefix, process.pid);
let logFile = path.join(logPath, fileName);
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);
let deletedLogFiles = removeOldLogFiles(logPath, fileName);
console.log(`Old log files deletion report: ${JSON.stringify(deletedLogFiles)}`);
launchArgs.push('--tracing-level');
launchArgs.push(getConfigTracingLevel());