Skip to content

Commit

Permalink
Added logging system
Browse files Browse the repository at this point in the history
  • Loading branch information
mligtenberg committed Dec 21, 2024
1 parent 07a7475 commit e9397ab
Show file tree
Hide file tree
Showing 28 changed files with 428 additions and 34 deletions.
4 changes: 2 additions & 2 deletions apps/servicebus-browser-app/src/app/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const rendererAppPort = 4200;
export const rendererAppName = 'servicebus-browser'; // options.name.split('-')[0] + '-web'
export const electronAppName = 'servicebus-browser';
export const rendererAppName = 'Servicebus Browser'; // options.name.split('-')[0] + '-web'
export const electronAppName = 'Servicebus Browser';
export const updateServerUrl = 'https://deployment-server-url.com'; // TODO: insert your update server url here
14 changes: 13 additions & 1 deletion apps/servicebus-browser-app/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import SquirrelEvents from './app/events/squirrel.events';
import ElectronEvents from './app/events/electron.events';
import UpdateEvents from './app/events/update.events';
import { app, BrowserWindow } from 'electron';
import App from './app/app';
import { installExtension, REDUX_DEVTOOLS } from 'electron-devtools-installer';



export default class Main {
static initialize() {
Expand Down Expand Up @@ -32,3 +34,13 @@ Main.initialize();
// bootstrap app
Main.bootstrapApp();
Main.bootstrapAppEvents();

if (App.isDevelopmentMode()) {
App.application.whenReady().then(() => {
installExtension(REDUX_DEVTOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));

App.mainWindow.webContents.openDevTools();
});
}
4 changes: 1 addition & 3 deletions apps/servicebus-browser-frontend/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@

@if (logsOpened()) {
<div class="logs-content">
<p-scrollPanel>
<pre>tempt text this will be replaced by actual logs in a logs component</pre>
</p-scrollPanel>
<sbb-logs-list [logs]="logs()"></sbb-logs-list>
</div>
}
</div>
Expand Down
10 changes: 7 additions & 3 deletions apps/servicebus-browser-frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Component, signal } from '@angular/core';
import { Component, inject, signal } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Button } from 'primeng/button';
import { Splitter } from 'primeng/splitter';
import { PrimeTemplate } from 'primeng/api';
import { Menubar } from 'primeng/menubar';
import { ScrollPanel } from 'primeng/scrollpanel';
import { Tab, TabList, Tabs } from 'primeng/tabs';
import { LogsListComponent } from '@service-bus-browser/logs-components';
import { Store } from '@ngrx/store';
import { LogsSelectors } from '@service-bus-browser/logs-store';

