Skip to content

Commit

Permalink
do not load files
Browse files Browse the repository at this point in the history
  • Loading branch information
zoe-codez committed Nov 14, 2024
1 parent 37fd52e commit dabd2cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/helpers/wiring.mts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ export type TInjectedConfig = {

// #region Special
// SEE DOCS http://docs.digital-alchemy.app/docs/core/declaration-merging
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface AsyncLogData {
// No data by default
// Intended to have declaration merges happen to be useful
logger: ILogger;
}

export interface AsyncLocalData {
Expand Down
22 changes: 12 additions & 10 deletions src/services/configuration.service.mts
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,18 @@ export function Configuration({
}),
["env", "argv"],
);
mergeConfig(
await configLoaderFile({
application,
configs: configDefinitions,
internal,
logger,
}),
["file"],
);

const canFile = internal.boot.options?.configSources?.file ?? true;
if (canFile) {
mergeConfig(
await configLoaderFile({
application,
configs: configDefinitions,
internal,
logger,
}),
["file"],
);
}
// * load!
await eachSeries([...loaders.entries()], async ([type, loader]) => {
mergeConfig(await loader({ application, configs: configDefinitions, internal, logger }), [
Expand Down
16 changes: 12 additions & 4 deletions src/services/logger.service.mts
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,23 @@ export async function Logger({
});
}

function mergeData<T extends object>(data: T): T {
function mergeData<T extends object>(data: T): [T, ILogger] {
let out = { ...data, ...loggerOptions.mergeData };

if (loggerOptions.counter) {
const counter = out as { logIdx: number };
counter.logIdx = logCounter++;
}

let logger: ILogger;
if (loggerOptions.als) {
out = { ...out, ...als.getLogData() };
const data = als.getLogData();
logger = data.logger;
delete data.logger;
out = { ...out, ...data };
}

return out;
return [out, logger];
}

const prettyFormatMessage = (message: string): string => {
Expand Down Expand Up @@ -122,7 +126,7 @@ export async function Logger({
[...METHOD_COLORS.keys()].forEach(key => {
const level = `[${key.toUpperCase()}]`.padStart(LEVEL_MAX, " ");
logger[key] = (context: TContext, ...parameters: Parameters<TLoggerFunction>) => {
const data = mergeData(
const [data, child] = mergeData(
is.object(parameters[FIRST])
? (parameters.shift() as {
context?: TContext;
Expand Down Expand Up @@ -185,6 +189,10 @@ export async function Logger({
.slice(SYMBOL_START, SYMBOL_END)
.join("\n");
}
if (child) {
child[key](message);
return;
}
switch (key) {
case "warn": {
globalThis.console.warn(message);
Expand Down

0 comments on commit dabd2cf

Please sign in to comment.