Skip to content

Commit

Permalink
Merge pull request #133 from onicagroup/issue/132
Browse files Browse the repository at this point in the history
Fix issue #132 - log level setter
  • Loading branch information
kernwig authored Jun 21, 2022
2 parents 7d6492d + d8e6c6c commit bff0f6e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/types/logger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export declare class Logger {
* The Log Level of this Logger
*/
get level(): LogLevel;
/**
* Change the log level of this Logger
*/
set level(level: LogLevel);
/**
* Log an item at given level.
* Usually better to use the specific function per log level instead.
Expand Down
14 changes: 14 additions & 0 deletions logger/lib/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ describe('Logger', () => {
});
});

test("when set and read log level", () => {
// GIVEN
Logger = require('./logger').Logger;
Logger.initialize({
level: LogLevel.DEBUG,
});
const logger = new Logger("LoggerTest");
expect(logger.level).toEqual(LogLevel.DEBUG);
// WHEN
logger.level = LogLevel.NONE;
// THEN
expect(logger.level).toEqual(LogLevel.NONE);
});

describe('configured for AWS CloudWatch environment', () => {
beforeEach(() => {
process.env.LOG_TO_CLOUDWATCH = 'true';
Expand Down
7 changes: 7 additions & 0 deletions logger/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ export class Logger {
return this.config.level;
}

/**
* Change the log level of this Logger
*/
set level(level: LogLevel) {
this.config.level = level;
}

/**
* Log an item at given level.
* Usually better to use the specific function per log level instead.
Expand Down
2 changes: 1 addition & 1 deletion logger/package-lock.json

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

2 changes: 1 addition & 1 deletion logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sailplane/logger",
"version": "4.0.0",
"version": "4.1.0",
"description": "CloudWatch and serverless-offline friendly logger.",
"keywords": [
"aws",
Expand Down

0 comments on commit bff0f6e

Please sign in to comment.