-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for OPEN_NEXT_ERROR_LOG_LEVEL
OPEN_NEXT_ERROR_LOG_LEVEL is the minimal error level from which internal errors are logged. It can be set to - "0" / "debug" - "1" / "warn" (default) - "2" / "error"
- Loading branch information
Showing
5 changed files
with
149 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
"@opennextjs/aws": minor | ||
--- | ||
|
||
feat: Add support for OPEN_NEXT_ERROR_LOG_LEVEL | ||
|
||
OPEN_NEXT_ERROR_LOG_LEVEL is the minimal error level from which internal errors are logged. | ||
It can be set to: | ||
|
||
- "0" / "debug" | ||
- "1" / "warn" (default) | ||
- "2" / "error" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import * as logger from "@opennextjs/aws/adapters/logger.js"; | ||
import { | ||
FatalError, | ||
IgnorableError, | ||
RecoverableError, | ||
} from "@opennextjs/aws/utils/error.js"; | ||
import { vi } from "vitest"; | ||
|
||
describe("logger adapter", () => { | ||
describe("Open Next errors", () => { | ||
const debug = vi.spyOn(console, "log").mockImplementation(() => null); | ||
const warn = vi.spyOn(console, "warn").mockImplementation(() => null); | ||
const error = vi.spyOn(console, "error").mockImplementation(() => null); | ||
|
||
beforeEach(() => { | ||
debug.mockClear(); | ||
warn.mockClear(); | ||
error.mockClear(); | ||
}); | ||
|
||
const ignorableError = new IgnorableError("ignorable"); | ||
const recoverableError = new RecoverableError("recoverable"); | ||
const fatalError = new FatalError("fatal"); | ||
|
||
it("default to warn when OPEN_NEXT_ERROR_LOG_LEVEL is undefined", () => { | ||
delete process.env.OPEN_NEXT_ERROR_LOG_LEVEL; | ||
logger.error(ignorableError); | ||
logger.error(recoverableError); | ||
logger.error(fatalError); | ||
expect(debug).not.toHaveBeenCalled(); | ||
expect(warn).toHaveBeenCalledWith("RecoverableError: recoverable"); | ||
expect(error).toHaveBeenCalledWith(fatalError); | ||
}); | ||
|
||
it("OPEN_NEXT_ERROR_LOG_LEVEL is 'debug'/'0'", () => { | ||
process.env.OPEN_NEXT_ERROR_LOG_LEVEL = "0"; | ||
logger.error(ignorableError); | ||
logger.error(recoverableError); | ||
logger.error(fatalError); | ||
expect(debug).toHaveBeenCalledWith("IgnorableError: ignorable"); | ||
expect(warn).toHaveBeenCalledWith("RecoverableError: recoverable"); | ||
expect(error).toHaveBeenCalledWith(fatalError); | ||
process.env.OPEN_NEXT_ERROR_LOG_LEVEL = "debug"; | ||
logger.error(ignorableError); | ||
logger.error(recoverableError); | ||
logger.error(fatalError); | ||
expect(debug).toHaveBeenCalledWith("IgnorableError: ignorable"); | ||
expect(warn).toHaveBeenCalledWith("RecoverableError: recoverable"); | ||
expect(error).toHaveBeenCalledWith(fatalError); | ||
}); | ||
|
||
it("OPEN_NEXT_ERROR_LOG_LEVEL is 'warn'/'1'", () => { | ||
process.env.OPEN_NEXT_ERROR_LOG_LEVEL = "1"; | ||
logger.error(ignorableError); | ||
logger.error(recoverableError); | ||
logger.error(fatalError); | ||
expect(debug).not.toHaveBeenCalled(); | ||
expect(warn).toHaveBeenCalledWith("RecoverableError: recoverable"); | ||
expect(error).toHaveBeenCalledWith(fatalError); | ||
process.env.OPEN_NEXT_ERROR_LOG_LEVEL = "warn"; | ||
logger.error(ignorableError); | ||
logger.error(recoverableError); | ||
logger.error(fatalError); | ||
expect(debug).not.toHaveBeenCalled(); | ||
expect(warn).toHaveBeenCalledWith("RecoverableError: recoverable"); | ||
expect(error).toHaveBeenCalledWith(fatalError); | ||
}); | ||
|
||
it("OPEN_NEXT_ERROR_LOG_LEVEL is 'error'/'2'", () => { | ||
process.env.OPEN_NEXT_ERROR_LOG_LEVEL = "2"; | ||
logger.error(ignorableError); | ||
logger.error(recoverableError); | ||
logger.error(fatalError); | ||
expect(debug).not.toHaveBeenCalled(); | ||
expect(warn).not.toHaveBeenCalled(); | ||
expect(error).toHaveBeenCalledWith(fatalError); | ||
process.env.OPEN_NEXT_ERROR_LOG_LEVEL = "error"; | ||
logger.error(ignorableError); | ||
logger.error(recoverableError); | ||
logger.error(fatalError); | ||
expect(debug).not.toHaveBeenCalled(); | ||
expect(warn).not.toHaveBeenCalled(); | ||
expect(error).toHaveBeenCalledWith(fatalError); | ||
}); | ||
}); | ||
}); |