Skip to content

Commit

Permalink
feat(typescript): convert core files to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tduyng committed Nov 29, 2021
1 parent 8756e5a commit 0ac21ac
Show file tree
Hide file tree
Showing 21 changed files with 1,120 additions and 785 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.coveralls.yml

# nyc test coverage
.nyc_output
Expand All @@ -25,6 +26,7 @@ coverage

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
build/

# Dependency directories
node_modules
Expand All @@ -37,3 +39,12 @@ jspm_packages
.node_repl_history

.idea


# Yarn 2
.yarn/*
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
45 changes: 45 additions & 0 deletions definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'none'

export type LogInstance = {
level?: LogLevel
time?: Date
namespace?: string
contextId?: string
message?: string
meta?: Record<string, unknown>
data?: unknown
}
export type Output = Pick<LogInstance, 'contextId' | 'meta' | 'data'>

export type NameSpaceConfig = {
regex?: RegExp
level?: number
}

export interface Logger {
trace: LogMethod
debug: LogMethod
info: LogMethod
warn: LogMethod
error: LogMethod
isLevelEnabled(level: string): boolean | undefined
}

export interface OutputAdapter {
(log: LogInstance): void
}

export interface LogMethod {
(contextId: string, message: string, data?: unknown): void
(message: string, data?: unknown): void
}

export interface Internal {
loggers?: Record<string, Logger | undefined>
namespaces?: NameSpaceConfig[]
levels?: LogLevel[]
level?: number
outputs?: OutputAdapter[]
globalContext?: unknown
isEnabled?(namespace: string, index: number): boolean
}
2 changes: 1 addition & 1 deletion examples/example1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ logger.setLevel('debug')
const log = logger('root:testing')
log.debug('sample message', {
foo: 'bar',
})
})
2 changes: 1 addition & 1 deletion examples/example2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ logger.setLevel('debug')
const log = logger('root:testing')
log.debug('ctxId', 'log with predefined context ID', {
foo: 'bar',
})
})
2 changes: 1 addition & 1 deletion examples/example3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ logger.setLevel('debug')
//logger.setOutput(logger.outputs.json)

const log = logger('namespace:subNamespace')
log.debug('ctxId', 'Will be logged',{someData: 'someValue', someData2: 'someValue'})
log.debug('ctxId', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
2 changes: 1 addition & 1 deletion examples/example_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ logger.setGlobalContext({ version: '2.0.0', env: 'dev' })

const log = logger('namespace')

log.warn('message', { someData: 'someValue' })
log.warn('message', { someData: 'someValue' })
2 changes: 1 addition & 1 deletion examples/example_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ logger.setLevel('info')

const log = logger('namespace:subNamespace')

log.warn('message', { someData: 'someValue' })
log.warn('message', { someData: 'someValue' })
2 changes: 1 addition & 1 deletion examples/example_pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ logger.setLevel('debug')
logger.setOutput(logger.outputs.pretty)

const log = logger('namespace:subNamespace')
log.debug('ctxId', 'Will be logged',{someData: 'someValue', someData2: 'someValue'})
log.debug('ctxId', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
1 change: 1 addition & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'prettyoutput'
53 changes: 0 additions & 53 deletions index.d.ts

This file was deleted.

Loading

0 comments on commit 0ac21ac

Please sign in to comment.