-
-
Notifications
You must be signed in to change notification settings - Fork 25
Added typings for debug/logging/pretty-stream packages #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import initDebug = require('./lib/debug'); | ||
|
|
||
| export = initDebug; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /** | ||
| * A debug logger function, as returned by the `debug` package. | ||
| */ | ||
| interface Debugger { | ||
| (formatter: unknown, ...args: unknown[]): void; | ||
| enabled: boolean; | ||
| namespace: string; | ||
| /** | ||
| * The selected colour for this namespace. A string in the browser build, | ||
| * a numeric ANSI code under Node (as returned by `selectColor()`). | ||
| */ | ||
| color: string | number; | ||
| log: (...args: unknown[]) => void; | ||
| destroy(): boolean; | ||
| extend(namespace: string, delimiter?: string): Debugger; | ||
| } | ||
|
|
||
| /** | ||
| * A map of custom `%`-formatters registered on the `debug` module. | ||
| */ | ||
| interface Formatters { | ||
| [formatter: string]: (value: unknown) => string; | ||
| } | ||
|
|
||
| /** | ||
| * The underlying `debug` module. | ||
| */ | ||
| interface DebugModule { | ||
| (namespace: string): Debugger; | ||
| enable(namespaces: string): void; | ||
| disable(): string; | ||
| enabled(namespace: string): boolean; | ||
| /** Custom formatters, keyed by the format letter (e.g. `debug.formatters.h`). */ | ||
| formatters: Formatters; | ||
| names: RegExp[]; | ||
| skips: RegExp[]; | ||
| } | ||
|
|
||
| /** | ||
| * Create a debug instance based on your package.json alias/name. | ||
| * | ||
| * The challenge here is to figure out where your package.json exists. | ||
| */ | ||
| interface InitDebug { | ||
| /** | ||
| * @param name - Name of the debug unit. | ||
| */ | ||
| (name: string): Debugger; | ||
|
|
||
| /** | ||
| * The underlying `debug` module. | ||
| */ | ||
| _base: DebugModule; | ||
| } | ||
|
|
||
| declare const initDebug: InitDebug; | ||
|
|
||
| export = initDebug; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import logging = require('./lib/logging'); | ||
|
|
||
| export = logging; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'; | ||
|
|
||
| type Transport = 'stdout' | 'stderr' | 'parent' | 'file' | 'gelf' | 'http' | 'elasticsearch'; | ||
|
|
||
| interface RotationOptions { | ||
| enabled?: boolean; | ||
| period?: string; | ||
| count?: number; | ||
| /** | ||
| * Use the `@tryghost/bunyan-rotating-filestream` library instead of the | ||
| * built-in bunyan rotation. | ||
| */ | ||
| useLibrary?: boolean; | ||
| threshold?: string | number; | ||
| gzip?: boolean; | ||
| rotateExisting?: boolean; | ||
| } | ||
|
|
||
| interface ElasticsearchOptions { | ||
| host?: string; | ||
| username?: string; | ||
| password?: string; | ||
| index?: string; | ||
| pipeline?: string; | ||
| level?: LogLevel; | ||
| } | ||
|
|
||
| interface GelfOptions { | ||
| host?: string; | ||
| port?: number; | ||
| options?: object; | ||
| } | ||
|
|
||
| interface HttpOptions { | ||
| url?: string; | ||
| headers?: Record<string, string>; | ||
| username?: string; | ||
| password?: string; | ||
| level?: LogLevel; | ||
| } | ||
|
|
||
| interface GhostLoggerOptions { | ||
| /** Name of the logger. Appears in raw log files as `{"name": ...}`. */ | ||
| name?: string; | ||
| /** Used for creating the file name. */ | ||
| domain?: string; | ||
| /** Used for creating the file name. */ | ||
| env?: string; | ||
| /** Used to print short or long log. */ | ||
| mode?: string; | ||
| /** The default level of all transports except stderr. */ | ||
| level?: LogLevel; | ||
| /** Whether the body of a request should be logged to the target stream. */ | ||
| logBody?: boolean; | ||
| /** Transports to log to (e.g. `stdout`, `stderr`, `gelf`, `file`). */ | ||
| transports?: Transport[]; | ||
| /** File rotation configuration. */ | ||
| rotation?: RotationOptions; | ||
| /** Path where log files are stored. */ | ||
| path?: string; | ||
| /** | ||
| * Optional filename template for log files. Supports `{env}` and `{domain}` | ||
| * placeholders. Defaults to `{domain}_{env}`. | ||
| */ | ||
| filename?: string; | ||
| /** Elasticsearch transport configuration. */ | ||
| elasticsearch?: ElasticsearchOptions; | ||
| /** Gelf transport configuration. */ | ||
| gelf?: GelfOptions; | ||
| /** HTTP transport configuration. */ | ||
| http?: HttpOptions; | ||
| /** Use local time instead of UTC. */ | ||
| useLocalTime?: boolean; | ||
| /** Optional set of metadata to attach to each log line. */ | ||
| metadata?: Record<string, unknown>; | ||
| } | ||
|
|
||
| /** | ||
| * Ghost's logger class. | ||
| * | ||
| * The logger handles any stdout/stderr logs and streams them into the | ||
| * configured transports. | ||
| */ | ||
| declare class GhostLogger { | ||
| name: string; | ||
| env: string; | ||
| domain: string; | ||
| transports: Transport[]; | ||
| level: LogLevel; | ||
| logBody: boolean; | ||
| mode: string; | ||
| path: string; | ||
| filename: string; | ||
| elasticsearch: ElasticsearchOptions; | ||
| gelf: GelfOptions; | ||
| http: HttpOptions; | ||
| useLocalTime: boolean; | ||
| metadata: Record<string, unknown>; | ||
| rotation: RotationOptions; | ||
| streams: Record<string, { name: string; log: unknown }>; | ||
| serializers: Record<string, (input: any) => unknown>; | ||
|
|
||
| constructor(options?: GhostLoggerOptions); | ||
|
|
||
| /** Sanitize a domain for use in filenames. */ | ||
| sanitizeDomain(domain: string): string; | ||
|
|
||
| /** Replace `{env}`/`{domain}` placeholders in a filename template. */ | ||
| replaceFilenamePlaceholders(template: string): string; | ||
|
|
||
| /** Remove sensitive data (passwords, keys, cookies, ...) from an object. */ | ||
| removeSensitiveData<T extends object>(obj: T): T; | ||
|
|
||
| /** Centralised log function. */ | ||
| log(type: LogLevel, args: unknown[]): void; | ||
|
|
||
| trace(...args: unknown[]): void; | ||
| debug(...args: unknown[]): void; | ||
| info(...args: unknown[]): void; | ||
| warn(...args: unknown[]): void; | ||
| error(...args: unknown[]): void; | ||
| fatal(...args: unknown[]): void; | ||
|
|
||
| /** Create a child logger with some properties bound to every log message. */ | ||
| child(boundProperties: Record<string, unknown>): GhostLogger; | ||
| } | ||
|
|
||
| declare namespace GhostLogger { | ||
| export { | ||
| LogLevel, | ||
| Transport, | ||
| RotationOptions, | ||
| ElasticsearchOptions, | ||
| GelfOptions, | ||
| HttpOptions, | ||
| GhostLoggerOptions, | ||
| }; | ||
| } | ||
|
|
||
| export = GhostLogger; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import GhostLogger = require('./GhostLogger'); | ||
|
|
||
| /** | ||
| * A pre-configured `GhostLogger` instance (built from `loggingrc` if present), | ||
| * with the `GhostLogger` class attached for creating additional instances. | ||
| */ | ||
| declare const logging: GhostLogger & { | ||
| GhostLogger: typeof GhostLogger; | ||
| }; | ||
|
|
||
| declare namespace logging { | ||
| export type LogLevel = GhostLogger.LogLevel; | ||
| export type Transport = GhostLogger.Transport; | ||
| export type RotationOptions = GhostLogger.RotationOptions; | ||
| export type ElasticsearchOptions = GhostLogger.ElasticsearchOptions; | ||
| export type GelfOptions = GhostLogger.GelfOptions; | ||
| export type HttpOptions = GhostLogger.HttpOptions; | ||
| export type GhostLoggerOptions = GhostLogger.GhostLoggerOptions; | ||
| } | ||
|
|
||
| export = logging; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import PrettyStream = require('./lib/PrettyStream'); | ||
|
|
||
| export = PrettyStream; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Transform, TransformOptions } from 'stream'; | ||
|
|
||
| interface PrettyStreamOptions extends TransformOptions { | ||
| /** | ||
| * Controls how much detail is printed. Use `'long'` to include the | ||
| * pretty-printed request/error body, anything else prints the short form. | ||
| * @default 'short' | ||
| */ | ||
| mode?: string; | ||
| } | ||
|
|
||
| /** | ||
| * A Bunyan-compatible transform stream that turns raw JSON log records into | ||
| * human-readable, colourised output. | ||
| */ | ||
| declare class PrettyStream extends Transform { | ||
| mode: string; | ||
|
|
||
| constructor(options?: PrettyStreamOptions); | ||
| } | ||
|
|
||
| export = PrettyStream; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.