Skip to content

Commit

Permalink
feat: zhi-log tests
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Apr 14, 2023
1 parent 977e777 commit 2f8bc59
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions apps/zhi-log/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,58 @@
* questions.
*/

import { describe, test } from "@jest/globals"
import { describe, it } from "@jest/globals"
import Env from "zhi-env"
import LogFactory from "./index"
import LogFactory, { LogLevelEnum } from "./index"

describe("zhi-log", () => {
test("log", () => {
describe("zhiLog", () => {
it("test default log", function () {
const logger = LogFactory.defaultLogger()
logger.debug("This is debug log")
logger.info("This is info log")
logger.error("This is error log")
})

it("test default log env", function () {
const env = new Env(import.meta.env)
const logger = LogFactory.defaultLogger(env)
logger.debug("debug msg")
logger.info("info msg")
logger.error("error msg")
const logger = LogFactory.defaultLogger(env, 4)
logger.debug("This is debug log")
logger.info("This is info log")
logger.error("This is error log")
})

it("test custom sign", function () {
const logger = LogFactory.customSignLogFactory("haha").getLogger()
logger.debug("This is debug log")
logger.info("This is info log")
logger.error("This is error log")
})

it("test default logger", function () {
const logger = LogFactory.customLogFactory().getLogger(undefined, 2)
logger.debug("This is debug log")
logger.info("This is info log")
logger.error("This is error log")
})

it("test custom logger", function () {
const logger = LogFactory.customLogFactory().getLogger("haha")
logger.debug("This is debug log")
logger.info("This is info log")
logger.error("This is error log")
})

it("test custom log level", function () {
const logger = LogFactory.customLogFactory(LogLevelEnum.LOG_LEVEL_DEBUG).getLogger("test")
logger.debug("This is debug log")
logger.info("This is info log")
logger.error("This is error log")
})

it("test custom level and sign", function () {
const logger = LogFactory.customLogFactory(LogLevelEnum.LOG_LEVEL_DEBUG, "my-log").getLogger("test")
logger.debug("This is debug log")
logger.info("This is info log")
logger.error("This is error log")
})
})

0 comments on commit 2f8bc59

Please sign in to comment.