mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Minor refactoring in logger and pyconfig (#1072)
This commit is contained in:
committed by
GitHub
parent
f73d6cd9f2
commit
4b840f7cbd
@@ -10,8 +10,8 @@
|
||||
logger.warn('...');
|
||||
logger.error('...');
|
||||
|
||||
The logger automatically adds the prefix "[my-prefix]" to all logs; so e.g., the
|
||||
above call would print:
|
||||
The logger automatically adds the prefix "[my-prefix]" to all logs.
|
||||
E.g., the above call would print:
|
||||
|
||||
[my-prefix] hello world
|
||||
|
||||
@@ -42,7 +42,7 @@ function getLogger(prefix: string): Logger {
|
||||
}
|
||||
|
||||
function _makeLogger(prefix: string): Logger {
|
||||
prefix = '[' + prefix + '] ';
|
||||
prefix =`[${prefix}] `;
|
||||
|
||||
function make(level: string) {
|
||||
const out_fn = console[level].bind(console);
|
||||
|
||||
@@ -75,7 +75,7 @@ export function loadConfigFromElement(el: Element): AppConfig {
|
||||
srcConfig = mergeConfig(srcConfig, defaultConfig);
|
||||
const result = mergeConfig(inlineConfig, srcConfig);
|
||||
result.pyscript = {
|
||||
version: version,
|
||||
version,
|
||||
time: new Date().toISOString(),
|
||||
};
|
||||
return result;
|
||||
@@ -140,7 +140,6 @@ function mergeConfig(inlineConfig: AppConfig, externalConfig: AppConfig): AppCon
|
||||
}
|
||||
|
||||
function parseConfig(configText: string, configType = 'toml') {
|
||||
let config: object;
|
||||
if (configType === 'toml') {
|
||||
try {
|
||||
// TOML parser is soft and can parse even JSON strings, this additional check prevents it.
|
||||
@@ -150,7 +149,7 @@ function parseConfig(configText: string, configType = 'toml') {
|
||||
`The config supplied: ${configText} is an invalid TOML and cannot be parsed`
|
||||
);
|
||||
}
|
||||
config = toml.parse(configText);
|
||||
return toml.parse(configText);
|
||||
} catch (err) {
|
||||
const errMessage: string = err.toString();
|
||||
throw new UserError(
|
||||
@@ -160,7 +159,7 @@ function parseConfig(configText: string, configType = 'toml') {
|
||||
}
|
||||
} else if (configType === 'json') {
|
||||
try {
|
||||
config = JSON.parse(configText);
|
||||
return JSON.parse(configText);
|
||||
} catch (err) {
|
||||
const errMessage: string = err.toString();
|
||||
throw new UserError(
|
||||
@@ -174,7 +173,6 @@ function parseConfig(configText: string, configType = 'toml') {
|
||||
`The type of config supplied '${configType}' is not supported, supported values are ["toml", "json"]`
|
||||
);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
function validateConfig(configText: string, configType = 'toml') {
|
||||
|
||||
Reference in New Issue
Block a user