Skip to content

Commit 82cb0f2

Browse files
authored
config.logs throw an error, logging config not longer accept array or… (verdaccio#3097)
1 parent 4088cde commit 82cb0f2

File tree

57 files changed

+198
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+198
-150
lines changed

.changeset/proud-jobs-hope.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
'@verdaccio/api': major
3+
'@verdaccio/cli': major
4+
'@verdaccio/config': major
5+
'@verdaccio/core': major
6+
'@verdaccio/types': major
7+
'@verdaccio/logger': major
8+
'@verdaccio/node-api': major
9+
'verdaccio-aws-s3-storage': major
10+
'verdaccio-google-cloud': major
11+
'verdaccio-htpasswd': major
12+
'@verdaccio/local-storage': major
13+
'verdaccio-memory': major
14+
'@verdaccio/ui-theme': major
15+
'@verdaccio/proxy': major
16+
'@verdaccio/server': major
17+
'@verdaccio/mock': major
18+
'verdaccio': major
19+
'@verdaccio/web': major
20+
'@verdaccio/e2e-cli': major
21+
'@verdaccio/website': major
22+
---
23+
24+
feat!: config.logs throw an error, logging config not longer accept array or logs property
25+
26+
### 💥 Breaking change
27+
28+
This is valid
29+
30+
```yaml
31+
log: { type: stdout, format: pretty, level: http }
32+
```
33+
34+
This is invalid
35+
36+
```yaml
37+
logs: { type: stdout, format: pretty, level: http }
38+
```
39+
40+
or
41+
42+
```yaml
43+
logs:
44+
- [{ type: stdout, format: pretty, level: http }]
45+
```

docker-examples/v6/reverse_proxy/nginx/relative_path/conf/v6/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ middlewares:
4646
audit:
4747
enabled: true
4848

49-
logs: { type: stdout, format: pretty, level: trace }
49+
log: { type: stdout, format: pretty, level: trace }

docker-examples/v6/reverse_proxy/nginx/relative_path/conf/v6_root/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ middlewares:
4242
audit:
4343
enabled: true
4444

45-
logs: { type: stdout, format: json, level: trace }
45+
log: { type: stdout, format: json, level: trace }

docs/warnings.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ invalid address - xxxxxx, we expect a port (e.g. "4873"),
2222

2323
## VERDEP002
2424

25-
'deprecate: multiple logger configuration is deprecated, please check the migration guide.'
25+
> After version `[email protected]` this is not longer a warning and
26+
> will crash your application
2627
2728
## VERDEP003
2829

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"docker": "docker build -t verdaccio/verdaccio:local . --no-cache",
117117
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
118118
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
119-
"lint": "eslint --max-warnings 45 \"**/*.{js,jsx,ts,tsx}\"",
119+
"lint": "eslint --max-warnings 46 \"**/*.{js,jsx,ts,tsx}\"",
120120
"test": "pnpm recursive test --filter ./packages",
121121
"test:e2e:cli": "pnpm test --filter ...@verdaccio/e2e-cli",
122122
"test:e2e:ui": "pnpm test --filter ...@verdaccio/e2e-ui",

packages/api/test/integration/config/package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ publish:
1818

1919
uplinks:
2020

21-
logs: { type: stdout, format: pretty, level: trace }
21+
log: { type: stdout, format: pretty, level: trace }
2222

2323
packages:
2424
'@*/*':

packages/api/test/integration/config/ping.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ web:
1111

1212
uplinks:
1313

14-
logs: { type: stdout, format: pretty, level: trace }
14+
log: { type: stdout, format: pretty, level: trace }
1515

1616
packages:
1717
'@*/*':

packages/api/test/integration/config/publish.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ publish:
1818

1919
uplinks:
2020

21-
logs: { type: stdout, format: pretty, level: trace }
21+
log: { type: stdout, format: pretty, level: trace }
2222

2323
packages:
2424
'@*/*':

packages/api/test/integration/config/user.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ uplinks:
1717
npmjs:
1818
url: https://registry.npmjs.org/
1919

20-
logs: { type: stdout, format: pretty, level: trace }
20+
log: { type: stdout, format: pretty, level: trace }
2121

2222
packages:
2323
'@*/*':

packages/api/test/integration/config/whoami.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ uplinks:
1717
npmjs:
1818
url: https://registry.npmjs.org/
1919

20-
logs: { type: stdout, format: pretty, level: trace }
20+
log: { type: stdout, format: pretty, level: trace }
2121

2222
packages:
2323
'@*/*':

packages/cli/src/commands/FastifyServer.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Command, Option } from 'clipanion';
22

