Skip to content

Commit e1281ef

Browse files
committed
Inital work to add logging
Signed-off-by: EKhan <[email protected]>
1 parent 3b5d6c0 commit e1281ef

9 files changed

+413
-12
lines changed

packages/vsce/log4jsconfig.json

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"log4jsConfig": {
3+
"appenders": {
4+
"default": {
5+
"type": "fileSync",
6+
"layout": {
7+
"type": "pattern",
8+
"pattern": "[%d{yyyy/MM/dd} %d{hh:mm:ss.SSS}] [%p] %m"
9+
},
10+
"filename": "logs/imperative.log"
11+
},
12+
"imperative": {
13+
"type": "fileSync",
14+
"layout": {
15+
"type": "pattern",
16+
"pattern": "[%d{yyyy/MM/dd} %d{hh:mm:ss.SSS}] [%p] %m"
17+
},
18+
"filename": "logs/imperative.log"
19+
},
20+
"app": {
21+
"type": "fileSync",
22+
"layout": {
23+
"type": "pattern",
24+
"pattern": "[%d{yyyy/MM/dd} %d{hh:mm:ss.SSS}] [%p] %m"
25+
},
26+
"filename": "logs/zowe.log"
27+
}
28+
},
29+
"categories": {
30+
"default": {
31+
"appenders": ["default"],
32+
"level": "DEBUG"
33+
},
34+
"imperative": {
35+
"appenders": ["imperative"],
36+
"level": "DEBUG"
37+
},
38+
"app": {
39+
"appenders": ["app"],
40+
"level": "DEBUG"
41+
}
42+
}
43+
}
44+
}

