Unverified Kaydet (Commit) 9460aaf3 authored tarafından Ali GOREN's avatar Ali GOREN Kaydeden (comit) GitHub

Merge pull request #3 from aligoren/dev

Colors added, debug in todo
This diff is collapsed.
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"dev": "node tests/index.js", "dev": "node tests/index.js",
"doc": "esdoc",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"keywords": [ "keywords": [
......
// reference: https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
/**
* This colors only works on Node Runtime
*/
const nodeColors = {
Reset : "\x1b[0m",
Bright : "\x1b[1m",
Dim : "\x1b[2m",
Underscore : "\x1b[4m",
Blink : "\x1b[5m",
Reverse : "\x1b[7m",
Hidden : "\x1b[8m",
FgBlack : "\x1b[30m",
FgRed : "\x1b[31m",
FgGreen : "\x1b[32m",
FgYellow : "\x1b[33m",
FgBlue : "\x1b[34m",
FgMagenta : "\x1b[35m",
FgCyan : "\x1b[36m",
FgWhite : "\x1b[37m",
BgBlack : "\x1b[40m",
BgRed : "\x1b[41m",
BgGreen : "\x1b[42m",
BgYellow : "\x1b[43m",
BgBlue : "\x1b[44m",
BgMagenta : "\x1b[45m",
BgCyan : "\x1b[46m",
BgWhite : "\x1b[47m",
}
class Colors {
/**
*
* @param type - Type web or node
*/
static GET(type: string) {
if (type == "node") {
return nodeColors
} else {
}
}
}
export default Colors
\ No newline at end of file
/**
* @description If the server config is wrong like endPoint, this exception will fire.
* @class ServerException
*/
class ServerException extends Error { class ServerException extends Error {
constructor(message) { constructor(message) {
super(); super();
......
import LogTypes, { Levels } from './LogTypes' import LogTypes, { Levels } from './LogTypes'
import LogServer from './LogServer' import LogServer from './LogServer'
import Colors from './Colors'
/** /**
* @description Logger class. This class will have logging functions * @description Logger class. This class will have logging functions
...@@ -26,7 +27,7 @@ class Logger { ...@@ -26,7 +27,7 @@ class Logger {
/** /**
* @description Send extra fields to the log backend * @description Send extra fields to the log backend
* @function send * @function send
* @param sendBody Extra body field * @param sendBody - Extra body field
* @example * @example
* loggerInstance.send({ pageUrl: 'test', 'time': '12:30' }) * loggerInstance.send({ pageUrl: 'test', 'time': '12:30' })
*/ */
...@@ -37,24 +38,28 @@ class Logger { ...@@ -37,24 +38,28 @@ class Logger {
/** /**
* @description Debug Level Message * @description Debug Level Message
* @function debug * @function debug
* @param message any type of message * @param message - any type of message
* @param context Context will use to handle params. For example user IP address, username etc. * @param context - Context will use to handle params. For example user IP address, username etc.
* @example * @example
* loggerInstance.debug('Debug User', { username: 'John' }) * loggerInstance.debug('Debug User', { username: 'John' })
*/ */
debug(message: string, context: any) { debug(message: string, context: any) {
const logCode = LogTypes.DEBUG const logCode = LogTypes.DEBUG
const levelName = Levels.GET(logCode) const levelName = Levels.GET(logCode)
const colors = Colors.GET('node')
/**
* @todo This section will change. This needs formatted output
*/
console.log(logCode, levelName) console.log(logCode, levelName)
console.log(`${colors.FgWhite}${colors.BgRed}%s`, `${levelName}`, colors.Reset, '-', message);
} }
/** /**
* @description Informational messages * @description Informational messages
* @function info * @function info
* @param message any type of message * @param message - any type of message
* @param context Context will use to handle params. For example user IP address, username etc. * @param context - Context will use to handle params. For example user IP address, username etc.
* @example * @example
* loggerInstance.info('Info User', { username: 'John' }) * loggerInstance.info('Info User', { username: 'John' })
*/ */
...@@ -69,8 +74,8 @@ class Logger { ...@@ -69,8 +74,8 @@ class Logger {
/** /**
* @description Normal but significant condition * @description Normal but significant condition
* @function notice * @function notice
* @param message any type of message * @param message - any type of message
* @param context Context will use to handle params. For example user IP address, username etc. * @param context - Context will use to handle params. For example user IP address, username etc.
* @example * @example
* loggerInstance.notice('Notice User', { username: 'John' }) * loggerInstance.notice('Notice User', { username: 'John' })
*/ */
...@@ -85,8 +90,8 @@ class Logger { ...@@ -85,8 +90,8 @@ class Logger {
/** /**
* @description You can use to show deprecated messages, old API or functions * @description You can use to show deprecated messages, old API or functions
* @function warning * @function warning
* @param message any type of message * @param message - any type of message
* @param context Context will use to handle params. For example user IP address, username etc. * @param context - Context will use to handle params. For example user IP address, username etc.
* @example * @example
* loggerInstance.warning('Warning User', { username: 'John' }) * loggerInstance.warning('Warning User', { username: 'John' })
*/ */
...@@ -101,8 +106,8 @@ class Logger { ...@@ -101,8 +106,8 @@ class Logger {
/** /**
* @description Runtime errors, for example when parseInt or toFixed errors work wrong * @description Runtime errors, for example when parseInt or toFixed errors work wrong
* @function error * @function error
* @param message any type of message * @param message - any type of message
* @param context Context will use to handle params. For example user IP address, username etc. * @param context - Context will use to handle params. For example user IP address, username etc.
* @example * @example
* loggerInstance.error('Error User', { username: 'John' }) * loggerInstance.error('Error User', { username: 'John' })
*/ */
...@@ -117,8 +122,8 @@ class Logger { ...@@ -117,8 +122,8 @@ class Logger {
/** /**
* @description Components unavailable or unexpected exceptions * @description Components unavailable or unexpected exceptions
* @function critical * @function critical
* @param message any type of message * @param message - any type of message
* @param context Context will use to handle params. For example user IP address, username etc. * @param context - Context will use to handle params. For example user IP address, username etc.
* @example * @example
* loggerInstance.critical('Critical message User', { username: 'John' }) * loggerInstance.critical('Critical message User', { username: 'John' })
*/ */
...@@ -133,8 +138,8 @@ class Logger { ...@@ -133,8 +138,8 @@ class Logger {
/** /**
* @description Action must be taken immediately. * @description Action must be taken immediately.
* @function alert * @function alert
* @param message any type of message * @param message - any type of message
* @param context Context will use to handle params. For example user IP address, username etc. * @param context - Context will use to handle params. For example user IP address, username etc.
* @example * @example
* loggerInstance.alert('Alert message User', { username: 'John' }) * loggerInstance.alert('Alert message User', { username: 'John' })
*/ */
...@@ -149,8 +154,8 @@ class Logger { ...@@ -149,8 +154,8 @@ class Logger {
/** /**
* @description System is unusable * @description System is unusable
* @function emergency * @function emergency
* @param message any type of message * @param message - any type of message
* @param context Context will use to handle params. For example user IP address, username etc. * @param context - Context will use to handle params. For example user IP address, username etc.
* @example * @example
* loggerInstance.emergency('Emergency message User', { username: 'John' }) * loggerInstance.emergency('Emergency message User', { username: 'John' })
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment