Skip to content

Commit

Permalink
Updated with recent changes needed for the publisher and added the ca…
Browse files Browse the repository at this point in the history
…tegory as requested
  • Loading branch information
bcostdolby committed Sep 9, 2024
1 parent 9651f11 commit 4af1241
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions lib/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,22 @@ function log(color, prefix, message, args)

class Logger
{
constructor(name)
/**
* Creates a new logger instance
*
* @param {string} name - A name identifying the sub-catcgeory of this logger, for example if we are logging for a specific view stream id
* @param {string} category - Identifier or subsystem this logger services, for example "publisher", "media-server", "audio-codecs" etc
*/
constructor(name, category)
{
const categoryText = category ? "[" + category + "]" : "";
this.category = category;
this.name = name;
this.color = Colors[Math.trunc(Math.random()*Colors.length)];
this.prefixInfo = " [INFO ] " + this.name + " ";
this.prefixDebug = " [DEBUG] " + this.name + " ";
this.prefixWarn = " [WARN ] " + this.name + " ";
this.prefixError = " [ERROR] " + this.name + " ";
this.prefixInfo = " [INFO ] " + categoryText + this.name + " ";
this.prefixDebug = " [DEBUG] " + categoryText + this.name + " ";
this.prefixWarn = " [WARN ] " + categoryText + this.name + " ";
this.prefixError = " [ERROR] " + categoryText + this.name + " ";
}

info(message, ...args)
Expand All @@ -88,7 +96,7 @@ class Logger

child(name)
{
return new Logger(this.name +":"+name);
return new Logger(this.name +":"+name, this.category);
}

getName()
Expand Down Expand Up @@ -122,5 +130,23 @@ Logger.setFlushTimeout = function(timeout)
FlushTimeout = timeout;
};

Logger.end = function()
{
// We cant call writable.end() here to properly end and flush
// As there are still async ops outstanding sometimes that will
// throw exceptions.
//
// Instead we will force uncork from now on so they flush out regulary

// Prevent ongoing batching
FlushTimeout = 0;
if (timer)
{
clearTimeout(timer);
writable.uncork();
timer = null;
}
};

module.exports = Logger;

0 comments on commit 4af1241

Please sign in to comment.