33
import { findConfigFile, parseConfigFile } from '@verdaccio/config';
4-
import { warningUtils } from '@verdaccio/core';
54
import server from '@verdaccio/fastify-migration';
65
import { logger, setup } from '@verdaccio/logger';
76
import { ConfigRuntime } from '@verdaccio/types';
@@ -28,13 +27,13 @@ export class FastifyServer extends Command {
2827

2928
private initLogger(logConfig: ConfigRuntime) {
3029
try {
31-
if (logConfig.logs) {
32-
warningUtils.emit(warningUtils.Codes.VERDEP001);
30+
if (logConfig.log) {
31+
throw Error('logger as array not longer supported');
3332
}
3433
// FUTURE: remove fallback when is ready
35-
setup(logConfig.log || logConfig.logs);
36-
} catch {
37-
throw new Error('error on init logger');
34+
setup(logConfig.log);
35+
} catch (err: any) {
36+
throw new Error(err);
3837
}
3938
}
4039

packages/cli/src/commands/init.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Command, Option } from 'clipanion';
22

33
import { findConfigFile, parseConfigFile } from '@verdaccio/config';
4-
import { warningUtils } from '@verdaccio/core';
54
import { logger, setup } from '@verdaccio/logger';
5+
import { LoggerConfigItem } from '@verdaccio/logger/src/logger';
66
import { initServer } from '@verdaccio/node-api';
77
import { ConfigRuntime } from '@verdaccio/types';
88

@@ -47,13 +47,13 @@ export class InitCommand extends Command {
4747

4848
private initLogger(logConfig: ConfigRuntime) {
4949
try {
50+
// @ts-expect-error
5051
if (logConfig.logs) {
51-
warningUtils.emit(warningUtils.Codes.VERDEP001);
52+
throw Error('logger as array not longer supported');
5253
}
53-
// FUTURE: remove fallback when is ready
54-
setup(logConfig.log || logConfig.logs);
55-
} catch {
56-
throw new Error('error on init logger');
54+
setup(logConfig.log as LoggerConfigItem);
55+
} catch (err: any) {
56+
throw new Error(err);
5757
}
5858
}
5959

packages/config/src/conf/default.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
storage: ./storage
1111
# path to a directory with plugins to include
1212
plugins: ./plugins
13-
# print logs
14-
# logs: ./logs
1513

1614
web:
1715
title: Verdaccio
@@ -87,7 +85,7 @@ middlewares:
8785
enabled: true
8886

8987
# log settings
90-
logs:
88+
log:
9189
# Logger as STDOUT
9290
{ type: stdout, format: pretty, level: http }
9391
# Logger as STDOUT as JSON

packages/config/src/conf/docker.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ middlewares:
7272

7373
# log settings
7474
# log settings
75-
logs:
75+
log:
7676
# Logger as STDOUT
7777
{ type: stdout, format: pretty, level: http }
7878
# Logger as STDOUT as JSON

packages/config/test/config.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ describe('check basic content parsed file', () => {
5757
expect(config.middlewares).toBeDefined();
5858
expect(config.middlewares.audit).toBeDefined();
5959
expect(config.middlewares.audit.enabled).toBeTruthy();
60-
// logs
61-
expect(config.logs).toBeDefined();
62-
expect(config.logs.type).toEqual('stdout');
63-
expect(config.logs.format).toEqual('pretty');
64-
expect(config.logs.level).toEqual('http');
60+
// log
61+
expect(config.log).toBeDefined();
62+
expect(config.log.type).toEqual('stdout');
63+
expect(config.log.format).toEqual('pretty');
64+
expect(config.log.level).toEqual('http');
6565
// must not be enabled by default
6666
expect(config.notify).toBeUndefined();
6767
expect(config.store).toBeUndefined();

packages/config/test/partials/config/js/default.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ module.exports = {
1111
vue: { access: '$authenticated', publish: '$authenticated', proxy: 'npmjs' },
1212
'*': { access: '$all', publish: '$all', proxy: 'npmjs' },
1313
},
14-
logs: [{ type: 'stdout', format: 'pretty', level: 'warn' }],
14+
log: { type: 'stdout', format: 'pretty', level: 'warn' },
1515
};
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
22
storage: './storage_default_storage'
33

4-
logs:
5-
- type: stdout
6-
format: pretty
7-
level: warn
4+
log: { type: stdout, format: pretty, level: warn }

packages/core/core/src/warning-utils.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export enum Codes {
99
VERWAR002 = 'VERWAR002',
1010
VERWAR003 = 'VERWAR003',
1111
VERWAR004 = 'VERWAR004',
12-
VERDEP001 = 'VERDEP001',
13-
VERDEP002 = 'VERDEP002',
12+
// deprecation warnings
1413
VERDEP003 = 'VERDEP003',
1514
}
1615

@@ -36,18 +35,6 @@ host:port (e.g. "localhost:4873") or full url '(e.g. "http://localhost:4873/")
3635
https://verdaccio.org/docs/en/configuration#listen-port`
3736
);
3837

39-
warningInstance.create(
40-
verdaccioDeprecation,
41-
Codes.VERDEP001,
42-
'config.logs is deprecated, rename configuration to "config.log" in singular'
43-
);
44-
45-
warningInstance.create(
46-
verdaccioDeprecation,
47-
Codes.VERDEP002,
48-
'deprecate: multiple logger configuration is deprecated, please check the migration guide.'
49-
);
50-
5138
warningInstance.create(
5239
verdaccioDeprecation,
5340
Codes.VERDEP003,

packages/core/types/index.d.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,6 @@ declare module '@verdaccio/types' {
335335
sync(): void;
336336
}
337337

338-
interface LoggerConf {
339-
[key: string]: LoggerConfItem;
340-
}
341-
342338
interface ListenAddress {
343339
[key: string]: string;
344340
}
@@ -420,9 +416,8 @@ declare module '@verdaccio/types' {
420416
storage?: string | void;
421417
packages: PackageList;
422418
uplinks: UpLinksConfList;
423-
// @deprecated in favor of log
424-
logs?: LoggerConf[];
425-
log?: LoggerConf[];
419+
// FUTURE: log should be mandatory
420+
log?: LoggerConfItem;
426421
web?: WebConf;
427422
auth?: AuthConf;
428423
security: Security;

packages/logger/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"dependencies": {
4242
"@verdaccio/core": "workspace:6.0.0-6-next.4",
4343
"@verdaccio/logger-prettify": "workspace:6.0.0-6-next.6",
44+
"pino-pretty": "7.6.0",
4445
"debug": "4.3.3",
4546
"lodash": "4.17.21",
4647
"pino": "7.6.4"

packages/logger/src/logger.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export type LogFormat = 'json' | 'pretty-timestamped' | 'pretty';
2626
export function createLogger(
2727
options = { level: 'http' },
2828
destination = pino.destination(1),
29-
format: LogFormat = DEFAULT_LOG_FORMAT,
3029
prettyPrintOptions = {
3130
// we hide warning since the prettifier should not be used in production
3231
// https://getpino.io/#/docs/pretty?id=prettifier-api
3332
suppressFlushSyncWarning: true,
34-
}
33+
},
34+
format: LogFormat = DEFAULT_LOG_FORMAT
3535
) {
3636
if (_.isNil(format)) {
3737
format = DEFAULT_LOG_FORMAT;
@@ -116,19 +116,11 @@ export type LoggerConfigItem = {
116116
level?: string;
117117
};
118118

119-
export type LoggerConfig = LoggerConfigItem[];
119+
export type LoggerConfig = LoggerConfigItem;
120120

121-
export function setup(options: LoggerConfig | LoggerConfigItem = DEFAULT_LOGGER_CONF) {
121+
export function setup(options: LoggerConfigItem = DEFAULT_LOGGER_CONF) {
122122
debug('setup logger');
123-
const isLegacyConf = Array.isArray(options);
124-
if (isLegacyConf) {
125-
warningUtils.emit(warningUtils.Codes.VERDEP002);
126-
}
127-
128-
// verdaccio 5 does not allow multiple logger configuration
129-
// backward compatible, pick only the first option
130-
// next major will thrown an error
131-
let loggerConfig = isLegacyConf ? options[0] : options;
123+
let loggerConfig = options;
132124
if (!loggerConfig?.level) {
133125
loggerConfig = Object.assign(
134126
{},
@@ -143,13 +135,17 @@ export function setup(options: LoggerConfig | LoggerConfigItem = DEFAULT_LOGGER_
143135
debug('logging file enabled');
144136
const destination = pino.destination(loggerConfig.path);
145137
process.on('SIGUSR2', () => destination.reopen());
138+
// @ts-ignore
146139
logger = createLogger(pinoConfig, destination, loggerConfig.format);
140+
// @ts-ignore
147141
} else if (loggerConfig.type === 'rotating-file') {
148142
warningUtils.emit(warningUtils.Codes.VERWAR003);
149143
debug('logging stdout enabled');
144+
// @ts-ignore
150145
logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);
151146
} else {
152147
debug('logging stdout enabled');
148+
// @ts-ignore
153149
logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);
154150
}
155151

packages/logger/test/logger.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { warningUtils } from '@verdaccio/core';
2-
31
import { logger, setup } from '../src';
42

53
const mockWarningUtils = jest.fn();
@@ -34,7 +32,7 @@ describe('logger', () => {
3432
// expect(spyOn).toHaveBeenCalledTimes(2);
3533
});
3634

37-
test('throw deprecation warning if multiple loggers configured', () => {
35+
test.skip('throw deprecation warning if multiple loggers configured', () => {
3836
setup([
3937
{
4038
level: 'info',
@@ -43,7 +41,7 @@ describe('logger', () => {
4341
level: 'http',
4442
},
4543
]);
46-
expect(mockWarningUtils).toHaveBeenCalledWith(warningUtils.Codes.VERDEP002);
44+
// expect(mockWarningUtils).toHaveBeenCalledWith(warningUtils.Codes.VERDEP002);
4745
});
4846

4947
test('regression: do not throw deprecation warning if no logger config is provided', () => {

0 commit comments

Comments
 (0)