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