Skip to content

Commit

Permalink
Util
Browse files Browse the repository at this point in the history
  • Loading branch information
ainsleyclark committed May 6, 2022
1 parent 4cc1db3 commit a9b33db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
14 changes: 11 additions & 3 deletions tests/util/logger.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@

import {Log} from "../../util/logger";
import {Environment} from "../../util/env";



jest.mock('../../util/env', () => jest.fn());

Environment.isProduction = (): boolean => {
return true;
};

describe('Logger', () => {

it('Should be log level: debug in development', () => {
// @ts-ignore
console.log('hello', Environment);

// (Environment.prototype.isProduction as jest.Mock).mockReturnValue('Mocked bar');
it('Should be log level: debug in development', () => {
expect(Log.level).toBe('debug');
});

Expand Down
2 changes: 1 addition & 1 deletion util/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env.config({
* Config represents the environment variables set in the .env file
* used a system configuration for the application.
*/
class Config {
export class Config {
appEnv: string;
appDebug: boolean;
appPort: number;
Expand Down
9 changes: 3 additions & 6 deletions util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ const httpOptions = {
}
return level;
},
meta: true, // Optional: control whether you want to log the meta data about the request (default to true)
msg: 'HTTP {{req.method}} {{req.url}}', // Optional: customize the default logging message. E.g. '{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}'
expressFormat: true, // Use the default Express/morgan request formatting. Enabling this will override any msg if true. Will only output colors with colorize set to true
ignoreRoute: function (req: any, res: any) {
return false;
} // Optional: allows to skip some log messages based on request and/or response
meta: true,
msg: 'HTTP {{req.method}} {{req.url}}',
expressFormat: true,
};

/**
Expand Down

0 comments on commit a9b33db

Please sign in to comment.