smartlog-destination-local/ts/beautylog.log.ts

99 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-03-01 00:06:12 +00:00
import 'typings-global';
2016-02-23 13:34:40 +00:00
2018-03-01 00:06:12 +00:00
import { internalLog } from './beautylog.log.helpers';
2016-02-23 13:34:40 +00:00
/**
* logs an info to console
* @param logText
* @returns {boolean}
*/
2016-07-23 23:17:38 +00:00
2018-03-01 00:06:12 +00:00
export let log = logText => {
return internalLog('log', logText);
};
2016-07-23 23:17:38 +00:00
2018-03-01 00:06:12 +00:00
export let info = logText => {
return internalLog('info', logText);
};
2016-02-23 13:34:40 +00:00
/**
* logs an 'OK!' message to console
* @param logText
* @returns {boolean}
*/
2018-03-01 00:06:12 +00:00
export let ok = logText => {
return internalLog('ok', logText);
};
2016-02-23 13:34:40 +00:00
/**
* logs a success to console
* @param logText string to log as error
* @returns {boolean}
*/
2018-03-01 00:06:12 +00:00
export let success = logText => {
return internalLog('success', logText);
};
2016-02-23 13:34:40 +00:00
/**
* logs a 'warn:' message to console
* @param logText string to log as error
* @returns {boolean}
*/
2018-03-01 00:06:12 +00:00
export let warn = logText => {
return internalLog('warn', logText);
};
2016-05-02 00:23:40 +00:00
/**
* logs an error to console
* @param logText
* @returns {boolean}
*/
2018-03-01 00:06:12 +00:00
export let error = logText => {
return internalLog('error', logText);
};
2016-05-02 00:23:40 +00:00
/**
* logs an directory to console
* @param logText
* @returns {boolean}
*/
2018-03-01 00:06:12 +00:00
export let dir = logText => {
return internalLog('dir', logText);
};
2016-06-16 00:17:28 +00:00
2017-01-21 22:12:39 +00:00
/**
* note
*/
2018-03-01 00:06:12 +00:00
export let note = logText => {
return internalLog('note', logText);
};
2017-01-21 22:12:39 +00:00
2016-06-16 21:57:49 +00:00
/**
* creates a new empty line
* @param linesArg
* @returns void
*/
2016-10-16 00:26:43 +00:00
export let newLine = (linesArg: number = 1) => {
2017-08-28 11:14:35 +00:00
for (let i = 0; i < linesArg; i++) {
2018-03-01 00:06:12 +00:00
console.log('\n');
2017-08-28 11:14:35 +00:00
}
2018-03-01 00:06:12 +00:00
};
2016-06-16 21:57:49 +00:00
/**
* logs a reduced log that only logs changes of consequential log messages
*/
2017-08-28 11:14:35 +00:00
export let logReduced = (logTextArg: string, repeatEveryTimesArg: number = 0) => {
2018-03-01 00:06:12 +00:00
if (
logTextArg === previousMessage &&
(repeatEveryTimesArg === 0 || sameMessageCounter !== repeatEveryTimesArg)
) {
sameMessageCounter++;
2017-08-28 11:14:35 +00:00
} else {
2018-03-01 00:06:12 +00:00
sameMessageCounter = 0;
previousMessage = logTextArg;
log(logTextArg);
2017-08-28 11:14:35 +00:00
}
2018-03-01 00:06:12 +00:00
};
let previousMessage: string = '';
let sameMessageCounter: number = 0;