Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update all log levels when a single row is changed #3801

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 30 additions & 81 deletions admin/tabs/cluster/logs/levels/LogLevelDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,90 +4,39 @@
*
* Copyright © 2024 Extremely Heavy Industries Inc.
*/
import {exportFilenameWithDate} from '@xh/hoist/admin/AdminUtils';
import {AppModel} from '@xh/hoist/admin/AppModel';
import * as Col from '@xh/hoist/admin/columns';
import {LogViewerModel} from '@xh/hoist/admin/tabs/cluster/logs/LogViewerModel';
import {LogLevelDialogModel} from '@xh/hoist/admin/tabs/cluster/logs/levels/LogLevelDialogModel';
import {filler, span} from '@xh/hoist/cmp/layout';
import {hoistCmp} from '@xh/hoist/core';
import {FieldSpec} from '@xh/hoist/data';
import {creates, hoistCmp} from '@xh/hoist/core';
import {button} from '@xh/hoist/desktop/cmp/button';
import {textInput} from '@xh/hoist/desktop/cmp/input';
import {panel} from '@xh/hoist/desktop/cmp/panel';
import {restGrid, RestGridConfig} from '@xh/hoist/desktop/cmp/rest';
import {restGrid} from '@xh/hoist/desktop/cmp/rest';
import {Icon} from '@xh/hoist/icon';
import {dialog} from '@xh/hoist/kit/blueprint';

export const logLevelDialog = hoistCmp.factory<LogViewerModel>(({model}) =>
dialog({
title: 'Configure Log Levels',
icon: Icon.gear(),
className: 'xh-admin-app__editor-dialog',
isOpen: model.showLogLevelDialog,
canOutsideClickClose: false,
onClose: () => (model.showLogLevelDialog = false),
item: panel({
item: restGrid({modelConfig: {...modelSpec, readonly: AppModel.readonly}}),
bbar: [
Icon.infoCircle(),
span('Note - log level adjustments apply to all instances in the cluster'),
filler(),
button({
text: 'Close',
icon: Icon.close(),
onClick: () => (model.showLogLevelDialog = false)
})
]
})
})
);

const modelSpec: RestGridConfig = {
persistWith: {localStorageKey: 'xhAdminLogLevelState'},
colChooserModel: true,
enableExport: true,
exportOptions: {filename: exportFilenameWithDate('log-levels')},
store: {
url: 'rest/logLevelAdmin',
fieldDefaults: {disableXssProtection: true},
fields: [
{
name: 'name',
type: 'string',
displayName: 'Package/Class',
required: true
},
{name: 'level', type: 'string', displayName: 'Override', lookupName: 'levels'},
{name: 'defaultLevel', type: 'string', displayName: 'Initial', editable: false},
{name: 'effectiveLevel', type: 'string', displayName: 'Effective', editable: false},
{...(Col.lastUpdated.field as FieldSpec), editable: false},
{...(Col.lastUpdatedBy.field as FieldSpec), editable: false}
]
},
unit: 'log level',
filterFields: ['name'],
columns: [
{field: 'name', width: 400},
{field: 'defaultLevel', width: 110},
{field: 'level', width: 110},
{field: 'effectiveLevel', width: 110},
Col.lastUpdated,
Col.lastUpdatedBy
],
editors: [
{
field: 'name',
formField: {
item: textInput({placeholder: 'com.myapp.MyClassWithLogging (or partial path)'})
}
},
{
field: 'level',
formField: {
info: 'Hint - clear to leave at default while keeping record in place to adjust again later.'
}
},
{field: 'lastUpdated'},
{field: 'lastUpdatedBy'}
]
};
export const logLevelDialog = hoistCmp.factory({
model: creates(LogLevelDialogModel),
render({model}) {
const {parent} = model;
return dialog({
title: 'Configure Log Levels',
icon: Icon.gear(),
className: 'xh-admin-app__editor-dialog',
isOpen: parent.showLogLevelDialog,
canOutsideClickClose: false,
onClose: () => (parent.showLogLevelDialog = false),
item: panel({
item: restGrid(),
bbar: [
Icon.infoCircle(),
span('Note - log level adjustments apply to all instances in the cluster'),
filler(),
button({
text: 'Close',
icon: Icon.close(),
onClick: () => (parent.showLogLevelDialog = false)
})
]
})
});
}
});
103 changes: 103 additions & 0 deletions admin/tabs/cluster/logs/levels/LogLevelDialogModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
*
* Copyright © 2024 Extremely Heavy Industries Inc.
*/
import {exportFilenameWithDate} from '@xh/hoist/admin/AdminUtils';
import {AppModel} from '@xh/hoist/admin/AppModel';
import * as Col from '@xh/hoist/admin/columns/Rest';
import {LogViewerModel} from '@xh/hoist/admin/tabs/cluster/logs/LogViewerModel';
import {HoistModel, managed, lookup, LoadSpec} from '@xh/hoist/core';
import {FieldSpec} from '@xh/hoist/data';
import {textInput} from '@xh/hoist/desktop/cmp/input';
import {RestGridModel} from '@xh/hoist/desktop/cmp/rest';

