Skip to content

Commit

Permalink
fix: update FUSION_LOG_LEVEL configuration in vite config generation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
odinr authored Apr 29, 2024
1 parent 1d6ca2e commit 491c2e0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .changeset/tricky-carpets-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@equinor/fusion-query": patch
"@equinor/fusion-framework-cli": patch
---

Fixed issue with missing process env `FUSION_LOG_LEVEL`

- added default resolve value when generating base vite configuration
- moved default query log level resolve outside class

fixes: https://github.com/equinor/fusion/issues/343
2 changes: 2 additions & 0 deletions packages/cli/src/lib/vite-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export const createViteConfig = async (
tsconfigPaths(),
viteEnv({
NODE_ENV: env.mode,
FUSION_LOG_LEVEL:
process.env.FUSION_LOG_LEVEL ?? env.mode === 'development' ? '3' : '1',
}),
],
root,
Expand Down
5 changes: 0 additions & 5 deletions packages/cli/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ export default defineConfig({
build: {
outDir: fileURLToPath(new URL('./dist/bin/public', import.meta.url)),
emptyOutDir: true,
// minify: false,
// terserOptions: {
// mangle: false,
// },
},
// mode: 'development',
});
16 changes: 16 additions & 0 deletions packages/utils/query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ subscription.unsubscribe();
query.complete();
```

## Setup

When compiling code the `FUSION_LOG_LEVEL` must be set (depending on build util, example shown for Vite)

`Uncaught ReferenceError: process is not defined`

```ts
defineConfig({
plugins: [
tsconfigPaths(),
viteEnv({
FUSION_LOG_LEVEL: process.env.FUSION_LOG_LEVEL ?? process.env.NODE_ENV === 'development' ? '3' : '1'
}),
]
})

## Advanced Usage

### Queue Operators
Expand Down
18 changes: 9 additions & 9 deletions packages/utils/query/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ export interface ILogger {
createSubLogger(domain: string): ILogger;
}

const defaultLogLevel = process.env.FUSION_LOG_LEVEL
? (Number(process.env.FUSION_LOG_LEVEL) as 0 | 1 | 2 | 3 | 4)
: process.env.NODE_ENV === 'development'
? 3
: 1;

export class ConsoleLogger implements ILogger {
/** - 0-1-2-3 (error-warning-info-debug) if not provided only errors are logged */
public level: 0 | 1 | 2 | 3 | 4;
/** - 0-1-2-3 (off-error-warning-info-debug) if not provided only errors are logged */
public level: 0 | 1 | 2 | 3 | 4 = defaultLogLevel;

/**
* Constructs a new ConsoleLogger instance.
Expand All @@ -55,13 +61,7 @@ export class ConsoleLogger implements ILogger {
constructor(
protected title: string,
protected subtitle?: string,
) {
if (process.env.FUSION_LOG_LEVEL) {
this.level = parseInt(process.env.FUSION_LOG_LEVEL) as 0 | 1 | 2 | 3 | 4;
} else {
this.level = process.env.NODE_ENV === 'development' ? 3 : 1;
}
}
) {}

/**
* Generates the formatted message to log, including the title, subtitle (if any), and the messages provided.
Expand Down

0 comments on commit 491c2e0

Please sign in to comment.