Skip to content

Commit

Permalink
chore: disable broken logger wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym committed Oct 7, 2024
1 parent fc5f17d commit a10f22e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 51 deletions.
4 changes: 1 addition & 3 deletions apps/staking/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { initLogger } from '@session/util-logger';

const logger = initLogger();
import { logger } from '@session/util-logger';

export default logger;
4 changes: 1 addition & 3 deletions packages/sanity-cms/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { initLogger } from '@session/util-logger';

const logger = initLogger();
import { logger } from '@session/util-logger';

export default logger;
3 changes: 2 additions & 1 deletion packages/ui/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const buttonVariants = cva(
'border border-session-green text-session-green bg-background hover:bg-session-green hover:text-session-black disabled:border-gray-lightest disabled:text-gray-lightest disabled:opacity-100',
'destructive-outline':
'border border-destructive text-destructive bg-background hover:bg-destructive hover:text-destructive-foreground',
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
secondary:
'bg-session-black text-session-white hover:bg-session-white border border-2 border-session-black hover:text-session-black',
ghost: 'hover:bg-accent hover:text-accent-foreground',
'destructive-ghost':
'text-destructive hover:bg-destructive hover:text-destructive-foreground',
Expand Down
47 changes: 28 additions & 19 deletions packages/util-logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { pino } from 'pino';
import { LOG_LEVEL, SessionLogger, type SessionLoggerOptions } from '@session/logger';
import { isProduction } from '@session/util-js/env';

// TODO: look into redoing the logger

// TODO: change this to use the json logger properly
export function constructLoggingArgs(...data: Array<any>) {
return [data.join(' ')];
if (data && typeof data[0] === 'object') {
return data[0];
}
return [data?.join(' ')];
}

const createSessionLoggerOptions = ({
isProd = isProduction(),
}: {
isProd?: boolean;
}): SessionLoggerOptions => ({
globalOptions: {
constructLoggingArgs,
ignoredLevels: isProd ? [LOG_LEVEL.DEBUG, LOG_LEVEL.INFO] : [],
},
});

type InitLoggerOptions = {
isProduction?: boolean;
};
//
// const createSessionLoggerOptions = ({
// isProd = isProduction(),
// }: {
// isProd?: boolean;
// }): SessionLoggerOptions => ({
// globalOptions: {
// constructLoggingArgs,
// ignoredLevels: isProd ? [LOG_LEVEL.DEBUG, LOG_LEVEL.INFO] : [],
// },
// });

export const initLogger = (options?: InitLoggerOptions) => {
// type InitLoggerOptions = {
// isProduction?: boolean;
// };

// export const initLogger = (options?: InitLoggerOptions) => {
export const initLogger = () => {
const logger = pino({
transport: {
target: 'pino-pretty',
Expand All @@ -33,5 +39,8 @@ export const initLogger = (options?: InitLoggerOptions) => {
},
});

return new SessionLogger(logger, createSessionLoggerOptions({ isProd: options?.isProduction }));
// return new SessionLogger(logger, createSessionLoggerOptions({ isProd: options?.isProduction }));
return logger;
};

export const logger = initLogger();
52 changes: 27 additions & 25 deletions packages/util-logger/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { constructLoggingArgs, initLogger } from '../index';
import { getPrivateClassProperty } from '@session/testing/util';
import { LOG_LEVEL } from '@session/logger';

const testLogger = initLogger({ isProduction: false });
// TODO: re-enable once we fix the logger
// const testLogger = initLogger({ isProduction: false });
const testLogger = initLogger();
let mockConsoleDebug: jest.SpyInstance;
let mockConsoleInfo: jest.SpyInstance;
let mockConsoleWarn: jest.SpyInstance;
Expand All @@ -21,23 +21,24 @@ describe('util-logger', () => {
expect(logger).toBeDefined();
});

it('should initialize logger by default with correct level', () => {
const logger = initLogger();
const ignoredLevels = getPrivateClassProperty(logger, 'ignoredLevels');
expect(ignoredLevels).toStrictEqual([]);
});

it('should initialize logger in production with correct level', () => {
const logger = initLogger({ isProduction: true });
const ignoredLevels = getPrivateClassProperty(logger, 'ignoredLevels');
expect(ignoredLevels).toStrictEqual([LOG_LEVEL.DEBUG, LOG_LEVEL.INFO]);
});

it('should initialize logger in development with correct level', () => {
const logger = initLogger({ isProduction: false });
const ignoredLevels = getPrivateClassProperty(logger, 'ignoredLevels');
expect(ignoredLevels).toStrictEqual([]);
});
// TODO: re-enable once we fix the logger
// it('should initialize logger by default with correct level', () => {
// const logger = initLogger();
// const ignoredLevels = getPrivateClassProperty(logger, 'ignoredLevels');
// expect(ignoredLevels).toStrictEqual([]);
// });
//
// it('should initialize logger in production with correct level', () => {
// const logger = initLogger({ isProduction: true });
// const ignoredLevels = getPrivateClassProperty(logger, 'ignoredLevels');
// expect(ignoredLevels).toStrictEqual([LOG_LEVEL.DEBUG, LOG_LEVEL.INFO]);
// });
//
// it('should initialize logger in development with correct level', () => {
// const logger = initLogger({ isProduction: false });
// const ignoredLevels = getPrivateClassProperty(logger, 'ignoredLevels');
// expect(ignoredLevels).toStrictEqual([]);
// });

it('should log at debug level', () => {
testLogger.debug('debug');
Expand All @@ -59,11 +60,12 @@ describe('util-logger', () => {
expect(mockConsoleError).toHaveBeenCalled();
});

it('should init and log', () => {
const logger = initLogger();
logger.initTimedLog();
expect(mockConsoleDebug).toHaveBeenCalled();
});
// TODO: re-enable once we fix the logger
// it('should init and log', () => {
// const logger = initLogger();
// logger.initTimedLog();
// expect(mockConsoleDebug).toHaveBeenCalled();
// });
});

describe('constructLoggingArgs', () => {
Expand Down

0 comments on commit a10f22e

Please sign in to comment.