Skip to content

Commit

Permalink
fix(logger): remove node util.inspect dep
Browse files Browse the repository at this point in the history
affects: @tao.js/utils

logger written with node's util.inspect import
now clients pass an inspect function in opts
  • Loading branch information
eudaimos committed Mar 11, 2024
1 parent 3111072 commit 8aa6297
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions packages/tao-utils/src/logger.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { inspect } from 'util';

function inspectObject(obj, depth) {
return inspect(obj, false, depth, true);
}

export function TaoLogger(
doLogging = true,
{ verbose = false, depth = 0, group = false, logger = console } = {}
{
verbose = false,
depth = 0,
group = false,
logger = console,
inspect = null
} = {}
) {
let inspector = null;
if (!depth && depth !== null) {
if (
inspect == null ||
typeof inspect != 'function' ||
(!depth && depth != null)
) {
inspector = obj => obj;
} else {
inspector = obj => inspectObject(obj, depth);
inspector = obj => inspect(obj, depth);
}
return {
handler: (tao, data) => {
Expand Down Expand Up @@ -41,17 +45,30 @@ export function TaoLogger(
verbose = !!v;
},
depth: v => {
if (!v && !v === null) {
depth = v;
if (
inspect == null ||
typeof inspect != 'function' ||
(!v && !v === null)
) {
inspector = obj => obj;
} else {
inspector = obj => inspectObject(obj, v);
inspector = obj => inspect(obj, depth);
}
},
group: v => {
group = !!v;
},
setLogger: l => {
logger = l;
},
setInspect: i => {
inspect = i;
if (i == null || typeof i != 'function' || (!depth && !depth === null)) {
inspector = obj => obj;
} else {
inspector = obj => inspect(obj, depth);
}
}
};
}

0 comments on commit 8aa6297

Please sign in to comment.