diff --git a/config.default.json b/config.default.json index 082aa3b..7514220 100644 --- a/config.default.json +++ b/config.default.json @@ -1,5 +1,4 @@ { - "loglevel": "info", "http": { "port": 3002 }, diff --git a/filters.js b/filters.js index 54afeb7..d5d0cec 100644 --- a/filters.js +++ b/filters.js @@ -2,6 +2,9 @@ const _ = require('lodash'); const Canvas = require('canvas'); const { _drawImage } = require('./imageex'); +const logger = require('loglevel'); +logger.setLevel(process.env.LOGLEVEL || 'info'); + const { createCanvas, Image } = Canvas; const filters = { @@ -13,7 +16,7 @@ const filters = { const tmpCtx = tmpCanvas.getContext('2d'); _drawImage(tmpCtx, frame.canvas, x, y, basicProps); const multiplyProps = _.extend({}, props, { attributes: { globalCompositeOperation: 'multiply' } }); - console.log('multiply props:', multiplyProps); + logger.debug('multiply props:', multiplyProps); _drawImage(tmpCtx, source.frames[0].canvas, x, y, multiplyProps); diff --git a/imageex.js b/imageex.js index f9c0a4a..a117bd2 100644 --- a/imageex.js +++ b/imageex.js @@ -7,6 +7,9 @@ const mime = require('mime-types'); const { GifReader } = require('omggif'); const GifEncoder = require('gifencoder'); +const logger = require('loglevel'); +logger.setLevel(process.env.LOGLEVEL || 'info'); + const { createCanvas } = Canvas; const { Image } = Canvas; @@ -33,13 +36,13 @@ function _drawImage(ctx, img, x, y, args = {}) { ctx.save(); if (args.transform) { _.each(args.transform, (val, prop) => { - console.log(`Transforming ${prop} by ${val}`); + logger.debug(`Transforming ${prop} by ${val}`); ctx[prop](...val); }); } if (args.attributes) { _.each(args.attributes, (val, prop) => { - console.log(`Setting ${prop} to ${val}`); + logger.debug(`Setting ${prop} to ${val}`); ctx[prop] = val; }); } @@ -62,7 +65,7 @@ class ImageEx { this.type = result.type; this.data = result.data; if (this.type === 'image/gif') { - console.log(uri, 'loaded'); + logger.debug(uri, 'loaded'); this.initGif(); } else { this.initStatic(); @@ -76,10 +79,10 @@ class ImageEx { const reader = new GifReader(new Uint8Array(this.data)); this.width = reader.width; this.height = reader.height; - console.log('Decoding frames'); + logger.debug('Decoding frames'); this.frames = this.decodeFrames(reader); - console.log('Frames decoded!'); + logger.debug('Frames decoded!'); this.renderAllFrames(); return this; @@ -128,7 +131,7 @@ class ImageEx { let saved; for (let i = 0; i < this.frames.length; ++i) { const frame = this.frames[i]; - console.log('Rendering frame', frame); + logger.debug('Rendering frame', frame); if (typeof disposeFrame === 'function') disposeFrame(); switch (frame.disposal) { @@ -281,7 +284,7 @@ class CanvasEx { return new Promise(resolve => { buf.on('finish', () => { - console.log('Render completed'); + logger.debug('Render completed'); resolve(buf.getContents()); }); }); diff --git a/index.js b/index.js index f630a16..2b04c09 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ const config = require('./config.default.json'); const filters = require('./filters.js'); const logger = require('loglevel'); -logger.setLevel(config.loglevel || 'info'); +logger.setLevel(process.env.LOGLEVEL || 'info'); try { _.extend(config, require(`./${process.env.CONFIG || 'config'}`)); // eslint-disable-line global-require