@Component({
imports: [
RouterModule,
Button,
LogsListComponent,
Splitter,
PrimeTemplate,
Menubar,
Expand Down Expand Up @@ -55,8 +57,10 @@ export class AppComponent {
],
},
];
store = inject(Store);

logsOpened = signal(false);
logs = this.store.selectSignal(LogsSelectors.selectLogs);

toggleLogs() {
this.logsOpened.update((value) => !value);
Expand Down
14 changes: 13 additions & 1 deletion apps/servicebus-browser-frontend/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { ApplicationConfig, isDevMode, provideZoneChangeDetection } from '@angular/core';
import { provideRouter, withHashLocation } from '@angular/router';
import { appRoutes } from './app.routes';
import { providePrimeNG } from 'primeng/config';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { theme } from './theme';
import { provideLogsState } from '@service-bus-browser/logs-store';
import { provideStore } from '@ngrx/store';
import { provideStoreDevtools } from '@ngrx/store-devtools';

export const appConfig: ApplicationConfig = {
providers: [
Expand All @@ -21,5 +24,14 @@ export const appConfig: ApplicationConfig = {
// config
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(appRoutes, withHashLocation()),
provideLogsState(),

// ngrx
provideStore(),
provideStoreDevtools({
maxAge: 25,
logOnly: !
isDevMode(),
}),
],
};
2 changes: 1 addition & 1 deletion apps/servicebus-browser-frontend/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>servicebus-browser-frontend</title>
<title>Servicebus Browser</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
Expand Down
7 changes: 7 additions & 0 deletions libs/logs/components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @service-bus-browser/logs-components

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test @service-bus-browser/logs-components` to execute the unit tests.
34 changes: 34 additions & 0 deletions libs/logs/components/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const nx = require('@nx/eslint-plugin');
const baseConfig = require('../../../eslint.config.js');

module.exports = [
...baseConfig,
...nx.configs['flat/angular'],
...nx.configs['flat/angular-template'],
{
files: ['**/*.ts'],
rules: {
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'sbb-logs',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'sbb-logs',
style: 'kebab-case',
},
],
},
},
{
files: ['**/*.html'],
// Override or add rules here
rules: {},
},
];
21 changes: 21 additions & 0 deletions libs/logs/components/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
displayName: '@service-bus-browser/logs-components',
preset: '../../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: '../../../coverage/libs/logs/components',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
20 changes: 20 additions & 0 deletions libs/logs/components/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@service-bus-browser/logs-components",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/logs/components/src",
"prefix": "sbb-logs",
"projectType": "library",
"tags": [],
"targets": {
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/logs/components/jest.config.ts"
}
},
"lint": {
"executor": "@nx/eslint:lint"
}
}
}
1 change: 1 addition & 0 deletions libs/logs/components/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/logs-list/logs-list.component'
3 changes: 3 additions & 0 deletions libs/logs/components/src/lib/log-line/log-line.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pre
[style.--color]="logLineColor()"
>{{logLine().loggedAt | date:'YYYY-MM-dd HH:mm:ss' }} - {{logLine().severity}}: {{logLine().message}}</pre>
7 changes: 7 additions & 0 deletions libs/logs/components/src/lib/log-line/log-line.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pre {
--color: 'inherit';
margin: 0;
font-size: 12px;
padding: 4px 1rem;
color: var(--color);
}
28 changes: 28 additions & 0 deletions libs/logs/components/src/lib/log-line/log-line.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Component, input, computed } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LogLine } from '@service-bus-browser/logs-contracts';

@Component({
selector: 'sbb-logs-log-line',
imports: [CommonModule],
templateUrl: './log-line.component.html',
styleUrl: './log-line.component.scss',
})
export class LogLineComponent {
logLine = input.required<LogLine>();
logLineColor = computed<string>(() => {
const logLevel = this.logLine().severity;
switch (logLevel) {
case 'info':
return 'var(--p-blue-400)';
case 'warn':
return 'var(--p-amber-500)';
case 'error':
return 'var(--p-red-400)';
case 'critical':
return 'var(--p-red-900)';
default:
return 'var(--p-slate-400)';
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p-virtual-scroller
[items]="logs()"
[itemSize]="20"
scrollHeight="20rem"
>
<ng-template #item let-item let-options="options">
<sbb-logs-log-line [logLine]="item" [ngClass]="{'odd': options.index % 2 === 1}"></sbb-logs-log-line>
</ng-template>
</p-virtual-scroller>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sbb-logs-log-line {
display: block;
height: 20px;

&.odd {
background: var(--p-surface-100);
}
}
15 changes: 15 additions & 0 deletions libs/logs/components/src/lib/logs-list/logs-list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, input } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LogLine } from '@service-bus-browser/logs-contracts';
import { Scroller } from 'primeng/scroller';
import { LogLineComponent } from '../log-line/log-line.component';

@Component({
selector: 'sbb-logs-list',
imports: [CommonModule, Scroller, LogLineComponent],
templateUrl: './logs-list.component.html',
styleUrl: './logs-list.component.scss',
})
export class LogsListComponent {
logs = input.required<LogLine[]>();
}
6 changes: 6 additions & 0 deletions libs/logs/components/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';

setupZoneTestEnv({
errorOnUnknownElements: true,
errorOnUnknownProperties: true,
});
28 changes: 28 additions & 0 deletions libs/logs/components/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "es2022",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../../tsconfig.base.json",
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
17 changes: 17 additions & 0 deletions libs/logs/components/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": []
},
"exclude": [
"src/**/*.spec.ts",
"src/test-setup.ts",
"jest.config.ts",
"src/**/*.test.ts"
],
"include": ["src/**/*.ts"]
}
16 changes: 16 additions & 0 deletions libs/logs/components/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"target": "es2016",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
3 changes: 2 additions & 1 deletion libs/logs/contract/src/lib/log-line.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type LogLineSeverity = 'verbose' | 'info' | 'warn' | 'error' | 'critical';
export interface LogLine {
severity: 'verbose' | 'info' | 'warn' | 'error' | 'critical';
severity: LogLineSeverity;
message: string;
loggedAt: Date;
context?: any;
Expand Down
14 changes: 14 additions & 0 deletions libs/logs/store/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
import { EnvironmentProviders, Provider } from '@angular/core';
import { provideState } from '@ngrx/store';
import { logsFeature } from './lib/logs.store';

export * as LogsActions from './lib/logs.actions';
export * as LogsSelectors from './lib/logs.selectors';

export function provideLogsState(): (
| Provider
| EnvironmentProviders
)[] {
return [
provideState(logsFeature),
];
}
7 changes: 5 additions & 2 deletions libs/logs/store/src/lib/logs.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createFeatureSelector } from '@ngrx/store';
import { createFeatureSelector, createSelector } from '@ngrx/store';
import { featureKey, LogsState } from './logs.store';

const featureSelector = createFeatureSelector<LogsState>(featureKey);

export const selectLogs = featureSelector;
export const selectLogs = createSelector(
featureSelector,
(state) => state.logs
)
Loading

0 comments on commit e9397ab

Please sign in to comment.