-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
142 lines (141 loc) · 3.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
require('colors')
/**
* Good Logs
* Copyright(c) 2024 Bally Lomibao
* MIT Licensed
*/
var Key
;(function (Key) {
// @error keys
Key['Connected'] = 'CONNECTED'
Key['NotConnected'] = 'NOT CONNECTED'
Key['Environment'] = ' ENVIRONMENT: '
Key['Production'] = 'production'
Key['Development'] = 'development'
// @logger - req
Key['ReqMethod'] = ' Request Method: '
Key['ReqURL'] = ' Request URL: '
Key['ReqTime'] = ' Request Time: '
// @logger - server
Key['ServerPort'] = ' SERVER PORT: '
Key['ServerAPIVersion'] = ' API VERSION: '
Key['ServerStatus'] = ' SERVER STATUS: '
// @logger - database
Key['DBHost'] = ' DB HOST: '
Key['DBName'] = ' DB NAME: '
Key['DBStatus'] = ' DB STATUS: '
// @error
Key['Error'] = ' ERROR: '
Key['ErrorCode'] = ' CODE: '
Key['Tag'] = ' TAG: '
Key['Target'] = ' FUNC_TARGET: '
})(Key || (Key = {}))
var goodlog = {
// @type - custom
custom: function (color) {
var message = []
for (var _i = 1; _i < arguments.length; _i++) {
message[_i - 1] = arguments[_i]
}
return console.log(message.join('')[color])
},
// @type - log :Default
log: function () {
var message = []
for (var _i = 0; _i < arguments.length; _i++) {
message[_i] = arguments[_i]
}
return console.log(message.join(' ').yellow)
},
// @type - info
info: function () {
var message = []
for (var _i = 0; _i < arguments.length; _i++) {
message[_i] = arguments[_i]
}
return console.log(message.join(' ').bgCyan)
},
// @type - warn
warn: function () {
var message = []
for (var _i = 0; _i < arguments.length; _i++) {
message[_i] = arguments[_i]
}
return console.warn(message.join(' ').bgYellow)
},
// @type - table -for array and obj
tbl: function () {
var message = []
for (var _i = 0; _i < arguments.length; _i++) {
message[_i] = arguments[_i]
}
return console.table(message)
},
// @type - error
error: function (error, tag, target, ...args) {
if (tag === void 0) {
tag = ''
}
if (target === void 0) {
target = ''
}
console.log('')
console.log(Key.Tag.dim, tag.red)
console.log(Key.Target.dim, target.brightRed)
console.log(Key.Error.dim, error && error)
if (args.length > 0) {
console.log('')
console.log(Key.Error.dim, args.join(' ').red)
}
},
// @type - debug
debug: function () {
var message = []
for (var _i = 0; _i < arguments.length; _i++) {
message[_i] = arguments[_i]
}
return console.debug(message.join(' ').bgRed)
},
req: function (req, res) {
console.log('')
console.log(Key.ReqMethod.dim, req.method.yellow.bold)
console.log(Key.ReqURL.dim, req.url.yellow.bold)
console.log(Key.ReqTime.dim, new Date().toString().yellow.bold)
console.log('')
},
/**
*
* @param port - server port
* @param apiRoot - api version
* @param env - status of the server environment
* @param isConnected - send the status of the server connection
* @return void
*/
server: function (port, apiRoot, env, isConnected) {
console.log(Key.ServerPort.dim, port.yellow)
console.log(Key.ServerAPIVersion.dim, apiRoot.yellow)
if (env === Key.Production) {
console.log(Key.Environment.dim, Key.Production.blue.bold)
} else {
console.log(Key.Environment.dim, Key.Development.white.bold)
}
if (isConnected) {
console.log(Key.ServerStatus.dim, Key.Connected.green.bold)
} else {
console.log(Key.ServerStatus.dim, Key.NotConnected.red.bold)
}
},
// @preset - database
db: function (host, dbName, isConnected) {
console.log(Key.DBHost.dim, host.brightYellow)
console.log(Key.DBName.dim, dbName.brightMagenta)
if (isConnected) {
console.log(Key.DBStatus.dim, Key.Connected.green.bold)
} else {
console.log(Key.DBStatus.dim, Key.NotConnected.red.bold)
}
},
}
module.exports = goodlog