fix(config): correct basicConfig option assignments and control flow
Fix dateformat and style variables reading from wrong option fields (filemode instead of datefmt/style). Restructure control flow to match CPython logic: early return when handlers exist and force is not set, proper mutual exclusion of stream/filename/handlers args. Remove unreachable code block.
This commit is contained in:
parent
e76d8fb77b
commit
9fed1ffe6b
1 changed files with 44 additions and 54 deletions
|
|
@ -121,8 +121,8 @@ export function basicConfig(options: BasicConfigOptions) {
|
|||
const filename = options.filename ?? null;
|
||||
const stream = options.stream ?? null;
|
||||
const filemode = options.filemode ?? 'a';
|
||||
const dateformat = options.filemode ?? null;
|
||||
const style = options.filemode ?? '%';
|
||||
const dateformat = options.datefmt ?? null;
|
||||
const style = options.style ?? '%';
|
||||
const level = options.level ?? null;
|
||||
|
||||
if (!Object.keys(STYLES).includes(style)) {
|
||||
|
|
@ -139,42 +139,43 @@ export function basicConfig(options: BasicConfigOptions) {
|
|||
}
|
||||
}
|
||||
|
||||
if (handlers.length == 0) {
|
||||
if (handlers === null && stream && filename) {
|
||||
throw new ValueError(
|
||||
"'stream' and 'filename' should not be specified together"
|
||||
);
|
||||
if (MANAGER.root.handlers.length > 0 && !force) {
|
||||
return;
|
||||
}
|
||||
|
||||
else if (stream || filename) {
|
||||
if (handlers.length > 0) {
|
||||
if (stream || filename) {
|
||||
throw new ValueError(
|
||||
"'stream' or 'filename' should not be specified together " +
|
||||
"with 'handlers'"
|
||||
);
|
||||
}
|
||||
|
||||
if (handlers === null) {
|
||||
var h: Handler;
|
||||
}
|
||||
else {
|
||||
if (stream && filename) {
|
||||
throw new ValueError(
|
||||
"'stream' and 'filename' should not be specified together"
|
||||
);
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
if (filemode.match('b')) { errors = undefined }
|
||||
else { encoding = 'utf-8' }
|
||||
|
||||
h = new FileHandler({
|
||||
handlers = [new FileHandler({
|
||||
filename: filename,
|
||||
filemode: filemode,
|
||||
'encoding': encoding,
|
||||
encoding: encoding,
|
||||
errors: errors
|
||||
});
|
||||
})];
|
||||
}
|
||||
else {
|
||||
handlers = [new StreamHandler(stream)];
|
||||
}
|
||||
}
|
||||
|
||||
else { h = new StreamHandler(stream) }
|
||||
|
||||
handlers = [h];
|
||||
}
|
||||
|
||||
for (var i = 0; i < handlers.length; i += 1) {
|
||||
let h = handlers[i];
|
||||
for (let i = 0; i < handlers.length; i += 1) {
|
||||
const h = handlers[i];
|
||||
|
||||
if (h.formatter === null) {
|
||||
h.formatter = new Formatter({
|
||||
|
|
@ -188,15 +189,4 @@ export function basicConfig(options: BasicConfigOptions) {
|
|||
}
|
||||
|
||||
if (level !== null) { MANAGER.root.setLevel(level) }
|
||||
|
||||
if (options) {
|
||||
// runtime interface guard, please let me stay. 🥺
|
||||
// the interface does not allow for additional members, but the
|
||||
// runtime environment has no concept of interfaces. We can stick to
|
||||
// the original implementation
|
||||
const keys = Object.keys(options).join(', ');
|
||||
|
||||
throw new ValueError(`Unrecognised argument(s): ${keys}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue