Initial commit
This commit is contained in:
11
payload/core/connect.v
Normal file
11
payload/core/connect.v
Normal file
@@ -0,0 +1,11 @@
|
||||
module core
|
||||
|
||||
import net.websocket
|
||||
|
||||
fn connect_ws(url string) ?&websocket.Client {
|
||||
mut ws := websocket.new_client(url) ?
|
||||
|
||||
ws.connect() ?
|
||||
|
||||
return &ws
|
||||
}
|
||||
11
payload/core/constants.v
Normal file
11
payload/core/constants.v
Normal file
@@ -0,0 +1,11 @@
|
||||
module core
|
||||
|
||||
__global (
|
||||
logs Logger
|
||||
)
|
||||
|
||||
pub fn initialize() {
|
||||
logs = Logger{}
|
||||
|
||||
logs.debug('core:constants:initialize', 'test')
|
||||
}
|
||||
46
payload/core/logger.v
Normal file
46
payload/core/logger.v
Normal file
@@ -0,0 +1,46 @@
|
||||
module core
|
||||
|
||||
import time
|
||||
|
||||
enum LogLevel {
|
||||
info
|
||||
debug
|
||||
error
|
||||
}
|
||||
|
||||
pub struct Logger {
|
||||
mut:
|
||||
logs string
|
||||
}
|
||||
|
||||
fn log_level_str(level LogLevel) string {
|
||||
return match level {
|
||||
.info { 'INFO' }
|
||||
.debug { 'DEBUG' }
|
||||
.error { 'ERROR' }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut l Logger) log(mod string, level LogLevel, msg string) {
|
||||
timestamp := time.now().format_ss_milli()
|
||||
full_msg := '[$timestamp] [${log_level_str(level)}] [$mod] $msg'
|
||||
|
||||
println(full_msg)
|
||||
|
||||
l.logs += full_msg + '\n'
|
||||
}
|
||||
|
||||
pub fn (mut l Logger) info(mod string, msg string) {
|
||||
l.log(mod, .info, msg)
|
||||
}
|
||||
|
||||
pub fn (mut l Logger) debug(mod string, msg string) {
|
||||
l.log(mod, .debug, msg)
|
||||
}
|
||||
|
||||
pub fn (mut l Logger) error(mod string, msg string) {
|
||||
l.log(mod, .error, msg)
|
||||
}
|
||||
pub fn (l Logger) get_logs() string {
|
||||
return l.logs
|
||||
}
|
||||
Reference in New Issue
Block a user