packages/vsce/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,28 @@
755755
"description": "Zowe CICS Extension History",
756756
"scope": "window"
757757
},
758+
"zowe.cics.logger": {
759+
"type": "string",
760+
"default": "INFO",
761+
"enum": [
762+
"TRACE",
763+
"DEBUG",
764+
"INFO",
765+
"WARN",
766+
"ERROR",
767+
"FATAL"
768+
],
769+
"markdownEnumDescriptions": [
770+
"Messages about fine details of the application's behaviour.",
771+
"Messages about diagnostic information for troubleshooting.",
772+
"Messages about routine application operations.",
773+
"Messages about potentially harmful occurrences.",
774+
"Messages about serious problem occurrences.",
775+
"Messages about catastraphic error events."
776+
],
777+
"description": "Select the log level for IBM CICS for Zowe Explorer. The default is INFO.",
778+
"scope": "window"
779+
},
758780
"zowe.cics.program.filter": {
759781
"type": "string",
760782
"default": "NOT (PROGRAM=CEE* OR PROGRAM=DFH* OR PROGRAM=CJ* OR PROGRAM=EYU* OR PROGRAM=CSQ* OR PROGRAM=CEL* OR PROGRAM=IGZ*)",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
10+
*/
11+
12+
import { IMessageDefinition } from "@zowe/imperative";
13+
14+
export const CicsMessages: { [key: string]: IMessageDefinition } = {
15+
zoweExplorerNotFound: {
16+
message: "Zowe Explorer was not found: Please ensure Zowe Explorer v2.0.0 or higher is installed"
17+
},
18+
19+
zoweExplorerModified: {
20+
message: "Zowe Explorer was modified for the CICS Extension."
21+
},
22+
23+
notInitializedCorrectly: {
24+
message: "IBM CICS for Zowe Explorer was not initialized correctly."
25+
},
26+
27+
incorrectZoweExplorerVersion: {
28+
message: `Zowe Explorer was not found: either it is not installed or you are using an older version without extensibility API.
29+
Please ensure Zowe Explorer v2.0.0-next.202202221200 or higher is installed`
30+
},
31+
32+
loadingResources: {
33+
message: "Loading resources..."
34+
}
35+
36+
};

packages/vsce/src/extension.ts

+24-11
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import { getFolderIcon, getIconFilePathFromName } from "./utils/iconUtils";
1616
import { ProfileManagement } from "./utils/profileManagement";
1717
import { getZoweExplorerVersion } from "./utils/workspaceUtils";
1818

19-
import { Logger } from "@zowe/imperative";
2019
import { getCommands } from "./commands";
20+
import { CicsLogger } from "./utils/cicsLogger";
21+
import { LoggerUtils } from "./utils/LoggerUtils";
22+
import { CicsMessages } from "./constants/Cics.messages";
2123

2224
/**
2325
* Initializes the extension
@@ -26,13 +28,21 @@ import { getCommands } from "./commands";
2628
*/
2729
export async function activate(context: ExtensionContext) {
2830
const zeVersion = getZoweExplorerVersion();
29-
const logger = Logger.getAppLogger();
31+
32+
const logsPath =
33+
await CicsLogger.initializeZoweLogger(context);
34+
CicsLogger.zeOutputChannel = await LoggerUtils.initVscLogger(context, logsPath);
35+
36+
3037
let treeDataProv: CICSTree = null;
3138
if (!zeVersion) {
32-
window.showErrorMessage("Zowe Explorer was not found: Please ensure Zowe Explorer v2.0.0 or higher is installed");
39+
CicsLogger.error(CicsMessages.zoweExplorerNotFound.message);
40+
window.showErrorMessage(CicsMessages.zoweExplorerNotFound.message);
3341
return;
3442
} else if (zeVersion[0] !== "3") {
35-
window.showErrorMessage(`Current version of Zowe Explorer is ${zeVersion}. Please ensure Zowe Explorer v3.0.0 or higher is installed`);
43+
const message = `Current version of Zowe Explorer is ${zeVersion}. Please ensure Zowe Explorer v3.0.0 or higher is installed`;
44+
CicsLogger.error(message);
45+
window.showErrorMessage(message);
3646
return;
3747
}
3848
if (ProfileManagement.apiDoesExist()) {
@@ -47,16 +57,14 @@ export async function activate(context: ExtensionContext) {
4757
await treeDataProv.refreshLoadedProfiles();
4858
});
4959
}
50-
logger.debug("Zowe Explorer was modified for the CICS Extension.");
60+
CicsLogger.debug(CicsMessages.zoweExplorerModified.message);
5161
} catch (error) {
52-
logger.error("IBM CICS for Zowe Explorer was not initialized correctly");
62+
CicsLogger.error(CicsMessages.notInitializedCorrectly.message);
5363
return;
5464
}
5565
} else {
56-
window.showErrorMessage(
57-
"Zowe Explorer was not found: either it is not installed or you are using an older version without extensibility API. " +
58-
"Please ensure Zowe Explorer v2.0.0-next.202202221200 or higher is installed"
59-
);
66+
CicsLogger.error(CicsMessages.incorrectZoweExplorerVersion.message);
67+
window.showErrorMessage(CicsMessages.incorrectZoweExplorerVersion.message);
6068
return;
6169
}
6270

