diff --git a/ts/bin/index.ts b/ts/bin/index.ts index 724d3d70..985c8230 100755 --- a/ts/bin/index.ts +++ b/ts/bin/index.ts @@ -5,6 +5,7 @@ import * as fs from 'fs'; import * as path from 'path'; import Server from '../server/app'; import Analyser from '../analyser'; +import { LogLevel } from '../domain'; var args = minimist(process.argv.slice(2), { alias: { @@ -12,9 +13,10 @@ var args = minimist(process.argv.slice(2), { help: 'h', port: 'p', version: 'v', - open: 'o' + open: 'o', + quiet: 'q', }, - boolean: ['serve', 'help', 'version', 'open'], + boolean: ['serve', 'help', 'version', 'open', 'quiet'], string: ['port', 'elm-format-path', 'format'] }); @@ -29,7 +31,8 @@ var args = minimist(process.argv.slice(2), { port: args.port || 3000, elmFormatPath: elmFormatPath, format: validFormats.indexOf(args.format) != -1 ? args.format : 'human', - open: args.open || false + open: args.open || false, + logLevel: args.quiet ? LogLevel.ERROR : LogLevel.INFO }; const info = { version: elmAnalyseVersion, @@ -50,6 +53,7 @@ var args = minimist(process.argv.slice(2), { console.log(' --serve, -s Enable server mode. Disabled by default.'); console.log(' --port, -p The port on which the server should listen. Defaults to 3000.'); console.log(' --open, -o Open default browser when server goes live.'); + console.log(' --quiet, -q Print fewer log messages.'); console.log(' --elm-format-path Path to elm-format. Defaults to `elm-format`.'); console.log(' --format Output format for CLI. Defaults to "human". Options "human"|"json"'); process.exit(1); diff --git a/ts/domain.ts b/ts/domain.ts index 00eb1e12..55a8416d 100644 --- a/ts/domain.ts +++ b/ts/domain.ts @@ -1,11 +1,19 @@ interface Info { config: Config; } + +enum LogLevel { + INFO, + WARN, + ERROR, +} + interface Config { format: string | undefined; open: boolean; port: number; elmFormatPath: string; + logLevel: LogLevel; } export interface DependencyPointer { @@ -48,7 +56,7 @@ export interface FixedFile { } export interface LogMessage { - level: string; + level: keyof typeof LogLevel; message: string; } interface ElmApp { @@ -182,5 +190,6 @@ export { FileContentSha, EditorElmApp, EditorMessage, - EditorData + EditorData, + LogLevel }; diff --git a/ts/util/logging-ports.ts b/ts/util/logging-ports.ts index f3b90667..d22e9420 100644 --- a/ts/util/logging-ports.ts +++ b/ts/util/logging-ports.ts @@ -1,9 +1,11 @@ -import { Config, ElmApp, LogMessage } from '../domain'; +import { Config, ElmApp, LogLevel, LogMessage } from '../domain'; export function setup(app: ElmApp, config: Config) { if (config.format === 'human') { app.ports.log.subscribe((data: LogMessage) => { - console.log(data.level + ':', data.message); + if (LogLevel[data.level] >= config.logLevel) { + console.log(data.level + ':', data.message); + } }); } }