/**
* @internal
*/
export class LogLevelDialogModel extends HoistModel {
@lookup(LogViewerModel)
parent: LogViewerModel;

@managed
gridModel: RestGridModel;

constructor() {
super();
this.gridModel = this.createGridModel();

// Force a full-reload after any update. Levels cascade, so need to update entire grid
const {store} = this.gridModel;
this.addReaction({
track: () => store.lastLoaded != store.lastUpdated,
run: async isUpdated => {
if (isUpdated) await store.loadAsync();
}
});
}

override async doLoadAsync(loadSpec: LoadSpec) {
this.gridModel.loadAsync(loadSpec);
}

private createGridModel() {
return new RestGridModel({
persistWith: {localStorageKey: 'xhAdminLogLevelState'},
colChooserModel: true,
enableExport: true,
exportOptions: {filename: exportFilenameWithDate('log-levels')},
readonly: AppModel.readonly,
store: {
url: 'rest/logLevelAdmin',
fieldDefaults: {disableXssProtection: true},
fields: [
{
name: 'name',
type: 'string',
displayName: 'Package/Class',
required: true
},
{name: 'level', type: 'string', displayName: 'Override', lookupName: 'levels'},
{name: 'defaultLevel', type: 'string', displayName: 'Initial', editable: false},
{
name: 'effectiveLevel',
type: 'string',
displayName: 'Effective',
editable: false
},
{...(Col.lastUpdated.field as FieldSpec), editable: false},
{...(Col.lastUpdatedBy.field as FieldSpec), editable: false}
]
},
unit: 'log level',
filterFields: ['name'],
columns: [
{field: 'name', width: 400},
{field: 'defaultLevel', width: 110},
{field: 'level', width: 110},
{field: 'effectiveLevel', width: 110},
Col.lastUpdated,
Col.lastUpdatedBy
],
editors: [
{
field: 'name',
formField: {
item: textInput({
placeholder: 'com.myapp.MyClassWithLogging (or partial path)'
})
}
},
{
field: 'level',
formField: {
info: 'Hint - clear to leave at default while keeping record in place to adjust again later.'
}
},
{field: 'lastUpdated'},
{field: 'lastUpdatedBy'}
]
});
}
}
4 changes: 3 additions & 1 deletion desktop/cmp/rest/impl/RestGridToolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {hoistCmp, uses} from '@xh/hoist/core';
import {exportButton} from '@xh/hoist/desktop/cmp/button';
import {recordActionBar} from '@xh/hoist/desktop/cmp/record';
import {toolbar, toolbarSep} from '@xh/hoist/desktop/cmp/toolbar';
import {refreshButton} from '@xh/hoist/desktop/cmp/button';
import {castArray, isEmpty, isFunction} from 'lodash';
import {RestGridModel} from '../RestGridModel';

Expand Down Expand Up @@ -52,7 +53,8 @@ export const restGridToolbar = hoistCmp.factory({
exportButton({
gridModel,
omit: !model.gridModel.enableExport
})
}),
refreshButton({model})
);
}
});
Loading