Skip to content

Commit

Permalink
feat(logging)!: drop logFile and logFileLevel (#29104)
Browse files Browse the repository at this point in the history
Co-authored-by: HonkingGoose <[email protected]>
  • Loading branch information
2 people authored and rarkins committed Jun 9, 2024
1 parent ab87dc8 commit b3e86d9
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 78 deletions.
3 changes: 0 additions & 3 deletions docs/usage/self-hosted-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,6 @@ When you set `inheritConfigStrict=true` then Renovate will abort the run and rai
`logContext` is included with each log entry only if `logFormat="json"` - it is not included in the pretty log output.
If left as default (null), a random short ID will be selected.

## logFile

## logFileLevel

## mergeConfidenceDatasources

Expand Down
19 changes: 0 additions & 19 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,25 +542,6 @@ const options: RenovateOptions[] = [
supportedManagers: ['gomod'],
},
// Log options
{
name: 'logFile',
description: 'Log file path.',
stage: 'global',
type: 'string',
globalOnly: true,
deprecationMsg:
'Instead of configuring log file path in the file config. Use the `LOG_FILE` environment variable instead.',
},
{
name: 'logFileLevel',
description: 'Set the log file log level.',
stage: 'global',
type: 'string',
default: 'debug',
globalOnly: true,
deprecationMsg:
'Instead of configuring log file level in the file config. Use the `LOG_FILE_LEVEL` environment variable instead.',
},
{
name: 'logContext',
description: 'Add a global or per-repo log context to each log entry.',
Expand Down
3 changes: 0 additions & 3 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { LogLevel } from 'bunyan';
import type { PlatformId } from '../constants';
import type { LogLevelRemap } from '../logger/types';
import type { CustomManager } from '../modules/manager/custom/types';
Expand Down Expand Up @@ -114,8 +113,6 @@ export interface GlobalOnlyConfig {
gitNoVerify?: GitNoVerifyOption[];
gitPrivateKey?: string;
globalExtends?: string[];
logFile?: string;
logFileLevel?: LogLevel;
mergeConfidenceDatasources?: string[];
mergeConfidenceEndpoint?: string;
platform?: PlatformId;
Expand Down
16 changes: 10 additions & 6 deletions lib/config/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1341,19 +1341,23 @@ describe('config/validation', () => {
});

describe('validateConfig() -> globaOnly options', () => {
it('returns deprecation warnings', async () => {
it('returns errors for invalid options', async () => {
const config = {
logFile: 'something',
logFileLevel: 'DEBUG',
};
const { warnings } = await configValidation.validateConfig(
const { errors } = await configValidation.validateConfig(
'global',
config,
);
expect(warnings).toMatchObject([
expect(errors).toMatchObject([
{
message:
'Using logFile to specify log file name is deprecated now. Please use the enviroment variable LOG_FILE instead',
topic: 'Deprecation Warning',
message: 'Invalid configuration option: logFile',
topic: 'Configuration Error',
},
{
message: 'Invalid configuration option: logFileLevel',
topic: 'Configuration Error',
},
]);
});
Expand Down
3 changes: 1 addition & 2 deletions lib/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ function getDeprecationMessage(option: string): string | undefined {
branchName: `Direct editing of branchName is now deprecated. Please edit branchPrefix, additionalBranchPrefix, or branchTopic instead`,
commitMessage: `Direct editing of commitMessage is now deprecated. Please edit commitMessage's subcomponents instead.`,
prTitle: `Direct editing of prTitle is now deprecated. Please edit commitMessage subcomponents instead as they will be passed through to prTitle.`,
logFile: `Using logFile to specify log file name is deprecated now. Please use the enviroment variable LOG_FILE instead`,
logFileLevel: `Using logFileLevel to specify log level for file logging is deprecated now. Please use the enviroment variable LOG_FILE_LEVEL instead`,
};
return deprecatedOptions[option];
}
Expand Down Expand Up @@ -906,6 +904,7 @@ async function validateGlobalConfig(
currentPath: string | undefined,
config: RenovateConfig,
): Promise<void> {
// istanbul ignore if
if (getDeprecationMessage(key)) {
warnings.push({
topic: 'Deprecation Warning',
Expand Down
1 change: 0 additions & 1 deletion lib/workers/global/config/parse/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe('workers/global/config/parse/file', () => {
`module.exports = {
"platform": "github",
"token":"abcdef",
"logFileLevel": "warn",
"onboarding": false,
"gitAuthor": "Renovate Bot <[email protected]>"
"onboardingConfig": {
Expand Down
27 changes: 4 additions & 23 deletions lib/workers/global/config/parse/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,30 +173,11 @@ describe('workers/global/config/parse/index', () => {
expect(parsed).toContainEntries([['dryRun', null]]);
});

it('initalizes file logging when logFile is set and env vars LOG_FILE is undefined', async () => {
jest.doMock(
'../../../../../config.js',
() => ({ logFile: 'somepath', logFileLevel: 'debug' }),
{
virtual: true,
},
);
const env: NodeJS.ProcessEnv = {};
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).not.toContain([['logFile', 'someFile']]);
expect(getParentDir).toHaveBeenCalledWith('somepath');
});

it('skips initializing file logging when logFile is set but env vars LOG_FILE is defined', async () => {
jest.doMock(
'../../../../../config.js',
() => ({ logFile: 'somepath', logFileLevel: 'debug' }),
{
virtual: true,
},
);
it('only initializes the file when the env var LOG_FILE is properly set', async () => {
jest.doMock('../../../../../config.js', () => ({}), {
virtual: true,
});
const env: NodeJS.ProcessEnv = {};
process.env.LOG_FILE = 'somepath';
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).not.toContain([['logFile', 'someFile']]);
expect(getParentDir).not.toHaveBeenCalled();
Expand Down
23 changes: 2 additions & 21 deletions lib/workers/global/config/parse/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import is from '@sindresorhus/is';
import * as defaultsParser from '../../../../config/defaults';
import type { AllConfig } from '../../../../config/types';
import { mergeChildConfig } from '../../../../config/utils';
import { addStream, logger, setContext } from '../../../../logger';
import { logger, setContext } from '../../../../logger';
import { detectAllGlobalConfig } from '../../../../modules/manager';
import { coerceArray } from '../../../../util/array';
import { ensureDir, getParentDir, readSystemFile } from '../../../../util/fs';
import { readSystemFile } from '../../../../util/fs';
import { addSecretForSanitizing } from '../../../../util/sanitize';
import { ensureTrailingSlash } from '../../../../util/url';
import * as cliParser from './cli';
Expand Down Expand Up @@ -67,20 +66,6 @@ export async function parseConfigs(
setContext(config.logContext);
}

// Add file logger
if (config.logFile && is.undefined(process.env.LOG_FILE)) {
logger.debug(
// TODO: types (#22198)
`Enabling ${config.logFileLevel!} logging to ${config.logFile}`,
);
await ensureDir(getParentDir(config.logFile));
addStream({
name: 'logfile',
path: config.logFile,
level: config.logFileLevel,
});
}

logger.trace({ config: defaultConfig }, 'Default config');
logger.debug({ config: fileConfig }, 'File config');
logger.debug({ config: cliConfig }, 'CLI config');
Expand Down Expand Up @@ -119,9 +104,5 @@ export async function parseConfigs(
config.onboardingNoDeps = 'enabled';
}

// Remove log file entries
delete config.logFile;
delete config.logFileLevel;

return config;
}

0 comments on commit b3e86d9

Please sign in to comment.