@@ -78,7 +86,7 @@ export async function activate(context: ExtensionContext) {
7886
window.withProgress(
7987
{
8088
location: ProgressLocation.Notification,
81-
title: "Loading resources...",
89+
title: CicsMessages.loadingResources.message,
8290
cancellable: true,
8391
},
8492
async (_progress, _token) => {
@@ -121,6 +129,7 @@ export async function activate(context: ExtensionContext) {
121129
try {
122130
plexExpansionHandler(node.element, treeDataProv);
123131
} catch (error) {
132+
CicsLogger.error(error);
124133
node.element.getParent().iconPath = getIconFilePathFromName("profile-disconnected");
125134
treeDataProv._onDidChangeTreeData.fire(undefined);
126135
}
@@ -175,3 +184,7 @@ export async function activate(context: ExtensionContext) {
175184

176185
context.subscriptions.concat(getCommands(treeDataProv, treeview));
177186
}
187+
188+
export async function deactivate(): Promise<void> {
189+
CicsLogger.disposeZoweLogger();
190+
}
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
10+
*/
11+
12+
/* eslint-disable @typescript-eslint/restrict-plus-operands */
13+
14+
import * as vscode from "vscode";
15+
import { Gui } from "@zowe/zowe-explorer-api";
16+
17+
import { CicsLogger } from "./cicsLogger";
18+
import { PersistentStorage } from "./PersistentStorage";
19+
20+
export class LoggerUtils {
21+
private static outputChannel: vscode.OutputChannel;
22+
private static persistentStorage = new PersistentStorage("zowe.cics.persistent");
23+
24+
public static async initVscLogger(context: vscode.ExtensionContext, logFileLocation: string): Promise<vscode.OutputChannel> {
25+
LoggerUtils.outputChannel ??= Gui.createOutputChannel(vscode.l10n.t("CICS for Zowe Explorer"));
26+
this.writeVscLoggerInfo(LoggerUtils.outputChannel, logFileLocation, context);
27+
CicsLogger.info(vscode.l10n.t("Initialized logger for IBM CICS for Zowe Explorer"));
28+
await this.compareCliLogSetting();
29+
return LoggerUtils.outputChannel;
30+
}
31+
32+
private static writeVscLoggerInfo(outputChannel: vscode.OutputChannel, logFileLocation: string, context: vscode.ExtensionContext): void {
33+
outputChannel.appendLine(`${context.extension.packageJSON.displayName as string} ${context.extension.packageJSON.version as string}`);
34+
outputChannel.appendLine(
35+
vscode.l10n.t({
36+
message: "This log file can be found at {0}",
37+
args: [logFileLocation],
38+
comment: ["Log file location"],
39+
})
40+
);
41+
outputChannel.appendLine(
42+
vscode.l10n.t({
43+
message: "Zowe Explorer log level: {0}",
44+
args: [CicsLogger.getLogSetting()],
45+
comment: ["Log setting"],
46+
})
47+
);
48+
}
49+
50+
private static async compareCliLogSetting(): Promise<void> {
51+
const cliLogSetting = this.getZoweLogEnvVar();
52+
const zeLogSetting = CicsLogger.getLogSetting();
53+
// @ts-expect-error
54+
if (cliLogSetting && +MessageSeverity[zeLogSetting] !== +MessageSeverity[cliLogSetting]) {
55+
const notified = LoggerUtils.persistentStorage.getCicsZoweLoggerSetting();
56+
if (!notified) {
57+
await this.updateVscLoggerSetting(cliLogSetting);
58+
}
59+
}
60+
}
61+
62+
private static async updateVscLoggerSetting(cliSetting: string): Promise<void> {
63+
const updateLoggerButton = vscode.l10n.t("Update");
64+
const message = vscode.l10n.t({
65+
message: `Zowe Explorer now has a VS Code logger with a default log level of INFO.
66+
\nIt looks like the Zowe CLI's ZOWE_APP_LOG_LEVEL={0}.
67+
\nWould you like Zowe Explorer to update to the the same log level?`,
68+
args: [cliSetting],
69+
comment: ["CLI setting"],
70+
});
71+
await Gui.infoMessage(message, {
72+
items: [updateLoggerButton],
73+
vsCodeOpts: { modal: true },
74+
}).then((selection) => {
75+
if (selection === updateLoggerButton) {
76+
this.setLogSetting(cliSetting);
77+
}
78+
});
79+
}
80+
81+
private static setLogSetting(setting: string): void {
82+
LoggerUtils.persistentStorage.addCicsZoweLoggerSetting(setting);
83+
}
84+
85+
private static getZoweLogEnvVar(): string {
86+
return process.env.ZOWE_APP_LOG_LEVEL;
87+
}
88+
}

packages/vsce/src/utils/PersistentStorage.ts

+29
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class PersistentStorage {
2525
private static readonly urimapsSearchHistory: string = "urimapsSearchHistory";
2626
private static readonly pipelineSearchHistory: string = "pipelineSearchHistory";
2727
private static readonly webserviceSearchHistory: string = "webserviceSearchHistory";
28+
private static readonly cicsZoweLoggerSetting: string = "cicsZoweLoggerSetting";
2829

2930
private mProgramSearchHistory: string[] = [];
3031
private mLibrarySearchHistory: string[] = [];
@@ -37,6 +38,7 @@ export class PersistentStorage {
3738
private mURIMapsSearchHistory: string[] = [];
3839
private mPipelineSearchHistory: string[] = [];
3940
private mWebServiceSearchHistory: string[] = [];
41+
private mCicsZoweLoggerSetting: string = "INFO";
4042

4143
constructor(schema: string) {
4244
this.schema = schema;
@@ -55,6 +57,7 @@ export class PersistentStorage {
5557
let urimapsSearchHistoryLines: string[] | undefined;
5658
let pipelineSearchHistoryLines: string[] | undefined;
5759
let webserviceSearchHistoryLines: string[] | undefined;
60+
let cicsZoweLoggerSetting: string;
5861

5962
if (workspace.getConfiguration(this.schema)) {
6063
programSearchHistoryLines = workspace.getConfiguration(this.schema).get(PersistentStorage.programSearchHistory);
@@ -68,6 +71,7 @@ export class PersistentStorage {
6871
urimapsSearchHistoryLines = workspace.getConfiguration(this.schema).get(PersistentStorage.urimapsSearchHistory);
6972
pipelineSearchHistoryLines = workspace.getConfiguration(this.schema).get(PersistentStorage.pipelineSearchHistory);
7073
webserviceSearchHistoryLines = workspace.getConfiguration(this.schema).get(PersistentStorage.webserviceSearchHistory);
74+
cicsZoweLoggerSetting = workspace.getConfiguration(this.schema).get(PersistentStorage.cicsZoweLoggerSetting);
7175
}
7276
if (programSearchHistoryLines) {
7377
this.mProgramSearchHistory = programSearchHistoryLines;
@@ -160,6 +164,10 @@ export class PersistentStorage {
160164
return this.mWebServiceSearchHistory;
161165
}
162166

167+
public getCicsZoweLoggerSetting() : string {
168+
return this.mCicsZoweLoggerSetting;
169+
}
170+
163171
public async resetProgramSearchHistory(): Promise<void> {
164172
this.mProgramSearchHistory = [];
165173
await this.updateProgramSearchHistory();
@@ -205,6 +213,11 @@ export class PersistentStorage {
205213
await this.updateWebServiceSearchHistory();
206214
}
207215

216+
public async resetCicsZoweLoggerSetting() : Promise<void> {
217+
this.mCicsZoweLoggerSetting = "INFO";
218+
await this.updateCicsZoweLoggerSetting();
219+
}
220+
208221
private async updateProgramSearchHistory(): Promise<void> {
209222
const settings: any = { ...workspace.getConfiguration(this.schema) };
210223
if (settings.persistence) {
@@ -285,6 +298,14 @@ export class PersistentStorage {
285298
}
286299
}
287300

301+
private async updateCicsZoweLoggerSetting(): Promise<void> {
302+
const settings: any = { ...workspace.getConfiguration(this.schema) };
303+
if (settings.persistence) {
304+
settings[PersistentStorage.cicsZoweLoggerSetting] = this.mCicsZoweLoggerSetting;
305+
await workspace.getConfiguration().update(this.schema, settings, ConfigurationTarget.Global);
306+
}
307+
}
308+
288309
public async addProgramSearchHistory(criteria: string): Promise<void> {
289310
if (criteria) {
290311
this.mProgramSearchHistory = this.mProgramSearchHistory.filter((element) => {
@@ -446,6 +467,14 @@ export class PersistentStorage {
446467
}
447468
}
448469

470+
public async addCicsZoweLoggerSetting(criteria: string): Promise<void> {
471+
if (criteria) {
472+
this.mCicsZoweLoggerSetting = criteria.trim();
473+
474+
await this.updateCicsZoweLoggerSetting();
475+
}
476+
}
477+
449478
public async removeLoadedCICSProfile(name: string): Promise<void> {
450479
if (name) {
451480
this.mLoadedCICSProfile = this.mLoadedCICSProfile.filter((element) => {

0 commit comments

Comments
 (0)