Skip to content

Commit

Permalink
fix: provide a logger implementation that only shows debug messages o…
Browse files Browse the repository at this point in the history
…n debug

fixes Unnecessary logging to console #301
  • Loading branch information
danielo515 committed Jul 10, 2024
1 parent d668eac commit 72faa20
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
3 changes: 3 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const context = await esbuild.context({
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
define: {
"process.env.NODE_ENV": JSON.stringify(prod ? "production" : "development"),
},
});

if (prod) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/std/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as A from "fp-ts/Array";
import {
Either,
type Either,
ap,
bimap,
chainW,
Expand All @@ -18,12 +18,12 @@ import {
tryCatch,
tryCatchK,
} from "fp-ts/Either";
import { NonEmptyArray, concatAll as concatAllNea } from "fp-ts/NonEmptyArray";
import { type NonEmptyArray, concatAll as concatAllNea } from "fp-ts/NonEmptyArray";
import * as _O from "fp-ts/Option";
import { Semigroup, concatAll } from "fp-ts/Semigroup";
import { type Semigroup, concatAll } from "fp-ts/Semigroup";
import * as TE from "fp-ts/TaskEither";
import { absurd as _absurd, flow as f, pipe as p } from "fp-ts/function";
import { BaseSchema, Output, ValiError, parse as parseV } from "valibot";
import { type BaseSchema, type Output, ValiError, parse as parseV } from "valibot";
export type Option<T> = _O.Option<T>;
export type { Either, Left, Right } from "fp-ts/Either";
export type { NonEmptyArray } from "fp-ts/NonEmptyArray";
Expand Down
2 changes: 1 addition & 1 deletion src/store/formStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export function makeFormEngine({
},
};
const isVisible = derived(formStore, ($form): E.Either<string, boolean> => {
console.log(
l.debug(
"condition",
field.name,
field.condition && $form.fields[field.condition.dependencyName],
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type Level = "DEBUG" | "INFO" | "WARN" | "ERROR";
function noop() {}
export class Logger {
private static instance: Logger;
#level: Level = "DEBUG";
#level: Level = process.env.NODE_ENV === "development" ? "DEBUG" : "ERROR";
private constructor() {}

static getInstance(): Logger {
Expand Down
4 changes: 3 additions & 1 deletion src/views/components/Form/RenderField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
import MultiSelectField from "./MultiSelectField.svelte";
import ObsidianSelect from "./ObsidianSelect.svelte";
import ObsidianToggle from "./ObsidianToggle.svelte";
import { logger as l } from "src/utils/Logger";
import InputSlider from "./inputSlider.svelte";
export let model: ReturnType<FormEngine["addField"]>;
export let definition: FieldDefinition;
export let formEngine: FormEngine;
export let app: App;
export let logger = l;
$: value = model.value;
$: errors = model.errors;
$: isVisible = model.isVisible;
$: visibleError = derived(model.isVisible, ($isVisible) =>
E.isLeft($isVisible) ? [$isVisible.left] : ([] as string[]),
);
$: console.log($isVisible);
$: logger.debug($isVisible);
</script>

{#if E.isLeft($isVisible)}
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"inlineSources": true,
"resolveJsonModule": true,
"module": "ESNext",
"target": "ES6",
"target": "ES2019",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "node",
Expand Down Expand Up @@ -101,4 +101,4 @@
"src/**/*",
"jest.config.ts"
]
}
}

0 comments on commit 72faa20

Please sign in to comment.