mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-06-22 19:15:10 +02:00
Merge branch 'dev' of github.com:estruyf/vscode-front-matter into dev
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
### 🎨 Enhancements
|
||||
|
||||
- [#799](https://github.com/estruyf/vscode-front-matter/issues/799): Added `frontMatter.logging` setting to define the logging output. Options are `info`, `warn`, `error`, and `verbose`. Default is `info`.
|
||||
- [#800](https://github.com/estruyf/vscode-front-matter/issues/800): Add colors for the Front Matter CMS output
|
||||
|
||||
### ⚡️ Optimizations
|
||||
|
||||
@@ -1988,6 +1988,16 @@
|
||||
"frontMatter.website.host": {
|
||||
"type": "string",
|
||||
"markdownDescription": "%setting.frontMatter.website.host.markdownDescription%"
|
||||
},
|
||||
"frontMatter.logging": {
|
||||
"type": "string",
|
||||
"default": "info",
|
||||
"enum": [
|
||||
"error",
|
||||
"warn",
|
||||
"info",
|
||||
"verbose"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -34,6 +34,7 @@ import * as l10n from '@vscode/l10n';
|
||||
import { LocalizationKey } from '../localization';
|
||||
import { DashboardMessage } from '../dashboardWebView/DashboardMessage';
|
||||
import { NavigationType } from '../dashboardWebView/models';
|
||||
import { ignoreMsgCommand } from '../utils';
|
||||
|
||||
export class Dashboard {
|
||||
private static webview: WebviewPanel | null = null;
|
||||
@@ -222,7 +223,9 @@ export class Dashboard {
|
||||
});
|
||||
|
||||
Dashboard.webview.webview.onDidReceiveMessage(async (msg) => {
|
||||
Logger.info(`Receiving message from dashboard: ${msg.command}`);
|
||||
if (!ignoreMsgCommand(msg.command)) {
|
||||
Logger.verbose(`Receiving message from dashboard: ${msg.command}`);
|
||||
}
|
||||
|
||||
LocalizationListener.process(msg);
|
||||
DashboardListener.process(msg);
|
||||
|
||||
@@ -565,7 +565,7 @@ export class Folders {
|
||||
* Find the content folders
|
||||
*/
|
||||
public static async getContentFolders() {
|
||||
Logger.info('Folders:getContentFolders:start');
|
||||
Logger.verbose('Folders:getContentFolders:start');
|
||||
// Find folders that contain files
|
||||
const wsFolder = Folders.getWorkspaceFolder();
|
||||
if (!wsFolder) {
|
||||
@@ -604,7 +604,7 @@ export class Folders {
|
||||
|
||||
const uniqueFolders = [...new Set(folders)];
|
||||
|
||||
Logger.info('Folders:getContentFolders:end');
|
||||
Logger.verbose('Folders:getContentFolders:end');
|
||||
return uniqueFolders.map((folder) => relative(wsFolder?.path || '', folder));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ export const GeneralCommands = {
|
||||
logging: {
|
||||
info: 'logInfo',
|
||||
warn: 'logWarn',
|
||||
error: 'logError'
|
||||
error: 'logError',
|
||||
verbose: 'logVerbose'
|
||||
},
|
||||
runCommand: 'runCommand',
|
||||
getLocalization: 'getLocalization',
|
||||
|
||||
@@ -114,6 +114,8 @@ export const SETTING_SNIPPETS_WRAPPER = 'snippets.wrapper.enabled';
|
||||
|
||||
export const SETTING_WEBSITE_URL = 'website.host';
|
||||
|
||||
export const SETTING_LOGGING = 'logging';
|
||||
|
||||
/**
|
||||
* Sponsors only settings
|
||||
*/
|
||||
|
||||
@@ -70,7 +70,7 @@ export const App: React.FunctionComponent<IAppProps> = ({
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
messageHandler.send(GeneralCommands.toVSCode.logging.info, {
|
||||
messageHandler.send(GeneralCommands.toVSCode.logging.verbose, {
|
||||
message: `Loaded with view ${view}`,
|
||||
location: 'DASHBOARD'
|
||||
});
|
||||
@@ -85,14 +85,14 @@ export const App: React.FunctionComponent<IAppProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (settings && Object.keys(settings).length > 0) {
|
||||
messageHandler.send(GeneralCommands.toVSCode.logging.info, {
|
||||
messageHandler.send(GeneralCommands.toVSCode.logging.verbose, {
|
||||
message: `Settings loaded`,
|
||||
location: 'DASHBOARD'
|
||||
});
|
||||
}
|
||||
|
||||
if (pages) {
|
||||
messageHandler.send(GeneralCommands.toVSCode.logging.info, {
|
||||
messageHandler.send(GeneralCommands.toVSCode.logging.verbose, {
|
||||
message: `Pages loaded - ${pages.length} pages`,
|
||||
location: 'DASHBOARD'
|
||||
});
|
||||
|
||||
@@ -130,7 +130,7 @@ export const DataView: React.FunctionComponent<IDataViewProps> = (
|
||||
});
|
||||
|
||||
Messenger.send(GeneralCommands.toVSCode.logging.info, {
|
||||
message: 'DataView loaded',
|
||||
message: 'Data view loaded',
|
||||
location: 'DASHBOARD'
|
||||
});
|
||||
|
||||
|
||||
@@ -159,7 +159,6 @@ ${snippetBody}
|
||||
message: `SnippetForm: ${(e as Error).message}`,
|
||||
location: 'DASHBOARD'
|
||||
});
|
||||
console.log('Error', (e as Error).message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
SearchReadyAtom,
|
||||
ModeAtom
|
||||
} from '../state';
|
||||
import { Messenger } from '@estruyf/vscode/dist/client';
|
||||
import { Messenger, messageHandler } from '@estruyf/vscode/dist/client';
|
||||
import { EventData } from '@estruyf/vscode/dist/models';
|
||||
import { NavigationType } from '../models';
|
||||
import { GeneralCommands } from '../../constants';
|
||||
@@ -31,6 +31,11 @@ export default function useMessages() {
|
||||
const messageListener = (event: MessageEvent<EventData<any>>) => {
|
||||
const message = event.data;
|
||||
|
||||
messageHandler.send(GeneralCommands.toVSCode.logging.verbose, {
|
||||
message: `Message received: ${message.command}`,
|
||||
location: 'DASHBOARD'
|
||||
});
|
||||
|
||||
switch (message.command) {
|
||||
case DashboardCommand.loading:
|
||||
setLoading(message.payload);
|
||||
|
||||
@@ -87,7 +87,7 @@ export class DashboardSettings {
|
||||
}
|
||||
|
||||
public static async getSettings() {
|
||||
Logger.info('DashboardSettings:getSettings:start');
|
||||
Logger.verbose('DashboardSettings:getSettings:start');
|
||||
|
||||
try {
|
||||
const ext = Extension.getInstance();
|
||||
@@ -171,7 +171,7 @@ export class DashboardSettings {
|
||||
lastUpdated: new Date().getTime()
|
||||
} as ISettings;
|
||||
|
||||
Logger.info('DashboardSettings:getSettings:end');
|
||||
Logger.verbose('DashboardSettings:getSettings:end');
|
||||
|
||||
return settings;
|
||||
} catch (error) {
|
||||
@@ -185,7 +185,7 @@ export class DashboardSettings {
|
||||
* @returns
|
||||
*/
|
||||
private static async getDataFiles(): Promise<DataFile[]> {
|
||||
Logger.info('DashboardSettings:getDataFiles:start');
|
||||
Logger.verbose('DashboardSettings:getDataFiles:start');
|
||||
const wsPath = parseWinPath(Folders.getWorkspaceFolder()?.fsPath);
|
||||
const files = Settings.get<DataFile[]>(SETTING_DATA_FILES);
|
||||
const folders = Settings.get<DataFolder[]>(SETTING_DATA_FOLDERS);
|
||||
@@ -231,7 +231,7 @@ export class DashboardSettings {
|
||||
}
|
||||
}
|
||||
|
||||
Logger.info('DashboardSettings:getDataFiles:end');
|
||||
Logger.verbose('DashboardSettings:getDataFiles:end');
|
||||
return clonedFiles;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-4
@@ -1,7 +1,8 @@
|
||||
import { Extension } from './Extension';
|
||||
import { commands, OutputChannel, window } from 'vscode';
|
||||
import { format } from 'date-fns';
|
||||
import { COMMAND_NAME } from '../constants';
|
||||
import { COMMAND_NAME, SETTING_LOGGING } from '../constants';
|
||||
import { Settings } from '.';
|
||||
|
||||
export type LoggerLocation = 'VSCODE' | 'DASHBOARD' | 'PANEL';
|
||||
|
||||
@@ -33,9 +34,19 @@ export class Logger {
|
||||
Logger.getInstance();
|
||||
}
|
||||
|
||||
Logger.channel?.appendLine(
|
||||
`["${type}" - ${format(new Date(), 'HH:mm:ss')}] ${location} | ${message}`
|
||||
);
|
||||
const loggingLevel = Settings.get(SETTING_LOGGING) || 'info';
|
||||
|
||||
const logMessage = `["${type}" - ${format(new Date(), 'HH:mm:ss')}] ${location} | ${message}`;
|
||||
|
||||
if (loggingLevel === 'verbose') {
|
||||
Logger.log(logMessage);
|
||||
} else if (loggingLevel === 'info' && type !== 'VERBOSE') {
|
||||
Logger.log(logMessage);
|
||||
} else if (loggingLevel === 'warning' && (type === 'WARNING' || type === 'ERROR')) {
|
||||
Logger.log(logMessage);
|
||||
} else if (loggingLevel === 'error' && type === 'ERROR') {
|
||||
Logger.log(logMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static warning(message: string, location: LoggerLocation = 'VSCODE'): void {
|
||||
@@ -49,4 +60,8 @@ export class Logger {
|
||||
public static verbose(message: string, location: LoggerLocation = 'VSCODE'): void {
|
||||
Logger.info(message, location, 'VERBOSE');
|
||||
}
|
||||
|
||||
private static log(message: string) {
|
||||
Logger.channel?.appendLine(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export class TaxonomyHelper {
|
||||
* @param options
|
||||
*/
|
||||
public static async get(type: TaxonomyType): Promise<string[] | undefined> {
|
||||
Logger.info(`TaxonomyHelper:get:start:${type}`);
|
||||
Logger.verbose(`TaxonomyHelper:get:start:${type}`);
|
||||
if (!TaxonomyHelper.db) {
|
||||
Logger.info(`TaxonomyHelper:get:db-not-initialized`);
|
||||
return;
|
||||
@@ -86,7 +86,7 @@ export class TaxonomyHelper {
|
||||
if (await TaxonomyHelper.db.exists(tagType)) {
|
||||
taxonomy = await TaxonomyHelper.db.getObject<string[]>(tagType);
|
||||
}
|
||||
Logger.info(`TaxonomyHelper:get:end:${type}`);
|
||||
Logger.verbose(`TaxonomyHelper:get:end:${type}`);
|
||||
return taxonomy;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ export abstract class BaseListener {
|
||||
public static sendMsg(command: DashboardCommand, payload: any) {
|
||||
if (command === DashboardCommand.loading) {
|
||||
const loadingType = payload ? `- ${JSON.stringify(payload)}` : '- Turn off';
|
||||
Logger.info(`Sending message to dashboard: ${command} ${loadingType}`);
|
||||
Logger.verbose(`Sending message to dashboard: ${command} ${loadingType}`);
|
||||
} else {
|
||||
Logger.info(`Sending message to dashboard: ${command}`);
|
||||
Logger.verbose(`Sending message to dashboard: ${command}`);
|
||||
}
|
||||
|
||||
Dashboard.postWebviewMessage({
|
||||
|
||||
@@ -199,9 +199,11 @@ export class SettingsListener extends BaseListener {
|
||||
* Retrieve the settings for the dashboard
|
||||
*/
|
||||
public static async getSettings(clear: boolean = false) {
|
||||
Logger.info(`SettingsListener:getSettings:start - clear: ${clear}`);
|
||||
Logger.verbose(`SettingsListener:getSettings:start - clear: ${clear}`);
|
||||
const settings = await DashboardSettings.get(clear);
|
||||
Logger.info(`SettingsListener:getSettings:end - setting keys: ${Object.keys(settings).length}`);
|
||||
Logger.verbose(
|
||||
`SettingsListener:getSettings:end - setting keys: ${Object.keys(settings).length}`
|
||||
);
|
||||
|
||||
this.sendMsg(DashboardCommand.settings, settings);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ export abstract class BaseListener {
|
||||
commands.executeCommand(command, args);
|
||||
}
|
||||
break;
|
||||
case GeneralCommands.toVSCode.logging.verbose:
|
||||
Logger.verbose(msg.payload.message, msg.payload.location);
|
||||
break;
|
||||
case GeneralCommands.toVSCode.logging.info:
|
||||
Logger.info(msg.payload.message, msg.payload.location);
|
||||
break;
|
||||
@@ -43,7 +46,7 @@ export abstract class BaseListener {
|
||||
* @param data
|
||||
*/
|
||||
public static sendMsg(command: string, payload: any) {
|
||||
Logger.info(`Sending message to webview (panel&dashboard): ${command}`);
|
||||
Logger.verbose(`Sending message to webview (panel&dashboard): ${command}`);
|
||||
|
||||
const extPath = Extension.getInstance().extensionPath;
|
||||
const panel = PanelProvider.getInstance(extPath);
|
||||
|
||||
@@ -65,10 +65,10 @@ export class GitListener {
|
||||
}
|
||||
| undefined
|
||||
> {
|
||||
Logger.info('GitListener:getSettings:start');
|
||||
Logger.verbose('GitListener:getSettings:start');
|
||||
const gitActions = Settings.get<boolean>(SETTING_GIT_ENABLED);
|
||||
if (gitActions) {
|
||||
Logger.info('GitListener:getSettings:end:enabled');
|
||||
Logger.verbose('GitListener:getSettings:end:enabled');
|
||||
return {
|
||||
isGitRepo: gitActions ? await GitListener.isGitRepository() : false,
|
||||
actions: gitActions || false,
|
||||
@@ -81,7 +81,7 @@ export class GitListener {
|
||||
};
|
||||
}
|
||||
|
||||
Logger.info('GitListener:getSettings:end:disabled');
|
||||
Logger.verbose('GitListener:getSettings:end:disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import { Telemetry } from '../helpers/Telemetry';
|
||||
import { GitListener, ModeListener } from '../listeners/general';
|
||||
import { Folders } from '../commands';
|
||||
import { basename } from 'path';
|
||||
import { ignoreMsgCommand } from '../utils';
|
||||
|
||||
export class PanelProvider implements WebviewViewProvider, Disposable {
|
||||
public static readonly viewType = 'frontMatter.explorer';
|
||||
@@ -100,7 +101,9 @@ export class PanelProvider implements WebviewViewProvider, Disposable {
|
||||
this.updateCurrentFile();
|
||||
|
||||
webviewView.webview.onDidReceiveMessage(async (msg) => {
|
||||
Logger.info(`Receiving message from panel: ${msg.command}`);
|
||||
if (!ignoreMsgCommand(msg.command)) {
|
||||
Logger.info(`Receiving message from panel: ${msg.command}`);
|
||||
}
|
||||
|
||||
LocalizationListener.process(msg);
|
||||
FieldsListener.process(msg);
|
||||
|
||||
@@ -6,7 +6,7 @@ import { FolderInfo } from '../../models/PanelSettings';
|
||||
import { Command } from '../Command';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { TagType } from '../TagType';
|
||||
import { Messenger } from '@estruyf/vscode/dist/client';
|
||||
import { Messenger, messageHandler } from '@estruyf/vscode/dist/client';
|
||||
import { EventData } from '@estruyf/vscode/dist/models';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { PanelSettingsAtom } from '../state';
|
||||
@@ -23,6 +23,11 @@ export default function useMessages() {
|
||||
const messageListener = (event: MessageEvent<EventData<any>>) => {
|
||||
const message = event.data;
|
||||
|
||||
messageHandler.send(GeneralCommands.toVSCode.logging.verbose, {
|
||||
message: `Message received: ${message.command}`,
|
||||
location: 'PANEL'
|
||||
});
|
||||
|
||||
switch (message.command) {
|
||||
case Command.metadata:
|
||||
setMetadata(message.payload);
|
||||
|
||||
@@ -77,7 +77,7 @@ export class PagesParser {
|
||||
* Parse all pages in the workspace
|
||||
*/
|
||||
public static async parsePages() {
|
||||
Logger.info('PagesParser:parsePages:start');
|
||||
Logger.verbose('PagesParser:parsePages:start');
|
||||
i18n.clearFiles();
|
||||
Folders.clearCached();
|
||||
const ext = Extension.getInstance();
|
||||
@@ -93,7 +93,7 @@ export class PagesParser {
|
||||
PagesParser.pagesStatusBar.show();
|
||||
|
||||
for (const folder of folderInfo) {
|
||||
Logger.info(`PagesParser::parsePages: Parsing folder ${folder.title} - ${folder.files}`);
|
||||
Logger.verbose(`PagesParser:parsePages: Parsing folder ${folder.title} - ${folder.files}`);
|
||||
for (const file of folder.lastModified) {
|
||||
if (isValidFile(file.fileName)) {
|
||||
try {
|
||||
@@ -140,7 +140,7 @@ export class PagesParser {
|
||||
PagesParser.pagesStatusBar.hide();
|
||||
|
||||
Folders.clearCached();
|
||||
Logger.info('PagesParser:parsePages:end');
|
||||
Logger.verbose('PagesParser:parsePages:end');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { GeneralCommands } from '../constants';
|
||||
|
||||
export const ignoreMsgCommand = (command: string) => {
|
||||
const toIgnore = [
|
||||
GeneralCommands.toVSCode.logging.verbose,
|
||||
GeneralCommands.toVSCode.logging.info,
|
||||
GeneralCommands.toVSCode.logging.warn,
|
||||
GeneralCommands.toVSCode.logging.error
|
||||
];
|
||||
|
||||
return toIgnore.includes(command);
|
||||
};
|
||||
@@ -6,11 +6,13 @@ export * from './fetchWithTimeout';
|
||||
export * from './fieldWhenClause';
|
||||
export * from './flattenObjectKeys';
|
||||
export * from './getLocalizationFile';
|
||||
export * from './ignoreMsgCommand';
|
||||
export * from './mkdirAsync';
|
||||
export * from './readFileAsync';
|
||||
export * from './readdirAsync';
|
||||
export * from './renameAsync';
|
||||
export * from './rmdirAsync';
|
||||
export * from './sentryInit';
|
||||
export * from './sortPages';
|
||||
export * from './unlinkAsync';
|
||||
export * from './writeFileAsync';
|
||||
|
||||
Reference in New Issue
Block a user