...
 
Commits (2)
......@@ -24,7 +24,7 @@ Error("error message");
## Web usage (global script import)
Include: `<script src="https://unpkg.com/log74@1.0.3/dist/index.webpack.js"></script>`
Include: `<script src="https://unpkg.com/log74@1.0.4/dist/index.webpack.js"></script>`
```javascript
// functions are bound to window object
......
......@@ -18,7 +18,7 @@
"prod:node": "tsc"
},
"name": "log74",
"version": "1.0.3",
"version": "1.0.4",
"description": "Mini logging library for Node.js and the web.",
"main": "dist/index.node.js",
"repository": "https://gitlab.insrt.uk/insert/log74.git",
......
export type Result = (raw: string, formatted?: string) => void;
\ No newline at end of file
export enum LogLevel {
Error,
Warn,
Info,
Success,
Log,
Debug
};
export type Result = (raw: string, level: LogLevel, formatted?: string) => void;
\ No newline at end of file
import chalk from 'chalk';
import { Result } from './common/result';
import { Result, LogLevel } from './common/result';
import LoggerClass from './common/logger';
/**
......@@ -9,7 +9,7 @@ import LoggerClass from './common/logger';
export function Error(string: string, cb?: Result) {
let output = chalk`{bgRed {white ✖ ERR }} {red ${string}}`;
console.error(output);
cb && cb(`ERR: ${string}`, output);
cb && cb(`[${new Date().toUTCString()}] ERR: ${string}`, LogLevel.Error, output);
}
/**
......@@ -18,7 +18,7 @@ export function Error(string: string, cb?: Result) {
export function Warn(string: string, cb?: Result) {
let output = chalk`{bgYellow {black ⚠ WARN }} {white ${string}}`;
console.warn(output);
cb && cb(`WARN: ${string}`, output);
cb && cb(`[${new Date().toUTCString()}] WARN: ${string}`, LogLevel.Warn, output);
}
/**
......@@ -27,7 +27,7 @@ export function Warn(string: string, cb?: Result) {
export function Info(string: string, cb?: Result) {
let output = chalk`{bgBlue {white ℹ️ INFO }} {white ${string}}`;
console.info(output);
cb && cb(`INFO: ${string}`, output);
cb && cb(`[${new Date().toUTCString()}] INFO: ${string}`, LogLevel.Info, output);
}
/**
......@@ -36,7 +36,7 @@ export function Info(string: string, cb?: Result) {
export function Success(string: string, cb?: Result) {
let output = chalk`{bgGreen {black ✔️ SUCCESS }} {white ${string}}`;
console.log(output);
cb && cb(`SUCCESS: ${string}`, output);
cb && cb(`[${new Date().toUTCString()}] SUCCESS: ${string}`, LogLevel.Success, output);
}
/**
......@@ -45,7 +45,16 @@ export function Success(string: string, cb?: Result) {
export function Log(string: string, cb?: Result) {
let output = chalk`{bgWhite {black LOG }} {gray ${string}}`;
console.log(output);
cb && cb(`LOG: ${string}`, output);
cb && cb(`[${new Date().toUTCString()}] LOG: ${string}`, LogLevel.Log, output);
}
/**
* Write a debug message
*/
export function Debug(string: string, cb?: Result) {
let output = chalk`{gray [DEBUG] ${string}}`;
console.log(output);
cb && cb(`[${new Date().toUTCString()}] DEBUG: ${string}`, LogLevel.Debug, output);
}
/**
......@@ -57,6 +66,8 @@ export class Logger extends LoggerClass {
info(string: string) {Info(string, this.l)};
success(string: string) {Success(string, this.l)};
log(string: string) {Log(string, this.l)};
debug(string: string) {Debug(string, this.l)};
};
export default Logger;
\ No newline at end of file
export default Logger;
export * from './common/result';
\ No newline at end of file
import { Result } from './common/result';
import { Result, LogLevel } from './common/result';
import Logger from './common/logger';
/**
* Write an error message
*/
export function Error(string: string, cb?: Result) {
console.error(`%c✖ ERR %c${string}`, 'color: red; font-size: 1.6em', 'color: white');
cb && cb(`ERR: ${string}`);
console.error(`%c✖ ERR %c${string}`, 'color: red; font-size: 1.6em', 'color: white; font-size: 1.4em');
cb && cb(`[${new Date().toUTCString()}] ERR: ${string}`, LogLevel.Error);
}
/**
* Write a warning message
*/
export function Warn(string: string, cb?: Result) {
console.warn(`%c⚠ WARN %c${string}`, 'color: yellow; font-size: 1.6em', 'color: white');
cb && cb(`WARN: ${string}`);
console.warn(`%c⚠ WARN %c${string}`, 'color: yellow; font-size: 1.6em', 'color: white; font-size: 1.4em');
cb && cb(`[${new Date().toUTCString()}] WARN: ${string}`, LogLevel.Warn);
}
/**
* Write an info message
*/
export function Info(string: string, cb?: Result) {
console.info(`%cℹ️ INFO %c${string}`, 'color: #6298ef; font-size: 1.6em', 'color: white');
cb && cb(`WARN: ${string}`);
console.info(`%cℹ️ INFO %c${string}`, 'color: #6298ef; font-size: 1.6em', 'color: white; font-size: 1.4em');
cb && cb(`[${new Date().toUTCString()}] WARN: ${string}`, LogLevel.Info);
}
/**
* Write a success message
*/
export function Success(string: string, cb?: Result) {
console.info(`%c✔️ SUCCESS %c${string}`, 'color: green; font-size: 1.6em', 'color: white');
cb && cb(`SUCCESS: ${string}`);
console.info(`%c✔️ SUCCESS %c${string}`, 'color: green; font-size: 1.6em', 'color: white; font-size: 1.4em');
cb && cb(`[${new Date().toUTCString()}] SUCCESS: ${string}`, LogLevel.Success);
}
/**
* Write a 'notice' message
*/
export function Log(string: string, cb?: Result) {
console.info(`%cLOG %c${string}`, 'color: gray; font-size: 1.6em', 'color: white');
cb && cb(`LOG: ${string}`);
console.info(`%cLOG %c${string}`, 'color: gray; font-size: 1.6em', 'color: white; font-size: 1.4em');
cb && cb(`[${new Date().toUTCString()}] LOG: ${string}`, LogLevel.Log);
}
/**
* Write a debug message
*/
export function Debug(string: string, cb?: Result) {
console.info(`%cDEBUG ${string}`, 'color: gray; font-size: 1.6em', 'font-size: 1.4em');
cb && cb(`[${new Date().toUTCString()}] LOG: ${string}`, LogLevel.Debug);
}
/**
......@@ -50,13 +58,5 @@ export class WebLogger extends Logger {
info(string: string) {Info(string, this.l)};
success(string: string) {Success(string, this.l)};
log(string: string) {Log(string, this.l)};
};
const win: any = window;
win.Error = Error;
win.Warn = Warn;
win.Info = Info;
win.Success = Success;
win.Log = Log;
win.Logger = WebLogger;
\ No newline at end of file
debug(string: string) {Debug(string, this.l)};
};
\ No newline at end of file
......@@ -7,4 +7,5 @@ win.Warn = web.Warn;
win.Info = web.Info;
win.Success = web.Success;
win.Log = web.Log;
win.Debug = web.Debug;
win.Logger = web.WebLogger;
\ No newline at end of file