Skip to content

Log function does not limit log size #7

Description

@JefStat

I replaced most of my tail windows with this box log. I ran into a problem were I would into huge slowdowns because of a the large amount of log lines. I had to put in a way to limit the log html.

if (box.logDiv.childElementCount > 500) {
	box.logDiv.replaceChildren(...Array.from(box.logDiv.children).slice(-100))
}

More specifically this is how I use the box api

export const boxTailSingleton = (ns, title, icon, height) => {
	var res = [];
	sidebar.querySelectorAll('div.sbitem').forEach(sbitem => res.push({ sbitem, title: sbitem.querySelector('div.head > span').innerText }));
	let box = res.find(o => o.title === title);
	if (box) {
		box = box.sbitem;
	} else {
		box = createSidebarItem(title, "<div/>", icon);
	}
	if (height) box.style.height = height;

	const _print = ns.print;
	ns.print = (m) => {
		box.log(`<span>${m}</span>`);
		_print(m);
		box.logDiv = box.body.querySelector('div.log');
		if (box.logDiv.childElementCount > 500) {
			box.logDiv.replaceChildren(...Array.from(box.logDiv.children).slice(-100))
		}
	}
}

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

wontfixThis will not be worked on

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions