Skip to content

Instantly share code, notes, and snippets.

@bwindels
Last active October 29, 2019 08:34
Show Gist options
  • Save bwindels/1632a4254627242ca9a7c38f522bbf0b to your computer and use it in GitHub Desktop.
Save bwindels/1632a4254627242ca9a7c38f522bbf0b to your computer and use it in GitHub Desktop.
API idea for structured logging that can be rendered as timeline
// we should consider using descend here to have the same api
// so code doesn't have to care if it deals with the root or not though.
// Although the root wouldn't have any other method... still,
// could be nice to pass in a logitem instead of the root logger object.
const syncLog = loggerRoot.start("sync");
// log level means the whole sync item and subtree will be ignored if so configured,
// unless it has a node that has a higher loglevel.
// Calling `fail` automatically sets the loglevel to WarnLevel for example?
// This way, you can configure the logger to only persist log trees that had a failure in them.
// is fork a better name than descend?
const networkLog = syncLog.descend("network call", syncLog.InfoLevel);
// or rather:
// this forces you to pick a log level as opposed to inherit from parent, we should at least offer both
// also you wouldn't expect a return value on this api as it resembles console.info. If you don't call `finish`
// you'll get a distorted image as it would only stop counting time when one of the parents is finished.
const networkLog = syncLog.info("network call");
const networkLog = syncLog.descendInfo("network call");
// add structured data to log item
networkLog.set("key", "value");
networkLog.set({key: "value"});
// special function for PII?
networkLog.setPII({key: "value"});
networkLog.finish();
networkLog.fail(err);
// fails or succeeds the log item based on a promise, and forwards the promise
const promise = networkLog.wrap(() => hsApi.sync(...));
const sendLog = loggerRoot.start("send message");
when closing the app:
// this finishes all open log items with a specific message saying the app got closed before they could close?
// stores unfinished log trees in localStorage as we can't do async stuff (IDB) on document unload
logger.close();
@bwindels
Copy link
Author

what to do with overlapping siblings?
also, we can show all inherited properties in the properties panel, so you would only need to put roomId in the highest item in the log tree.

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