Skip to content

Commit

Permalink
fix(pkg): Export LogLevel to satisfy typescript defs
Browse files Browse the repository at this point in the history
Even though this project isn't ESM or typescript, we support a
definitions file for it. In it, we define `LogLevel` as an enum, but
it's not officially exported as such. This commit fixes the typescript
definition to export that enum, as well as export it from the CommonJS
entrypoint.

Fixes: #47
  • Loading branch information
darinspivey committed Aug 16, 2024
1 parent be2ac9e commit 3c543fb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ function createLogger(key, options) {
return new Logger(key, options)
}

const LogLevel = {
trace: 'TRACE'
, debug: 'DEBUG'
, info: 'INFO'
, warn: 'WARN'
, error: 'ERROR'
, fatal: 'FATAL'
}

module.exports = {
createLogger
, setupDefaultLogger
, LogLevel
}
10 changes: 9 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ const index = require('../index.js')
const {apiKey, createOptions} = require('./common/index.js')

test('Index exports are correct', async (t) => {
t.equal(Object.keys(index).length, 2, 'property count is correct')
t.equal(Object.keys(index).length, 3, 'property count is correct')
t.match(index, {
createLogger: Function
, setupDefaultLogger: Function
, LogLevel: {
trace: 'TRACE'
, debug: 'DEBUG'
, info: 'INFO'
, warn: 'WARN'
, error: 'ERROR'
, fatal: 'FATAL'
}
}, 'Exported properties are correct')
})

Expand Down
15 changes: 8 additions & 7 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
declare module "@logdna/logger" {
import { EventEmitter } from 'events';
enum LogLevel {
trace,
debug,
info,
warn,
error,
fatal

export enum LogLevel {
trace = 'TRACE',
debug = 'DEBUG',
info = 'INFO',
warn = 'WARN',
error = 'ERROR',
fatal = 'FATAL'
}

type CustomLevel = string
Expand Down

0 comments on commit 3c543fb

Please sign in to comment.