-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update cli for new version of core
- Loading branch information
Showing
9 changed files
with
43 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,27 @@ | ||
import * as winston from "winston"; | ||
import * as program from "commander"; | ||
import { AbstractLog } from "steem-wise-core"; | ||
|
||
import { Log as SteemWiseCoreLog } from "steem-wise-core"; | ||
export class Log extends AbstractLog { | ||
private static INSTANCE: Log = new Log(); | ||
|
||
export class Log { | ||
public static configureLoggers(program: program.Command) { | ||
const verboseOrDebug = !!program.debug || !!program.verbose; | ||
// cli logger | ||
Log.getLogger().add( | ||
new winston.transports.Console({ | ||
format: winston.format.combine( | ||
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), | ||
winston.format.printf(info => { | ||
if (verboseOrDebug) { | ||
return `${info.timestamp} [${info.level}]: ${info.message}`; | ||
} | ||
else { | ||
return `${info.message}`; | ||
} | ||
}) | ||
), | ||
handleExceptions: true, | ||
timestamp: true, | ||
} as object) | ||
); | ||
Log.getLogger().level = "warn"; | ||
|
||
if (program.debug) { | ||
console.log("Setting steem-wise-core log level to \"debug\""); | ||
SteemWiseCoreLog.setLevel("debug"); | ||
|
||
console.log("Setting steem-wise-cli log level to \"debug\""); | ||
Log.getLogger().level = "debug"; | ||
} | ||
else if (program.verbose) { | ||
console.log("Setting steem-wise-core log level to \"info\""); | ||
SteemWiseCoreLog.setLevel("info"); | ||
|
||
console.log("Setting steem-wise-cli log level to \"info\""); | ||
Log.getLogger().level = "info"; | ||
} | ||
} | ||
|
||
public static setLevel(level: string) { | ||
Log.getLogger().level = level; | ||
} | ||
|
||
public static getLogger(): winston.Logger { | ||
return (winston.loggers as any).get("steem-wise-cli"); | ||
} | ||
|
||
public static cheapDebug(debugStringReturnerFn: () => string): void { | ||
const logger = Log.getLogger(); | ||
if (logger.levels[logger.level] >= logger.levels["debug"]) logger.debug(debugStringReturnerFn()); | ||
} | ||
|
||
public static cheapInfo(infoStringReturnerFn: () => string): void { | ||
const logger = Log.getLogger(); | ||
if (logger.levels[logger.level] >= logger.levels["info"]) logger.debug(infoStringReturnerFn()); | ||
private constructor() { | ||
super("steem-wise-cli"); | ||
} | ||
|
||
public static exception(error: Error, level: string = "error"): void { | ||
const logger = Log.getLogger(); | ||
logger.log(level, error.name + ": " + error.message | ||
+ (logger.levels[logger.level] >= logger.levels["info"] && error.stack ? "\n" + error.stack : "")); | ||
public initialize(debug: boolean, verbose: boolean) { | ||
super.init([ | ||
(debug ? "debug" : undefined ), | ||
(verbose ? "verbose" : undefined ), | ||
process.env.WISE_CLI_LOG_LEVEL, | ||
process.env.WISE_LOG_LEVEL, | ||
"info" | ||
]); | ||
} | ||
|
||
public static promiseResolveDebug<T>(msgBeginning: string, result: T): T { | ||
Log.cheapDebug(() => msgBeginning + JSON.stringify(result)); | ||
return result; | ||
public init() { | ||
throw new Error("Instead of #init() please call #initialize(debug, verbose) which indirectly overrides init"); | ||
} | ||
|
||
public static promiseRejectionDebug<T>(msgBeginning: string, error: T): T { | ||
Log.cheapDebug(() => msgBeginning + JSON.stringify(error)); | ||
throw error; | ||
public static log(): Log { | ||
return Log.INSTANCE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters