Set log level with env variable and add more
This commit is contained in:
parent
a60291bec2
commit
edd08cca39
4 changed files with 15 additions and 10 deletions
|
@ -1,5 +1,4 @@
|
|||
{
|
||||
"loglevel": "info",
|
||||
"http": {
|
||||
"port": 3002
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
17
imageex.js
17
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());
|
||||
});
|
||||
});
|
||||
|
|
2
index.js
2
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
|
||||
|
|
Reference in a new issue