All files / src logger.ts

60% Statements 6/10
0% Branches 0/2
66.66% Functions 2/3
60% Lines 6/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 261x   1x         1x 1x       1x 1x                        
import joplin from "api";
 
export class Logger {
    private logsFile: string;
    private platform: string;
 
    private async initPlatform() {
        const version = await joplin.versionInfo();
        this.platform = version.platform;
    }
 
    constructor(profileDir: string) {
        this.logsFile = `${profileDir}/templates-logs.txt`;
        this.initPlatform();
    }
 
    public async log(message: string): Promise<void> {
        if (this.platform === "desktop") {
            const fs = joplin.require("fs-extra");
            await fs.appendFile(this.logsFile, `[${new Date().toISOString()}]\n${message}\n\n\n`);
        } else {
            console.log(`Templates Plugin: ${message}`);
        }
    }
}