-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use log and output channel * update testscd * notify about error on next * add more logs * cr fix * cr fixes * cr fixes * update coverage * update version
- Loading branch information
1 parent
107f458
commit 0ddcbf2
Showing
20 changed files
with
314 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
{ | ||
"require": ["ts-node/register/transpile-only"], | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["src/logger/*.ts"], | ||
"reporter": ["lcov", "text"], | ||
"extension": [".ts"], | ||
"all": true, | ||
"temp-dir": "./reports/.nyc_output", | ||
"report-dir": "./reports/coverage", | ||
"check-coverage": true, | ||
"branches": 27.9, | ||
"lines": 39.9, | ||
"functions": 31.7, | ||
"statements": 40 | ||
"branches": 30.1, | ||
"lines": 43.5, | ||
"functions": 33, | ||
"statements": 43.5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import * as vscode from "vscode"; // NOSONAR | ||
import { getExtensionLogger, getExtensionLoggerOpts, IChildLogger, IVSCodeExtLogger } from "@vscode-logging/logger"; | ||
import { listenToLogSettingsChanges, logLoggerDetails } from "./settings-changes-handler"; | ||
// import {resolve} from "path"; | ||
import { getLoggingLevelSetting, getSourceLocationTrackingSetting} from "./settings"; | ||
|
||
// const PACKAGE_JSON = "package.json"; | ||
const YEOMAN_UI_LOGGER_NAME = "yeomanui"; | ||
|
||
/** | ||
* A Simple Wrapper to hold the state of our "singleton" (per extension) IVSCodeExtLogger | ||
* implementation. | ||
*/ | ||
|
||
export const ERROR_LOGGER_NOT_INITIALIZED = 'Logger has not yet been initialized!'; | ||
|
||
/** | ||
* @type {IVSCodeExtLogger} | ||
*/ | ||
let logger: any; | ||
|
||
function isInitialized() :boolean { | ||
return (logger !== undefined ) ? true : false; | ||
} | ||
|
||
/** | ||
* Note the use of a getter function so the value would be lazy resolved on each use. | ||
* This enables concise and simple consumption of the Logger throughout our Extension. | ||
* | ||
* @returns { IVSCodeExtLogger } | ||
*/ | ||
export function getLogger() : IVSCodeExtLogger { | ||
if (isInitialized() === false) { | ||
throw Error(ERROR_LOGGER_NOT_INITIALIZED); | ||
} | ||
return logger; | ||
} | ||
|
||
export function getClassLogger(className: string) : IChildLogger { | ||
return getLogger().getChildLogger({label:className}); | ||
} | ||
|
||
export function getYeomanUILibraryLogger() : IChildLogger { | ||
return getLibraryLogger(YEOMAN_UI_LOGGER_NAME); | ||
} | ||
|
||
function getLibraryLogger(libraryName: string) : IChildLogger { | ||
return getLogger().getChildLogger({label:libraryName}); | ||
} | ||
|
||
export function createExtensionLoggerAndSubscribeToLogSettingsChanges(context: vscode.ExtensionContext) { | ||
createExtensionLogger(context); | ||
// Subscribe to Logger settings changes. | ||
listenToLogSettingsChanges(context); | ||
} | ||
|
||
/** | ||
* This function should be invoked after the Logger has been initialized in the Extension's `activate` function. | ||
* @param {IVSCodeExtLogger} newLogger | ||
*/ | ||
function initLoggerWrapper(newLogger: any) { | ||
logger = newLogger; | ||
} | ||
|
||
function createExtensionLogger(context: vscode.ExtensionContext) { | ||
const contextLogPath = context.logPath; | ||
const logLevelSetting: string = getLoggingLevelSetting(); | ||
const sourceLocationTrackingSettings: boolean = getSourceLocationTrackingSetting(); | ||
|
||
//TODO: const meta = require(resolve(context.extensionPath, PACKAGE_JSON)); | ||
const extensionLoggerOpts: getExtensionLoggerOpts = { | ||
extName: "yeoman-ui.logger", | ||
level: logLevelSetting, | ||
logPath: contextLogPath, | ||
sourceLocationTracking: sourceLocationTrackingSettings | ||
}; | ||
|
||
// The Logger must first be initialized before any logging commands may be invoked. | ||
const extensionLogger = getExtensionLogger(extensionLoggerOpts); | ||
// Update the logger-wrapper with a reference to the extLogger. | ||
initLoggerWrapper(extensionLogger); | ||
logLoggerDetails(context, logLevelSetting); | ||
} | ||
|
||
module.exports = { | ||
getLogger, | ||
createExtensionLoggerAndSubscribeToLogSettingsChanges, | ||
getClassLogger, | ||
getYeomanUILibraryLogger, | ||
ERROR_LOGGER_NOT_INITIALIZED | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as vscode from "vscode"; // NOSONAR | ||
import {getLogger} from "./logger-wrapper"; | ||
import {LOGGING_LEVEL_CONFIG_PROP, SOURCE_TRACKING_CONFIG_PROP} from "./settings"; | ||
|
||
export function logLoggerDetails(context: vscode.ExtensionContext, configLogLevel: string): void { | ||
getLogger().info(`Start Logging in Log Level: <${configLogLevel}>`); | ||
getLogger().info(`Full Logs can be found in the <${context.logPath}> folder.`); | ||
} | ||
|
||
/** | ||
* @param {vscode.ExtensionContext} context | ||
*/ | ||
export function listenToLogSettingsChanges(context: vscode.ExtensionContext) { | ||
// To enable dynamic logging level we must listen to VSCode configuration changes | ||
// on our `loggingLevelConfigProp` configuration setting. | ||
context.subscriptions.push( | ||
vscode.workspace.onDidChangeConfiguration(e => { | ||
if (e.affectsConfiguration(LOGGING_LEVEL_CONFIG_PROP)) { | ||
const logLevel: string = vscode.workspace | ||
.getConfiguration() | ||
.get(LOGGING_LEVEL_CONFIG_PROP); | ||
|
||
getLogger().changeLevel(logLevel); | ||
logLoggerDetails(context, logLevel); | ||
} | ||
}) | ||
); | ||
|
||
// Enable responding to changes in the sourceLocationTracking setting | ||
context.subscriptions.push( | ||
vscode.workspace.onDidChangeConfiguration(e => { | ||
if (e.affectsConfiguration(SOURCE_TRACKING_CONFIG_PROP)) { | ||
const newSourceLocationTracking = vscode.workspace | ||
.getConfiguration() | ||
.get(SOURCE_TRACKING_CONFIG_PROP); | ||
|
||
getLogger().changeSourceLocationTracking(newSourceLocationTracking); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
module.exports = { | ||
listenToLogSettingsChanges, | ||
logLoggerDetails | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as vscode from "vscode"; // NOSONAR | ||
import { resolve } from "dns"; | ||
|
||
/** | ||
* Note that the values of these configuration properties must match those defined in the package.json | ||
*/ | ||
export const LOGGING_LEVEL_CONFIG_PROP = "logger.loggingLevel"; | ||
export const SOURCE_TRACKING_CONFIG_PROP = "logger.sourceLocationTracking"; | ||
|
||
/** | ||
* @returns {LogLevel} | ||
*/ | ||
export function getLoggingLevelSetting(): string { | ||
const config = vscode.workspace.getConfiguration(); | ||
return config.get(LOGGING_LEVEL_CONFIG_PROP); | ||
} | ||
|
||
/** | ||
* @returns {boolean} | ||
*/ | ||
export function getSourceLocationTrackingSetting(): boolean { | ||
const config = vscode.workspace.getConfiguration(); | ||
return config.get(SOURCE_TRACKING_CONFIG_PROP); | ||
} | ||
|
||
module.exports = { | ||
LOGGING_LEVEL_CONFIG_PROP, | ||
SOURCE_TRACKING_CONFIG_PROP, | ||
getLoggingLevelSetting, | ||
getSourceLocationTrackingSetting | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.