Skip to content

feat: added timestamps to the logger #3

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

Open
wants to merge 3 commits into
base: fix/remove-eslint
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Button from '@/components/Button/Button';
import CMSImageBox from '@/components/ImageBox/CMSImageBox';

import { AnimatedElement } from '@/components/AnimatedComponent/AnimatedComponent';
import { log } from '@/lib/logger';
import type { SanityImage } from '@/lib/sanity.image';
import type { ButtonSchemaType } from '@/schemas/objects/button';
import clsx from 'clsx';
Expand All @@ -26,8 +27,7 @@ export default function CopyAndImage(props: CopyAndImageProps) {
props;

if (!mobileAlignment || !desktopAlignment) {
// eslint-disable-next-line no-console
console.warn(
log.warn(
'@deprecated A CopyAndImage component is using a depricated schema field. Please update the schema.'
);
return <DeprecatedCopyAndImage {...props} />;
Expand Down
4 changes: 2 additions & 2 deletions components/FlexibleContent/Modules/Hero/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import Button from '@/components/Button/Button';
import ScrollButton from '@/components/Button/ScrollButton';
import SplineModel from '@/components/SplineScene/SplineScene';
import { log } from '@/lib/logger';
import type {
HeroSchemaType,
HeroVariantType,
Expand Down Expand Up @@ -41,8 +42,7 @@ export default function Hero(props: HeroSchemaType) {

// TODO - Remove DepricatedHero support when all heros are updated
if (!_variant || !image) {
// eslint-disable-next-line no-console
console.warn(
log.warn(
'@deprecated A Hero component is using a depricated schema field. Please update the schema.'
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { REVALIDATIONS } from '@/lib/constants';
import { log } from '@/lib/logger';
import StatsTiles from './StatsTiles';

async function getData(): Promise<string | null> {
Expand All @@ -21,8 +22,7 @@ async function getData(): Promise<string | null> {
const { nodeCount } = await response.json();
return String(nodeCount);
} catch (err) {
// eslint-disable-next-line no-console
console.error(`internal ${response?.status || ''} error from Data API. Error ${err}`);
log.error(`internal ${response?.status || ''} error from Data API. Error ${err}`);
return null;
}
}
Expand Down
14 changes: 11 additions & 3 deletions lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ import { isProduction } from './env';

class Logger {
static debugEnabled = !isProduction() && process.env.DEBUG_LOG === 'true';

private getTimestamp(): string {
return new Date().toISOString();
}

public debug(message: string, ...args: Array<unknown>) {
if (Logger.debugEnabled) {
console.debug(message, ...args);
console.debug(`[${this.getTimestamp()}] ${message}`, ...args);
}
}
public info(message: string, ...args: Array<unknown>) {
console.info(message, ...args);
console.info(`[${this.getTimestamp()}] ${message}`, ...args);
}
public error(message: string, ...args: Array<unknown>) {
console.error(message, ...args);
console.error(`[${this.getTimestamp()}] ${message}`, ...args);
}
public warn(message: string, ...args: Array<unknown>) {
console.warn(`[${this.getTimestamp()}] ${message}`, ...args);
}
}

Expand Down