Set log level with env variable and add more

This commit is contained in:
Manuel 2021-05-05 08:28:31 +02:00
parent a60291bec2
commit edd08cca39
Signed by: SunRed
GPG Key ID: 4085037435E1F07A
4 changed files with 15 additions and 10 deletions

View File

@ -1,5 +1,4 @@
{
"loglevel": "info",
"http": {
"port": 3002
},

View File

@ -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);

View File

@ -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());
});
});

View File

@ -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