Skip to content

Commit bd6812d

Browse files
author
=
committed
refactor names
1 parent b5b84da commit bd6812d

File tree

7 files changed

+35
-37
lines changed

7 files changed

+35
-37
lines changed

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ yarn add @nolawnchairs/logger
1616

1717
As opposed to v2, there is more boilerplate to configure, since we now provide multiple logging environments that can each write to multiple output streams.
1818

19-
Set up your logging environments using the `init` method. The `providers.globalLoggers` object must contain one object where the key is any unique name you like (it's how the internal registry identifies it), and the value is a function that returns the configuration for this logger:
19+
Set up your logging environments using the `init` method. The `providers.globalLoggers` object must contain at least one object that defines the function providing the configuration for this logger:
2020

2121
```javascript
2222
Log.init({
@@ -35,9 +35,7 @@ Log.init({
3535
})
3636
```
3737

38-
In the above example, we define a single `globalLogger`. The name we give this logger is `development`, and it returns a `LoggerConfigInstance` object. Here, the `enabled` key is set based on whether or not we're in development mode, we set the `level` to `DEBUG`, set a serialization strategy (which dictates how non-scalar values are treated when printing), and an array of `LogWriter` instances that define where the logging output goes.
39-
40-
To log, we simply call the desired level with a message:
38+
In the above example, we define a single `globalLogger`. The name we give this logger is `development`, and it returns a `LoggerInstanceConfig` object. Here, the `enabled` key is set based on whether or not we're in development mode, we set the `level` to `DEBUG`, set a serialization strategy (which dictates how non-scalar values are treated when printing), and an array of `LogWriter` instances that define where the logging output goes.
4139

4240

4341

@@ -72,7 +70,7 @@ Log.init({
7270
})
7371
```
7472

75-
In this example, we set `enabled` to true, but set the `level` dependent on the `NODE_ENV` value. Instead of a single `LogWriter`, we specify two - one for the console, and one that logs to a file. Note that we're using a `formatProvider` to write monochrome, since we don't normally want ANSI colors present in our disk logs.
73+
In this example, we set `enabled` to true, but set the `level` dependent on the `NODE_ENV` value. Instead of a single `LogWriter`, we specify two - one for the console, and one that logs to a file. Note that we're using a `formatProvider` to write monochrome, since we normally don't want ANSI colors present in our disk logs.
7674

7775
Creating a Feature Logger is simple. We call the `forFeature` method on the main `Log` interface as such:
7876

@@ -117,10 +115,10 @@ Configuration is set in the `Log.init()` method, and has the following structure
117115
global: LoggerGlobalConfig
118116
providers: {
119117
globalLoggers: {
120-
yourLoggername: () => LoggerConfigInstance
121-
anotherLogger: () => LoggerConfigInstance
118+
yourLoggername: () => LoggerInstanceConfig
119+
anotherLogger: () => LoggerInstanceConfig
122120
}
123-
featureLogger: () => LoggerConfigInstance
121+
featureLogger: () => LoggerInstanceConfig
124122
}
125123
}
126124
```
@@ -135,23 +133,23 @@ The following values can be set to the `global` object, and will provide default
135133
| `serializationStrategy` | `ObjectSerializationStrategy` | How non-scalar values will be printed. Defaults to `INSPECT` ||
136134
| `inspectionDepth` | number | The depth of serialization when using the `INSPECT` strategy. Defaults to `3` ||
137135
| `inspectionColor` | boolean | Used in the `INSPECT` strategy, governs whether or not to color the inspected object ||
138-
| `formatter` | `FormatProvider` | Defines a custom formatter for all `LogWriters` for this logger. Note that writers can override this setting with their own formatting ||
136+
| `formatter` | `FormatProvider` | Defines a custom formatter for each `LogWriters` attached this logger. Note that writers may override this with their own formatter ||
139137

140138

141139
---
142140

143-
### `interface` LoggerConfigInstance
141+
### `interface` LoggerInstanceConfig
144142

145143
Each individial logger you define must be configured with the following properties.
146144

147145

148146
| Property | Type | Description | Required |
149147
| ----------- | ----------- | -------- | :--------: |
150148
| `enabled` | boolean | Whether this logger will produce data | ✔️ |
151-
| `level` | `LogLevel or number` | The level this logger will adhere to. Use a `LogLevel` enum value or an or'ed mask of multiple levels to use in unison<sup>1</sup> | ✔️ |
152-
| `writers` | `LogWriter[]` | An array of `LogWriter` instances to use with this logger |✔️|
149+
| `level` | `LogLevel` | The level to which this logger will adhere. Use a `LogLevel` enum value or an `or`'ed bitmask of multiple levels to use in unison<sup>1</sup> | ✔️ |
150+
| `writers` | `LogWriter[]` | An array of `LogWriter` instances this logger will use |✔️|
153151

154-
In addition to the above properties, the `LoggerConfigInstance` will accept any of the properties defined in `LoggerGlobalConfig`, which will override any default values you set in `global`.
152+
In addition to the above properties, the `LoggerInstanceConfig` will accept any of the properties defined in `LoggerGlobalConfig`, which will override any default values you set in `global`.
155153

156154

157155
#### Notes

index.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export declare class LogWriter {
7474
get formatterProvider(): FormatProvider;
7575
write(value: string): Promise<void>;
7676
}
77-
export interface LoggerConfigInstance extends LoggerGlobalConfig {
77+
export interface LoggerInstanceConfig extends LoggerGlobalConfig {
7878
enabled: boolean;
7979
level: LogLevel | number;
8080
writers: LogWriter[];
@@ -84,7 +84,7 @@ export declare enum ObjectSerializationStrategy {
8484
JSON = 1,
8585
INSPECT = 2
8686
}
87-
export declare type LoggerConfigProvider = (value: string) => LoggerConfigInstance;
87+
export declare type LoggerInstanceConfigProvider = (value: string) => LoggerInstanceConfig;
8888
export interface LoggerGlobalConfig {
8989
eol?: string;
9090
formatter?: FormatProvider;
@@ -95,8 +95,8 @@ export interface LoggerGlobalConfig {
9595
export interface LoggerConfig {
9696
global?: LoggerGlobalConfig;
9797
providers: {
98-
globalLoggers: Record<string, LoggerConfigProvider>;
99-
featureLogger?: LoggerConfigProvider;
98+
globalLoggers: Record<string, LoggerInstanceConfigProvider>;
99+
featureLogger?: LoggerInstanceConfigProvider;
100100
};
101101
}
102102
export interface Logger {
@@ -108,15 +108,15 @@ export interface Logger {
108108
}
109109
declare class LoggerDefault implements Logger {
110110
init(config: LoggerConfig): void;
111-
forFeature(name: string, config?: LoggerConfigInstance): Logger;
111+
forFeature(name: string, config?: LoggerInstanceConfig): Logger;
112112
debug(message: any, ...args: any[]): void;
113113
info(message: any, ...args: any[]): void;
114114
warn(message: any, ...args: any[]): void;
115115
error(message: any, ...args: any[]): void;
116116
fatal(message: any, ...args: any[]): void;
117117
}
118118
export declare type LoggerProperties = LoggerGlobalConfig & {
119-
config: LoggerConfigInstance;
119+
config: LoggerInstanceConfig;
120120
meta?: string;
121121
};
122122
declare const defaultLogger: LoggerDefault;

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module.exports = {
88
FormatProvider,
99
AnsiColors,
1010
LoggerConfig,
11-
LoggerConfigInstance,
11+
LoggerInstanceConfig,
1212
LoggerGlobalConfig,
13-
LoggerConfigProvider,
13+
LoggerInstanceConfigProvider,
1414
ObjectSerializationStrategy,
1515
LEVELS_ALL,
1616
} = require('./lib/index')

src/Config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FormatProvider } from './Format'
33
import { LogLevel } from './LogLevel'
44
import { LogWriter } from './Writer'
55

6-
export type LoggerConfigProvider = (value: string) => LoggerConfigInstance
6+
export type LoggerInstanceConfigProvider = (value: string) => LoggerInstanceConfig
77

88
export interface LoggerGlobalConfig {
99
eol?: string
@@ -16,12 +16,12 @@ export interface LoggerGlobalConfig {
1616
export interface LoggerConfig {
1717
global?: LoggerGlobalConfig
1818
providers: {
19-
globalLoggers: Record<string, LoggerConfigProvider>
20-
featureLogger?: LoggerConfigProvider
19+
globalLoggers: Record<string, LoggerInstanceConfigProvider>
20+
featureLogger?: LoggerInstanceConfigProvider
2121
}
2222
}
2323

24-
export interface LoggerConfigInstance extends LoggerGlobalConfig {
24+
export interface LoggerInstanceConfig extends LoggerGlobalConfig {
2525
enabled: boolean
2626
level: LogLevel | number
2727
writers: LogWriter[]

src/Format.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import { inspect } from 'util'
33
import { vsprintf } from 'sprintf-js'
4-
import { ObjectSerializationStrategy, LoggerConfigInstance } from './Config'
4+
import { ObjectSerializationStrategy, LoggerInstanceConfig } from './Config'
55
import { LogLevel, LogLevelEmoji } from './LogLevel'
66

77
export interface LogEntry {
@@ -47,7 +47,7 @@ const LEVEL_META: LevelMeta = {
4747
[LogLevel.FATAL]: ['FATAL', AnsiColors.BG_BRIGHT_RED, LogLevelEmoji.FATAL],
4848
}
4949

50-
const serialziers: Record<ObjectSerializationStrategy, (value: any, props: LoggerConfigInstance) => string> = {
50+
const serialziers: Record<ObjectSerializationStrategy, (value: any, props: LoggerInstanceConfig) => string> = {
5151
[ObjectSerializationStrategy.OMIT]: () => '',
5252
[ObjectSerializationStrategy.INSPECT]: (value, props) => inspect(value, false, props.inspectionDepth, props.inspectionColor),
5353
[ObjectSerializationStrategy.JSON]: value => JSON.stringify(value)
@@ -59,7 +59,7 @@ export type FormatProvider = (e: LogEntry) => string
5959
export class TextBuilder {
6060
private message: string
6161
private args: any[] = []
62-
constructor(message: any, args: any[], readonly config: LoggerConfigInstance) {
62+
constructor(message: any, args: any[], readonly config: LoggerInstanceConfig) {
6363
this.args = args
6464
if (typeof message === 'string') {
6565
this.message = message

src/Log.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { LoggerConfig, LoggerConfigInstance, LoggerConfigProvider, LoggerGlobalConfig, ObjectSerializationStrategy } from './Config'
2+
import { LoggerConfig, LoggerInstanceConfig, LoggerInstanceConfigProvider, LoggerGlobalConfig, ObjectSerializationStrategy } from './Config'
33
import { FormatProvider, Formatters, TextBuilder } from './Format'
44
import { LogLevel } from './LogLevel'
55
import { mergeOptions } from './Util'
@@ -24,7 +24,7 @@ const defaultConfig: LoggerGlobalConfig = {
2424
class LoggerDefault implements Logger {
2525

2626
private globalConfig: LoggerGlobalConfig = {}
27-
private featureLoggerTemplate: LoggerConfigProvider
27+
private featureLoggerTemplate: LoggerInstanceConfigProvider
2828

2929
init(config: LoggerConfig) {
3030
if (!config)
@@ -50,8 +50,8 @@ class LoggerDefault implements Logger {
5050
}
5151
}
5252

53-
forFeature(name: string, config?: LoggerConfigInstance): LogImpl {
54-
let loggerConfig: LoggerConfigInstance
53+
forFeature(name: string, config?: LoggerInstanceConfig): LogImpl {
54+
let loggerConfig: LoggerInstanceConfig
5555
if (!config) {
5656
if (!this.featureLoggerTemplate)
5757
throw new Error(`Named logger for '${name}' could not be initialized. No default configuration found`)
@@ -90,13 +90,13 @@ class LoggerDefault implements Logger {
9090
}
9191

9292
type LoggerProperties = {
93-
config: LoggerConfigInstance
93+
config: LoggerInstanceConfig
9494
meta?: string
9595
}
9696

9797
class LogImpl implements Logger {
9898

99-
private config: LoggerConfigInstance
99+
private config: LoggerInstanceConfig
100100
private eol: string
101101
private formatter: FormatProvider
102102
private meta?: string

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Log } from './Log'
2-
import { LoggerConfig, LoggerConfigInstance, LoggerGlobalConfig, LoggerConfigProvider, ObjectSerializationStrategy } from './Config'
2+
import { LoggerConfig, LoggerInstanceConfig, LoggerGlobalConfig, LoggerInstanceConfigProvider, ObjectSerializationStrategy } from './Config'
33
import { Formatters, FormatProvider, LogEntry, AnsiColors } from './Format'
44
import { LogLevel, LogLevelEmoji } from './LogLevel'
55
import { LogWriter } from './Writer'
@@ -16,9 +16,9 @@ export {
1616
FormatProvider,
1717
AnsiColors,
1818
LoggerConfig,
19-
LoggerConfigInstance,
19+
LoggerInstanceConfig,
2020
LoggerGlobalConfig,
21-
LoggerConfigProvider,
21+
LoggerInstanceConfigProvider,
2222
ObjectSerializationStrategy,
2323
LEVELS_ALL,
2424
}

0 commit comments

Comments
 (0)