strapi-pfapi
Version:
a strapi plugin library uses local and redis caches to achieve single digit milliseconds on average api response time.
57 lines (50 loc) • 1.21 kB
JavaScript
;
const util = require('util');
const debug_tool = require('debug')('pfapi:debug');
module.exports = {
error,
warn,
debug,
info,
cmsg
}
function error(...args) {
const message = cmsg(args);
if (global.strapi) {
global.strapi.log.error(message);
} else {
console.error('ERROR', message);
}
}
function warn(...args) {
const message = cmsg(args);
if (global.strapi) {
global.strapi.log.warn(message);
} else {
console.warn('WARN', message);
}
}
function debug(...args) {
debug_tool(cmsg(args));
}
function info(...args) {
const message = cmsg(args);
if (global.strapi) {
global.strapi.log.info(message);
} else {
console.log('INFO', message);
}
}
function cmsg(...args) {
if (args.length === 1 && Array.isArray(args[0])) args = args[0];
let message = '';
for (const value of args) {
if (message !== '') message += ' ';
if (typeof value === 'object') {
message += util.inspect(value, {breakLength: Infinity, depth: null, colors: true});
} else {
message += String(value);
}
}
return message;
}