Skip to content

Commit

Permalink
fix: deprecated should print to stdout (#281)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **Chores**
- Updated logging namespaces from `@eggjs/core:*` to `@eggjs/core/*`
across multiple files
	- Standardized debug and error logging formats
	- Minor adjustments to logging messages in test cases

- **Documentation**
	- Improved consistency in logging message formats

Note: These changes do not impact the core functionality of the
application and are primarily related to internal logging conventions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Dec 31, 2024
1 parent cb0a099 commit 2aeb0e2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/egg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Lifecycle } from './lifecycle.js';
import { EggLoader } from './loader/egg_loader.js';
import utils from './utils/index.js';

const debug = debuglog('@eggjs/core:egg');
const debug = debuglog('@eggjs/core/egg');

export const EGG_LOADER = Symbol.for('egg#loader');

Expand Down
16 changes: 8 additions & 8 deletions src/loader/egg_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class EggLoader {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('tsconfig-paths').register({ cwd: this.options.baseDir });
} else {
this.logger.info('[@eggjs/core:egg_loader] skip register "tsconfig-paths" because tsconfig.json not exists at %s',
this.logger.info('[@eggjs/core/egg_loader] skip register "tsconfig-paths" because tsconfig.json not exists at %s',
tsConfigFile);
}
}
Expand Down Expand Up @@ -639,14 +639,14 @@ export class EggLoader {

const logger = this.options.logger;
if (!config) {
logger.warn(`[@eggjs/core:egg_loader] pkg.eggPlugin is missing in ${pluginPackage}`);
logger.warn(`[@eggjs/core/egg_loader] pkg.eggPlugin is missing in ${pluginPackage}`);
return;
}

if (config.name && config.strict !== false && config.name !== plugin.name) {
// pluginName is configured in config/plugin.js
// pluginConfigName is pkg.eggPlugin.name
logger.warn(`[@eggjs/core:egg_loader] pluginName(${plugin.name}) is different from pluginConfigName(${config.name})`);
logger.warn(`[@eggjs/core/egg_loader] pluginName(${plugin.name}) is different from pluginConfigName(${config.name})`);
}

// dep compatible
Expand Down Expand Up @@ -1184,7 +1184,7 @@ export class EggLoader {
this.lifecycle.addFunctionAsBootHook(bootHook, bootFilePath);
debug('[loadBootHook] add bootHookFunction from %o', bootFilePath);
} else {
this.options.logger.warn('[@eggjs/core:egg_loader] %s must exports a boot class', bootFilePath);
this.options.logger.warn('[@eggjs/core/egg_loader] %s must exports a boot class', bootFilePath);
}
}
// init boots
Expand Down Expand Up @@ -1295,13 +1295,13 @@ export class EggLoader {
}
app.use(mw);
debug('[loadMiddleware] Use middleware: %s with options: %j', name, options);
this.options.logger.info('[@eggjs/core:egg_loader] Use middleware: %s', name);
this.options.logger.info('[@eggjs/core/egg_loader] Use middleware: %s', name);
} else {
this.options.logger.info('[@eggjs/core:egg_loader] Disable middleware: %s', name);
this.options.logger.info('[@eggjs/core/egg_loader] Disable middleware: %s', name);
}
}

this.options.logger.info('[@eggjs/core:egg_loader] Loaded middleware from %j', middlewarePaths);
this.options.logger.info('[@eggjs/core/egg_loader] Loaded middleware from %j', middlewarePaths);
this.timing.end('Load Middleware');

// add router middleware, make sure router is the last middleware
Expand Down Expand Up @@ -1359,7 +1359,7 @@ export class EggLoader {
};
await this.loadToApp(controllerBase, 'controller', opt as FileLoaderOptions);
debug('[loadController] app.controller => %o', this.app.controller);
this.options.logger.info('[@eggjs/core:egg_loader] Controller loaded: %s', controllerBase);
this.options.logger.info('[@eggjs/core/egg_loader] Controller loaded: %s', controllerBase);
this.timing.end('Load Controller');
}
/** end Controller loader */
Expand Down
8 changes: 4 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { stat } from 'node:fs/promises';
import BuiltinModule from 'node:module';
import { importResolve, importModule } from '@eggjs/utils';

const debug = debuglog('@eggjs/core:utils');
const debug = debuglog('@eggjs/core/utils');

export type Fun = (...args: any[]) => any;

Expand Down Expand Up @@ -55,10 +55,10 @@ function getCalleeFromStack(withLine?: boolean, stackIndex?: number) {
export default {
deprecated(message: string) {
if (debug.enabled) {
console.trace('[@eggjs/core:deprecated] %s', message);
console.trace('[@eggjs/core/deprecated] %s', message);
} else {
console.warn('[@eggjs/core:deprecated] %s', message);
console.warn('[@eggjs/core:deprecated] set NODE_DEBUG=@eggjs/core:utils can show call stack');
console.log('[@eggjs/core/deprecated] %s', message);
console.log('[@eggjs/core/deprecated] set NODE_DEBUG=@eggjs/core/utils can show call stack');
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/utils/sequencify.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { debuglog } from 'node:util';

const debug = debuglog('@eggjs/core:utils:sequencify');
const debug = debuglog('@eggjs/core/utils/sequencify');

export interface SequencifyResult {
sequence: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EOL } from 'node:os';
import { debuglog } from 'node:util';
import assert from 'node:assert';

const debug = debuglog('@eggjs/core:utils:timing');
const debug = debuglog('@eggjs/core/utils/timing');

export interface TimingItem {
name: string;
Expand Down
6 changes: 3 additions & 3 deletions test/loader/mixin/load_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ describe('test/loader/mixin/load_plugin.test.ts', () => {
let message = '';
app = createApp('plugin');
mm(app.console, 'warn', function(m: string) {
if (!m.startsWith('[@eggjs/core:egg_loader] eggPlugin is missing') && !message) {
if (!m.startsWith('[@eggjs/core/egg_loader] eggPlugin is missing') && !message) {
message = m;
}
});
const loader = app.loader;
await loader.loadPlugin();
await loader.loadConfig();

assert.equal(message, '[@eggjs/core:egg_loader] pluginName(e) is different from pluginConfigName(wrong-name)');
assert.equal(message, '[@eggjs/core/egg_loader] pluginName(e) is different from pluginConfigName(wrong-name)');
});

it('should not warn when the config.strict is false', async () => {
Expand Down Expand Up @@ -496,7 +496,7 @@ describe('test/loader/mixin/load_plugin.test.ts', () => {
await loader.loadPlugin();
const plugin = loader.plugins.a;
assert.equal(plugin.name, 'a');
assert.equal(plugin.path, getFilepath('realpath/a'));
assert.equal(plugin.path, getFilepath('realpath/node_modules/a'));
});

it('should get the defining plugin path in every plugin', async () => {
Expand Down

0 comments on commit 2aeb0e2

Please sign in to comment.