Skip to content

Commit 3c543fb

Browse files
committed
fix(pkg): Export LogLevel to satisfy typescript defs
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
1 parent be2ac9e commit 3c543fb

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

index.js

+10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ function createLogger(key, options) {
1414
return new Logger(key, options)
1515
}
1616

17+
const LogLevel = {
18+
trace: 'TRACE'
19+
, debug: 'DEBUG'
20+
, info: 'INFO'
21+
, warn: 'WARN'
22+
, error: 'ERROR'
23+
, fatal: 'FATAL'
24+
}
25+
1726
module.exports = {
1827
createLogger
1928
, setupDefaultLogger
29+
, LogLevel
2030
}

test/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ const index = require('../index.js')
55
const {apiKey, createOptions} = require('./common/index.js')
66

77
test('Index exports are correct', async (t) => {
8-
t.equal(Object.keys(index).length, 2, 'property count is correct')
8+
t.equal(Object.keys(index).length, 3, 'property count is correct')
99
t.match(index, {
1010
createLogger: Function
1111
, setupDefaultLogger: Function
12+
, LogLevel: {
13+
trace: 'TRACE'
14+
, debug: 'DEBUG'
15+
, info: 'INFO'
16+
, warn: 'WARN'
17+
, error: 'ERROR'
18+
, fatal: 'FATAL'
19+
}
1220
}, 'Exported properties are correct')
1321
})
1422

types.d.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
declare module "@logdna/logger" {
22
import { EventEmitter } from 'events';
3-
enum LogLevel {
4-
trace,
5-
debug,
6-
info,
7-
warn,
8-
error,
9-
fatal
3+
4+
export enum LogLevel {
5+
trace = 'TRACE',
6+
debug = 'DEBUG',
7+
info = 'INFO',
8+
warn = 'WARN',
9+
error = 'ERROR',
10+
fatal = 'FATAL'
1011
}
1112

1213
type CustomLevel = string

0 commit comments

Comments
 (0)