How to use @adonisjs/logger - 5 common examples

To help you get started, we’ve selected a few @adonisjs/logger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adonisjs / adonis-framework / test / exception-handler.spec.ts View on Github external
test('compute status pages from expression', async (assert) => {
    class AppHandler extends HttpExceptionHandler {
      protected statusPages = {
        '500..509': '500.edge',
      }

      protected context () {
        return { username: 'virk' }
      }
    }

    const appHandler = new AppHandler(new FakeLogger(loggerConfig))
    assert.deepEqual(appHandler.expandedStatusPages, {
      500: '500.edge',
      501: '500.edge',
      502: '500.edge',
      503: '500.edge',
      504: '500.edge',
      505: '500.edge',
      506: '500.edge',
      507: '500.edge',
      508: '500.edge',
      509: '500.edge',
    })
  })
github adonisjs / adonis-framework / test / exception-handler.spec.ts View on Github external
test('report error with custom context', (assert) => {
    class AppHandler extends HttpExceptionHandler {
      protected context () {
        return { username: 'virk' }
      }
    }
    const logger = new FakeLogger(loggerConfig)
    const handler = new AppHandler(logger)

    const ctx = HttpContext.create('/', {}, logger, new Profiler({}).create(''), encryption)
    handler.report(new Exception('bad request', 500, 'E_BAD_REQUEST'), ctx)

    assert.deepEqual(logger.logs.map(({ level, msg, username }) => {
      return { level, msg, username}
    }), [
      {
        level: 50,
        username: 'virk',
        msg: 'E_BAD_REQUEST: bad request',
      },
    ])
  })
github adonisjs / adonis-framework / test / exception-handler.spec.ts View on Github external
test('handle exception by returning html', async (assert) => {
    class AppHandler extends HttpExceptionHandler {
      protected context () {
        return { username: 'virk' }
      }
    }

    class InvalidAuth extends Exception {
    }

    const logger = new FakeLogger(loggerConfig)
    const handler = new AppHandler(logger)

    const ctx = HttpContext.create('/', {}, logger, new Profiler({}).create(''), encryption)
    ctx.request.request.headers = { accept: 'text/html' }

    await handler.handle(new InvalidAuth('bad request'), ctx)
    assert.deepEqual(ctx.response.lazyBody!.args, ['<h1> bad request </h1>', false])
  })
github adonisjs / adonis-lucid / test-helpers / index.ts View on Github external
export function getLogger () {
  return new FakeLogger({
    enabled: true,
    name: 'lucid',
    level: 'info',
  })
}
github adonisjs / adonis-framework / test / cors.spec.ts View on Github external
const server = createServer(async (req, res) => {
        const cors = new Cors(fixture.configureOptions())
        const logger = new Logger({ name: 'adonis', enabled: false, level: 'trace' })

        fixture.configureRequest(req)
        const ctx = HttpContext.create('/', {}, logger, new Profiler({}).create(''), encryption, req, res)
        await cors.handle(ctx)

        if (!ctx.response.hasLazyBody) {
          ctx.response.send(null)
        }

        ctx.response.finish()
      })

@adonisjs/logger

Logger built on top of pino to be used by AdonisJs

MIT
Latest version published 10 days ago

Package Health Score

76 / 100
Full package analysis