ol-logging-tools
v0.0.1
Published
A suite of logging tools for the Overlook Design System used by Overlook Games LLC.
Downloads
3
Maintainers
Keywords
Readme
ol-logging-tools
A logger tool for the Overlook Design System
Installation
npm install --save ol-logging-tools
Usage
- Create an instance of the logging tools object.
export const myLogger = createLoggingToolsInstance();
Optionall, pass in parameters to configure the logger.
let options = {
batchLimit : 2, //The total number of batches this will record
batchSize : 99 //The number of records in a batch
}
export const myConfiguredLogger = createLoggingToolsInstance(options);
These are the default values.
- Use the methods
createOperationRecord
andcreateOperationSubRecord
to log the progress of a process or operation.
//Heres an example using this tool
//to monitor an RTDB helper function
let loggingRTDBTools = createLoggingToolsInstance();
async function transaction({path, transform, ifNullValue, onError, onSuccess, consoleHelper}) {
if (consoleHelper === undefined) consoleHelper = "unknown"
loggingRTDBTools.newOperationRecord({operation: consoleHelper + "- transaction - start", payload: {}})
return await new Promise(((resolve, reject) => {
try{
let log = [];
let payload = {path, ifNullValue, consoleHelper,transform:transform.toString()};
log.push("We awaited a transaction at path")
firebaseApp
.database()
.ref(path)
.transaction(object => {
if (object === null) {
log.push("object in cloud was null")
log.push("returned ifNullValue")
return ifNullValue
}
log.push("we transformed object")
payload["transformedObject"] = transform(object)
return transform(object)
}, function (error, committed, snapshot) {
if (error) {
//console.error('Transaction failed abnormally!', error);
loggingRTDBTools.newOperationSubRecord(
{
operation: log,
subString: "Error - @ transaction " + consoleHelper,
payload: {error, ...payload}
})
reject(error);
onError(error);
return error;
} else if (!committed) {
log.push('We aborted the transaction (because value already exists.');
}
loggingRTDBTools.newOperationSubRecord(
{
operation: log,
subString: consoleHelper + " success! - @ transaction ",
payload: {error, ...payload}
})
resolve(snapshot.val());
onSuccess(snapshot.val());
}
)
} catch (e) {
throw new Error("Error in RTDB Tools Transaction")
}
}))
}
- Fetch batch results in groups of 99, for use in UI / console logs.
<button
onClick={()=>{
let batches = loggingRTDBTools.returnOperationRecordBatches();
batches.forEach(records=>{
console.log("RTDB Tools - ",{records})
})
}}
>Log Report</button>