mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-28 04:24:01 +00:00
Allow adjusting log levels on the fly
This commit is contained in:
parent
7a0bf5864e
commit
4baccc4701
6 changed files with 76 additions and 35 deletions
|
|
@ -119,15 +119,15 @@
|
|||
</a>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/gui/gui.js?v=1"></script>
|
||||
<script src="/static/js/gui/gui.js?v=2"></script>
|
||||
<script src="/static/js/utils.js?v1"></script>
|
||||
<script src="/static/js/gui/message.js?v=1"></script>
|
||||
<script src="/static/js/log.js?v=5"></script>
|
||||
<script src="/static/js/log.js?v=6"></script>
|
||||
<script src="/static/js/event/event.js?v=6"></script>
|
||||
<script src="/static/js/network/socket.js?v=4"></script>
|
||||
<script src="/static/js/input/keys.js?v=3"></script>
|
||||
<script src="/static/js/settings/opts.js?v=1"></script>
|
||||
<script src="/static/js/settings/settings.js?v=2"></script>
|
||||
<script src="/static/js/settings/settings.js?v=3"></script>
|
||||
<script src="/static/js/env.js?v=5"></script>
|
||||
<script src="/static/js/input/input.js?v=3"></script>
|
||||
<script src="/static/js/gameList.js?v=3"></script>
|
||||
|
|
@ -138,12 +138,12 @@
|
|||
<script src="/static/js/workerManager.js?v=1"></script>
|
||||
<script src="/static/js/recording.js?v=1"></script>
|
||||
<script src="/static/js/stats/stats.js?v=2"></script>
|
||||
<script src="/static/js/controller.js?v=7"></script>
|
||||
<script src="/static/js/controller.js?v=8"></script>
|
||||
<script src="/static/js/input/keyboard.js?v=5"></script>
|
||||
<script src="/static/js/input/touch.js?v=3"></script>
|
||||
<script src="/static/js/input/joystick.js?v=3"></script>
|
||||
|
||||
<script src="/static/js/init.js?v=5"></script>
|
||||
<script src="/static/js/init.js?v=6"></script>
|
||||
|
||||
{{if .Analytics.Inject}}
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{.Analytics.Gtag}}"></script>
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
state = newState;
|
||||
}
|
||||
|
||||
if (log.is(log.level.debug)) {
|
||||
if (log.level === log.DEBUG) {
|
||||
const previous = prevState ? prevState.name : '???';
|
||||
const current = state ? state.name : '???';
|
||||
const kept = lastState ? lastState.name : '???';
|
||||
|
|
@ -462,6 +462,13 @@
|
|||
event.sub(RECORDING_TOGGLED, handleRecording);
|
||||
event.sub(RECORDING_STATUS_CHANGED, handleRecordingStatus);
|
||||
|
||||
event.sub(SETTINGS_CHANGED, () => {
|
||||
const newValue = settings.get()[opts.LOG_LEVEL];
|
||||
if (newValue !== log.level) {
|
||||
log.level = newValue;
|
||||
}
|
||||
});
|
||||
|
||||
// initial app state
|
||||
setState(app.state.eden);
|
||||
})(document, event, env, gameList, input, KEY, log, message, recording, room, rtcp, settings, socket, stats, stream, utils, workerManager);
|
||||
|
|
|
|||
|
|
@ -13,16 +13,21 @@ const gui = (() => {
|
|||
return el;
|
||||
}
|
||||
|
||||
const _option = (text = '', selected = false) => {
|
||||
const _option = (text = '', selected = false, label) => {
|
||||
const el = _create('option');
|
||||
el.textContent = text;
|
||||
if (label) {
|
||||
el.textContent = label;
|
||||
el.value = text;
|
||||
} else {
|
||||
el.textContent = text;
|
||||
}
|
||||
if (selected) el.selected = true;
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
const select = (key = '', callback = function () {
|
||||
}, values = [], current = '') => {
|
||||
}, values = {values: [], labels: []}, current = '') => {
|
||||
const el = _create();
|
||||
const select = _create('select');
|
||||
select.onchange = event => {
|
||||
|
|
@ -31,7 +36,9 @@ const gui = (() => {
|
|||
el.append(select);
|
||||
|
||||
select.append(_option('none', current === ''));
|
||||
for (let value of values) select.append(_option(value, current === value));
|
||||
values.values.forEach((value, index) => {
|
||||
select.append(_option(value, current === value, values.labels?.[index]));
|
||||
});
|
||||
|
||||
return el;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,18 @@
|
|||
settings.init();
|
||||
log.setLevel(settings.loadOr(opts.LOG_LEVEL, 'debug'));
|
||||
|
||||
(() => {
|
||||
let lvl = settings.loadOr(opts.LOG_LEVEL, log.DEFAULT);
|
||||
// migrate old log level options
|
||||
// !to remove at some point
|
||||
if (isNaN(lvl)) {
|
||||
console.warn(
|
||||
`The log value [${lvl}] is not supported! ` +
|
||||
`The default value [debug] will be used instead.`);
|
||||
settings.set(opts.LOG_LEVEL, `${log.DEFAULT}`)
|
||||
lvl = log.DEFAULT
|
||||
}
|
||||
log.level = lvl
|
||||
})();
|
||||
|
||||
keyboard.init();
|
||||
joystick.init();
|
||||
|
|
|
|||
|
|
@ -1,23 +1,35 @@
|
|||
/**
|
||||
* Logging module.
|
||||
*
|
||||
* @version 2
|
||||
*/
|
||||
const log = (() => {
|
||||
const levels = {'trace': 0, 'debug': 1, 'error': 2, 'warning': 3, 'info': 4};
|
||||
let level = -1;
|
||||
const noop = () => ({})
|
||||
|
||||
const atLeast = lv => (lv || -1) >= level;
|
||||
const noop = () => ({});
|
||||
const _log = {
|
||||
ASSERT: 1,
|
||||
ERROR: 2,
|
||||
WARN: 3,
|
||||
INFO: 4,
|
||||
DEBUG: 5,
|
||||
TRACE: 6,
|
||||
|
||||
const
|
||||
info = atLeast(levels.info) ? console.info.bind(window.console) : noop,
|
||||
debug = atLeast(levels.debug) ? console.debug.bind(window.console) : noop,
|
||||
error = atLeast(levels.error) ? console.error.bind(window.console) : noop,
|
||||
warning = atLeast(levels.warning) ? console.warn.bind(window.console) : noop;
|
||||
DEFAULT: 5,
|
||||
|
||||
return {
|
||||
level: levels,
|
||||
info,
|
||||
debug,
|
||||
error,
|
||||
warning,
|
||||
setLevel: (level_) => level = levels[level_] || -1,
|
||||
is: (level_) => level === level_
|
||||
set level(level) {
|
||||
this.assert = level >= this.ASSERT ? console.assert.bind(window.console) : noop;
|
||||
this.error = level >= this.ERROR ? console.error.bind(window.console) : noop;
|
||||
this.warn = level >= this.WARN ? console.warn.bind(window.console) : noop;
|
||||
this.info = level >= this.INFO ? console.info.bind(window.console) : noop;
|
||||
this.debug = level >= this.DEBUG ? console.debug.bind(window.console) : noop;
|
||||
this.trace = level >= this.TRACE ? console.log.bind(window.console) : noop;
|
||||
this._level = level;
|
||||
},
|
||||
get level() {
|
||||
return this._level;
|
||||
}
|
||||
}
|
||||
_log.level = _log.DEFAULT;
|
||||
|
||||
return _log
|
||||
})(console, window);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
const settings = (() => {
|
||||
// internal structure version
|
||||
const revision = 1;
|
||||
const revision = 1.1;
|
||||
|
||||
// default settings
|
||||
// keep them for revert to defaults option
|
||||
|
|
@ -169,7 +169,7 @@ const settings = (() => {
|
|||
|
||||
if (revision > store.settings._version) {
|
||||
// !to handle this with migrations
|
||||
log.warning(`Your settings are in older format (v${store.settings._version})`);
|
||||
log.warn(`Your settings are in older format (v${store.settings._version})`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -248,7 +248,7 @@ const settings = (() => {
|
|||
|
||||
const remove = (key, subKey) => {
|
||||
const isRemoved = subKey !== undefined ? delete store.settings[key][subKey] : delete store.settings[key];
|
||||
if (!isRemoved) log.warning(`The key: ${key + (subKey ? '.' + subKey : '')} wasn't deleted!`);
|
||||
if (!isRemoved) log.warn(`The key: ${key + (subKey ? '.' + subKey : '')} wasn't deleted!`);
|
||||
provider.remove(key, subKey);
|
||||
}
|
||||
|
||||
|
|
@ -390,7 +390,7 @@ settings._renderrer = (() => {
|
|||
const _settings = settings.get()[opts.INPUT_KEYBOARD_MAP];
|
||||
|
||||
if (_settings[newValue] !== undefined) {
|
||||
log.warning(`There are old settings for key: ${_settings[newValue]}, won't change!`);
|
||||
log.warn(`There are old settings for key: ${_settings[newValue]}, won't change!`);
|
||||
} else {
|
||||
settings.remove(opts.INPUT_KEYBOARD_MAP, oldValue);
|
||||
settings.set(opts.INPUT_KEYBOARD_MAP, {[newValue]: key});
|
||||
|
|
@ -446,8 +446,10 @@ settings._renderrer = (() => {
|
|||
break;
|
||||
case opts.LOG_LEVEL:
|
||||
_option(data).withName('Log level')
|
||||
.restartNeeded()
|
||||
.add(gui.select(k, onChange, ['trace', 'debug', 'warning', 'info'], value))
|
||||
.add(gui.select(k, onChange, {
|
||||
labels: ['trace', 'debug', 'warning', 'info'],
|
||||
values: [log.TRACE, log.DEBUG, log.WARN, log.INFO].map(String)
|
||||
}, value))
|
||||
.build();
|
||||
break;
|
||||
case opts.INPUT_KEYBOARD_MAP:
|
||||
|
|
@ -458,7 +460,7 @@ settings._renderrer = (() => {
|
|||
break;
|
||||
case opts.MIRROR_SCREEN:
|
||||
_option(data).withName('Video mirroring without smooth')
|
||||
.add(gui.select(k, onChange, ['mirror'], value))
|
||||
.add(gui.select(k, onChange, {values: ['mirror']}, value))
|
||||
.build();
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue