Only display client logging on the browser
This commit is contained in:
parent
75de7c5f2a
commit
7eb7495537
|
@ -10,7 +10,7 @@ import { getLogger } from "helpers/logger";
|
||||||
config({ path: resolve(process.cwd(), ".env.local") });
|
config({ path: resolve(process.cwd(), ".env.local") });
|
||||||
|
|
||||||
const LOCAL_DATA_FOLDER = `${process.cwd()}/public/local-data`;
|
const LOCAL_DATA_FOLDER = `${process.cwd()}/public/local-data`;
|
||||||
const logger = getLogger("💽 [Local Data]");
|
const logger = getLogger("💽 [Local Data]", "server");
|
||||||
|
|
||||||
const writeLocalData = (name: LocalDataFile, localData: unknown) => {
|
const writeLocalData = (name: LocalDataFile, localData: unknown) => {
|
||||||
const path = `${LOCAL_DATA_FOLDER}/${name}.json`;
|
const path = `${LOCAL_DATA_FOLDER}/${name}.json`;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { filterDefined } from "helpers/asserts";
|
||||||
import { getLogger } from "helpers/logger";
|
import { getLogger } from "helpers/logger";
|
||||||
|
|
||||||
const OUTPUT_FOLDER = `${process.cwd()}/src/graphql`;
|
const OUTPUT_FOLDER = `${process.cwd()}/src/graphql`;
|
||||||
const logger = getLogger("💽 [ICU to TS]");
|
const logger = getLogger("💽 [ICU to TS]", "server");
|
||||||
|
|
||||||
const icuToTypescript = () => {
|
const icuToTypescript = () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
|
|
@ -1,13 +1,29 @@
|
||||||
|
type LoggerMode = "both" | "client" | "server";
|
||||||
|
|
||||||
|
const isServer = typeof window === "undefined";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
export const getLogger = (prefix: string) => ({
|
export const getLogger = (prefix: string, mode: LoggerMode = "client") => {
|
||||||
error: (message?: unknown, ...optionalParams: unknown[]) =>
|
if ((mode === "client" && isServer) || (mode === "server" && !isServer)) {
|
||||||
console.error(prefix, message, ...optionalParams),
|
return {
|
||||||
warn: (message?: unknown, ...optionalParams: unknown[]) =>
|
error: () => null,
|
||||||
console.warn(prefix, message, ...optionalParams),
|
warn: () => null,
|
||||||
log: (message?: unknown, ...optionalParams: unknown[]) =>
|
log: () => null,
|
||||||
console.log(prefix, message, ...optionalParams),
|
info: () => null,
|
||||||
info: (message?: unknown, ...optionalParams: unknown[]) =>
|
debug: () => null,
|
||||||
console.info(prefix, message, ...optionalParams),
|
};
|
||||||
debug: (message?: unknown, ...optionalParams: unknown[]) =>
|
}
|
||||||
console.debug(prefix, message, ...optionalParams),
|
|
||||||
});
|
return {
|
||||||
|
error: (message?: unknown, ...optionalParams: unknown[]) =>
|
||||||
|
console.error(prefix, message, ...optionalParams),
|
||||||
|
warn: (message?: unknown, ...optionalParams: unknown[]) =>
|
||||||
|
console.warn(prefix, message, ...optionalParams),
|
||||||
|
log: (message?: unknown, ...optionalParams: unknown[]) =>
|
||||||
|
console.log(prefix, message, ...optionalParams),
|
||||||
|
info: (message?: unknown, ...optionalParams: unknown[]) =>
|
||||||
|
console.info(prefix, message, ...optionalParams),
|
||||||
|
debug: (message?: unknown, ...optionalParams: unknown[]) =>
|
||||||
|
console.debug(prefix, message, ...optionalParams),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue