Skip to content

Commit

Permalink
chore: improve log format
Browse files Browse the repository at this point in the history
Signed-off-by: Gustav Grusell <[email protected]>
  • Loading branch information
grusell committed Aug 22, 2024
1 parent da95d74 commit 1f60529
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/analysis/brute-force.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export default async function analyzeBruteForce(
const skip =
options.skipTranscode || (options.skipExisting && fs.existsSync(outFile));
if (options.skipTranscode) {
console.log(`Skipping transcode for ${outFile}`);
logger.info(`Skipping transcode for ${outFile}`);
} else if (options.skipExisting && fs.existsSync(outFile)) {
console.log(`Skipping transcode for ${outFile} because file exists`);
logger.info(`Skipping transcode for ${outFile} because file exists`);
}
const variant = skip
? outFile
Expand Down
16 changes: 8 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ async function run() {

async function runSuggestLadder(argv) {
const { ladder, pairs } = await suggestLadder(argv.folder);
console.log(`ladder: ${ladder}`);
logger.info(`ladder: ${ladder}`);
ladder.forEach((rung) => {
console.log(rung);
logger.info(rung);
});
}

Expand Down Expand Up @@ -210,7 +210,7 @@ async function exportWmafResultToCsv(argv) {
async function transcodeAndAnalyse(argv) {
const job: any = await updateJobDefinition(argv);
const models: string[] = job.models;
console.log('Running job: ', job);
logger.info('Running job: ', job);

const vmafScores = await createJob(
job as JobDescription,
Expand All @@ -219,7 +219,7 @@ async function transcodeAndAnalyse(argv) {
argv.parallel
);

console.log(
logger.info(
`saveAsCsv: ${job.saveAsCsv}, ` +
(job.saveAsCsv
? `also saving results as a .csv file.`
Expand Down Expand Up @@ -284,9 +284,9 @@ async function updateJobDefinition(argv) {
job.pipeline.pythonPath = job.pipeline.pythonPath || pythonPath;
job.pipeline.ffmpegPath = job.pipeline.ffmpegPath || ffmpegPath;
job.pipeline.easyVmafPath = job.pipeline.easyVmafPath || easyVmafPath;
console.log('Python path: ', pythonPath);
console.log('FFmpeg path: ', ffmpegPath);
console.log('EasyVmaf path: ', easyVmafPath);
logger.info('Python path: ', pythonPath);
logger.info('FFmpeg path: ', ffmpegPath);
logger.info('EasyVmaf path: ', easyVmafPath);
*/
job.method = job.method || 'bruteForce';
Expand All @@ -304,7 +304,7 @@ async function readJobDefinition(file) {
const baseName = definition.name;
let i = 1;
while (await pathExists(definition.name)) {
console.log(definition.name);
logger.info(definition.name);
definition.name = `${baseName}-${i}`;
i++;
}
Expand Down
10 changes: 9 additions & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { createLogger, transports, format } from 'winston';

const logFormat = format.printf( ({ level, message, timestamp , ...metadata}) => {
let msg = `${timestamp} [${level}] : ${message} `
if(metadata && Object.keys(metadata).length > 0) {
msg += JSON.stringify(metadata)
}
return msg
});

export default createLogger({
level: process.env.LOG_LEVEL || 'info',
format: format.combine(format.colorize(), format.simple()),
format: format.combine(format.colorize(), format.timestamp(), logFormat),
transports: [new transports.Console()]
});
8 changes: 4 additions & 4 deletions src/pipelines/aws/aws-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ export default class AWSPipeline implements Pipeline {
(targetBitrate * 2).toString()
);

console.log(`variables: ${variables}`);
logger.debug(`variables: ${JSON.stringify(variables)}`);
//Handle pipelineVariables given in the JobDescription
if (variables) {
Object.entries(variables).forEach(([key, value]) => {
const replace = '${' + `${key}` + '}';
console.debug(`Replacing ${replace} with ${value}`);
logger.debug(`Replacing ${replace} with ${value}`);
settingsStr = this.stringReplacement(
settingsStr,
replace,
Expand Down Expand Up @@ -405,15 +405,15 @@ export default class AWSPipeline implements Pipeline {
private async copyMetadataFile(outputBucket: string, distortedFilename: string, outputObject: string) {
let key = `results/${outputObject}`.replace('_vmaf.json', '_metadata.json');
if ( await this.fileExists(outputBucket, key)) {
console.debug(`Metadata file already exists: ${key}`);
logger.debug(`Metadata file already exists: ${key}`);
return;
}
const input = {
Bucket: outputBucket,
CopySource: this.transcodedUriToMetadataUri(distortedFilename).replace('s3:/', ''),
Key: key
};
console.debug(`Uploading metadata: ${JSON.stringify(input)}`);
logger.debug(`Uploading metadata: ${JSON.stringify(input)}`);
const command = new CopyObjectCommand(input);
await this.s3.send(command);
}
Expand Down

0 comments on commit 1f60529

Please sign in to comment.