summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-02-03 04:18:27 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-02-03 04:18:27 +0900
commit238c6a428be14f484dac102289af183aec2a48fd (patch)
tree742f80c68a0f371558c1deb714256a041c09adef /src/services
parentClean up (diff)
downloadsharkey-238c6a428be14f484dac102289af183aec2a48fd.tar.gz
sharkey-238c6a428be14f484dac102289af183aec2a48fd.tar.bz2
sharkey-238c6a428be14f484dac102289af183aec2a48fd.zip
[Server] Use logger for logging
Diffstat (limited to 'src/services')
-rw-r--r--src/services/drive/add-file.ts44
-rw-r--r--src/services/drive/logger.ts3
2 files changed, 24 insertions, 23 deletions
diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts
index c6fa44a3ef..a7797351ae 100644
--- a/src/services/drive/add-file.ts
+++ b/src/services/drive/add-file.ts
@@ -3,7 +3,6 @@ import * as fs from 'fs';
import * as mongodb from 'mongodb';
import * as crypto from 'crypto';
-import * as debug from 'debug';
import * as Minio from 'minio';
import * as uuid from 'uuid';
import * as sharp from 'sharp';
@@ -23,8 +22,7 @@ import driveChart from '../../chart/drive';
import perUserDriveChart from '../../chart/per-user-drive';
import fetchMeta from '../../misc/fetch-meta';
import { GenerateVideoThumbnail } from './generate-video-thumbnail';
-
-const log = debug('misskey:drive:add-file');
+import { driveLogger } from './logger';
/***
* Save file
@@ -42,7 +40,7 @@ async function save(path: string, name: string, type: string, hash: string, size
let webpublicType = 'image/jpeg';
if (!metadata.uri) { // from local instance
- log(`creating web image`);
+ driveLogger.info(`creating web image of ${name}`);
if (['image/jpeg'].includes(type)) {
webpublic = await sharp(path)
@@ -83,10 +81,10 @@ async function save(path: string, name: string, type: string, hash: string, size
webpublicExt = 'png';
webpublicType = 'image/png';
} else {
- log(`web image not created (not an image)`);
+ driveLogger.info(`web image not created (not an image)`);
}
} else {
- log(`web image not created (from remote)`);
+ driveLogger.info(`web image not created (from remote)`);
}
// #endregion webpublic
@@ -123,7 +121,7 @@ async function save(path: string, name: string, type: string, hash: string, size
try {
thumbnail = await GenerateVideoThumbnail(path);
} catch (e) {
- console.log(`GenerateVideoThumbnail failed: ${e}`);
+ driveLogger.error(`GenerateVideoThumbnail failed: ${e}`);
}
}
// #endregion thumbnail
@@ -141,18 +139,18 @@ async function save(path: string, name: string, type: string, hash: string, size
const webpublicKey = `${config.drive.prefix}/${uuid.v4()}.${webpublicExt}`;
const thumbnailKey = `${config.drive.prefix}/${uuid.v4()}.${thumbnailExt}`;
- log(`uploading original: ${key}`);
+ driveLogger.info(`uploading original: ${key}`);
const uploads = [
upload(key, fs.createReadStream(path), type)
];
if (webpublic) {
- log(`uploading webpublic: ${webpublicKey}`);
+ driveLogger.info(`uploading webpublic: ${webpublicKey}`);
uploads.push(upload(webpublicKey, webpublic, webpublicType));
}
if (thumbnail) {
- log(`uploading thumbnail: ${thumbnailKey}`);
+ driveLogger.info(`uploading thumbnail: ${thumbnailKey}`);
uploads.push(upload(thumbnailKey, thumbnail, thumbnailType));
}
@@ -202,7 +200,7 @@ async function save(path: string, name: string, type: string, hash: string, size
fs.createReadStream(path).pipe(writeStream);
});
- log(`original stored to ${originalFile._id}`);
+ driveLogger.info(`original stored to ${originalFile._id}`);
// #endregion store original
// #region store webpublic
@@ -222,7 +220,7 @@ async function save(path: string, name: string, type: string, hash: string, size
writeStream.end(webpublic);
});
- log(`web stored ${webFile._id}`);
+ driveLogger.info(`web stored ${webFile._id}`);
}
// #endregion store webpublic
@@ -242,7 +240,7 @@ async function save(path: string, name: string, type: string, hash: string, size
writeStream.end(thumbnail);
});
- log(`thumbnail stored ${tuhmFile._id}`);
+ driveLogger.info(`thumbnail stored ${tuhmFile._id}`);
}
return originalFile;
@@ -351,7 +349,7 @@ export default async function(
const [hash, [mime, ext], size] = await Promise.all([calcHash, detectMime, getFileSize]);
- log(`hash: ${hash}, mime: ${mime}, ext: ${ext}, size: ${size}`);
+ driveLogger.info(`hash: ${hash}, mime: ${mime}, ext: ${ext}, size: ${size}`);
// detect name
const detectedName = name || (ext ? `untitled.${ext}` : 'untitled');
@@ -365,7 +363,7 @@ export default async function(
});
if (much) {
- log(`file with same hash is found: ${much._id}`);
+ driveLogger.info(`file with same hash is found: ${much._id}`);
return much;
}
}
@@ -395,7 +393,7 @@ export default async function(
return 0;
});
- log(`drive usage is ${usage}`);
+ driveLogger.info(`drive usage is ${usage}`);
const instance = await fetchMeta();
const driveCapacity = 1024 * 1024 * (isLocalUser(user) ? instance.localDriveCapacityMb : instance.remoteDriveCapacityMb);
@@ -438,12 +436,12 @@ export default async function(
// Calc width and height
const calcWh = async () => {
- log('calculate image width and height...');
+ driveLogger.info('calculating image width and height...');
// Calculate width and height
const meta = await img.metadata();
- log(`image width and height is calculated: ${meta.width}, ${meta.height}`);
+ driveLogger.info(`image width and height is calculated: ${meta.width}, ${meta.height}`);
properties['width'] = meta.width;
properties['height'] = meta.height;
@@ -451,7 +449,7 @@ export default async function(
// Calc average color
const calcAvg = async () => {
- log('calculate average color...');
+ driveLogger.info('calculating average color...');
try {
const info = await (img as any).stats();
@@ -460,7 +458,7 @@ export default async function(
const g = Math.round(info.channels[1].mean);
const b = Math.round(info.channels[2].mean);
- log(`average color is calculated: ${r}, ${g}, ${b}`);
+ driveLogger.info(`average color is calculated: ${r}, ${g}, ${b}`);
const value = info.isOpaque ? [r, g, b] : [r, g, b, 255];
@@ -516,14 +514,14 @@ export default async function(
} catch (e) {
// duplicate key error (when already registered)
if (e.code === 11000) {
- log(`already registered ${metadata.uri}`);
+ driveLogger.info(`already registered ${metadata.uri}`);
driveFile = await DriveFile.findOne({
'metadata.uri': metadata.uri,
'metadata.userId': user._id
});
} else {
- console.error(e);
+ driveLogger.error(e);
throw e;
}
}
@@ -531,7 +529,7 @@ export default async function(
driveFile = await (save(path, detectedName, mime, hash, size, metadata));
}
- log(`drive file has been created ${driveFile._id}`);
+ driveLogger.succ(`drive file has been created ${driveFile._id}`);
pack(driveFile).then(packedFile => {
// Publish driveFileCreated event
diff --git a/src/services/drive/logger.ts b/src/services/drive/logger.ts
new file mode 100644
index 0000000000..979d282cc1
--- /dev/null
+++ b/src/services/drive/logger.ts
@@ -0,0 +1,3 @@
+import Logger from "../../misc/logger";
+
+export const driveLogger = new Logger('drive', 'blue');