Skip to content

Commit

Permalink
Global exported logger uses the log methods from last call to `enable…
Browse files Browse the repository at this point in the history
…Logs`

Follow up to #6131
  • Loading branch information
robwalch committed Feb 7, 2024
1 parent 74f634f commit f237879
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/controller/cmcd-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { appendCmcdQuery } from '@svta/common-media-library/cmcd/appendCmcdQuery
import type { CmcdEncodeOptions } from '@svta/common-media-library/cmcd/CmcdEncodeOptions';
import { uuid } from '@svta/common-media-library/utils/uuid';
import { BufferHelper } from '../utils/buffer-helper';
import { logger } from '../utils/logger';
import type { ComponentAPI } from '../types/component-api';
import type { Fragment } from '../loader/fragment';
import type { BufferCreatedData, MediaAttachedData } from '../types/events';
Expand Down Expand Up @@ -201,7 +200,7 @@ export default class CMCDController implements ComponentAPI {
su: !this.initialized,
});
} catch (error) {
logger.warn('Could not generate manifest CMCD data.', error);
this.hls.logger.warn('Could not generate manifest CMCD data.', error);
}
};

Expand Down Expand Up @@ -237,7 +236,7 @@ export default class CMCDController implements ComponentAPI {

this.apply(context, data);
} catch (error) {
logger.warn('Could not generate segment CMCD data.', error);
this.hls.logger.warn('Could not generate segment CMCD data.', error);
}
};

Expand Down
9 changes: 4 additions & 5 deletions src/loader/playlist-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { Events } from '../events';
import { ErrorDetails, ErrorTypes } from '../errors';
import { logger } from '../utils/logger';
import M3U8Parser from './m3u8-parser';
import type { LevelParsed, VariableMap } from '../types/level';
import type {
Expand Down Expand Up @@ -221,10 +220,10 @@ class PlaylistLoader implements NetworkComponentAPI {
loaderContext.level === context.level
) {
// same URL can't overlap
logger.trace('[playlist-loader]: playlist request ongoing');
this.hls.logger.trace('[playlist-loader]: playlist request ongoing');
return;
}
logger.log(
this.hls.logger.log(
`[playlist-loader]: aborting previous loader for type: ${context.type}`,
);
loader.abort();
Expand Down Expand Up @@ -408,7 +407,7 @@ class PlaylistLoader implements NetworkComponentAPI {
levels[0].audioCodec &&
!levels[0].attrs.AUDIO
) {
logger.log(
this.hls.logger.log(
'[playlist-loader]: audio codec signaled in quality level, but no embedded audio track signaled, create one',
);
audioTracks.unshift({
Expand Down Expand Up @@ -555,7 +554,7 @@ class PlaylistLoader implements NetworkComponentAPI {
message += ` id: ${context.id} group-id: "${context.groupId}"`;
}
const error = new Error(message);
logger.warn(`[playlist-loader]: ${message}`);
this.hls.logger.warn(`[playlist-loader]: ${message}`);
let details = ErrorDetails.UNKNOWN;
let fatal = false;

Expand Down
5 changes: 3 additions & 2 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function getLoggerFn(
: consolePrintFn(key, id);
}

let exportedLogger: ILogger = createLogger();
const exportedLogger: ILogger = createLogger();

export function enableLogs(
debugConfig: boolean | ILogger,
Expand Down Expand Up @@ -107,7 +107,8 @@ export function enableLogs(
return createLogger();
}
}
exportedLogger = newLogger;
// global exported logger uses the log methods from last call to `enableLogs`
Object.assign(exportedLogger, newLogger);
return newLogger;
}

Expand Down

0 comments on commit f237879

Please sign in to comment.