mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
improve logging
This commit is contained in:
parent
c823b81dda
commit
1105a00f1d
@ -1,5 +1,6 @@
|
|||||||
const path = require("path")
|
const path = require("path")
|
||||||
const net = require("corenode/net")
|
const net = require("corenode/net")
|
||||||
|
|
||||||
const packageJSON = require(path.resolve(module.path, "../../package.json"))
|
const packageJSON = require(path.resolve(module.path, "../../package.json"))
|
||||||
const moduleAlias = require("module-alias")
|
const moduleAlias = require("module-alias")
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ global.DEFAULT_MIDDLEWARES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
if (process.env.LOG_REQUESTS === "true") {
|
if (process.env.LOG_REQUESTS === "true") {
|
||||||
global.DEFAULT_MIDDLEWARES.push(require("morgan")(process.env.NODE_ENV === "development" ? "dev" : "combined"))
|
global.DEFAULT_MIDDLEWARES.push(require("morgan")(process.env.MORGAN_FORMAT ?? ":method :url :status - :response-time ms"))
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerBaseAliases(fromPath, customAliases = {}) {
|
function registerBaseAliases(fromPath, customAliases = {}) {
|
||||||
|
@ -8,7 +8,6 @@ const pkgjson = require(path.resolve(process.cwd(), "package.json"))
|
|||||||
|
|
||||||
const tokenizer = require("corenode/libs/tokenizer")
|
const tokenizer = require("corenode/libs/tokenizer")
|
||||||
const { serverManifest, outputServerError, internalConsole } = require("./lib")
|
const { serverManifest, outputServerError, internalConsole } = require("./lib")
|
||||||
const InternalConsole = global.InternalInternalConsole = internalConsole
|
|
||||||
|
|
||||||
const HTTPProtocolsInstances = {
|
const HTTPProtocolsInstances = {
|
||||||
http: http,
|
http: http,
|
||||||
@ -33,8 +32,10 @@ class Server {
|
|||||||
constructor(params = {}, controllers = {}, middlewares = {}, headers = {}) {
|
constructor(params = {}, controllers = {}, middlewares = {}, headers = {}) {
|
||||||
// register aliases
|
// register aliases
|
||||||
this.params = {
|
this.params = {
|
||||||
|
minimal: false,
|
||||||
|
no_brand: false,
|
||||||
...global.DEFAULT_SERVER_PARAMS,
|
...global.DEFAULT_SERVER_PARAMS,
|
||||||
...params
|
...params,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.controllers = {
|
this.controllers = {
|
||||||
@ -51,6 +52,7 @@ class Server {
|
|||||||
this.endpoints_map = {}
|
this.endpoints_map = {}
|
||||||
|
|
||||||
// fix and fulfill params
|
// fix and fulfill params
|
||||||
|
this.params.listen_ip = this.params.listen_ip ?? "0.0.0.0"
|
||||||
this.params.listen_port = this.params.listen_port ?? 3000
|
this.params.listen_port = this.params.listen_port ?? 3000
|
||||||
this.params.http_protocol = this.params.http_protocol ?? "http"
|
this.params.http_protocol = this.params.http_protocol ?? "http"
|
||||||
this.params.ws_protocol = this.params.ws_protocol ?? "ws"
|
this.params.ws_protocol = this.params.ws_protocol ?? "ws"
|
||||||
@ -76,6 +78,10 @@ class Server {
|
|||||||
eventsChannels: [],
|
eventsChannels: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.internalConsole = global.InternalConsole = new internalConsole({
|
||||||
|
server_name: this.params.name
|
||||||
|
})
|
||||||
|
|
||||||
this.initializeManifest()
|
this.initializeManifest()
|
||||||
|
|
||||||
// handle silent mode
|
// handle silent mode
|
||||||
@ -124,8 +130,15 @@ class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initialize = async () => {
|
initialize = async () => {
|
||||||
InternalConsole.log(linebridge_ascii)
|
if (!this.params.no_brand) {
|
||||||
InternalConsole.info(`🚀 Starting server...`)
|
if (!this.params.minimal) {
|
||||||
|
InternalConsole.log(linebridge_ascii)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.params.minimal) {
|
||||||
|
InternalConsole.info(`🚀 Starting server...`)
|
||||||
|
}
|
||||||
|
|
||||||
//* set server defined headers
|
//* set server defined headers
|
||||||
this.initializeHeaders()
|
this.initializeHeaders()
|
||||||
@ -144,8 +157,11 @@ class Server {
|
|||||||
|
|
||||||
// initialize http server
|
// initialize http server
|
||||||
await this.http_instance.listen(this.params.listen_port, this.params.listen_ip ?? "0.0.0.0", () => {
|
await this.http_instance.listen(this.params.listen_port, this.params.listen_ip ?? "0.0.0.0", () => {
|
||||||
// output server info
|
InternalConsole.info(`✅ Server ready on => ${this.params.listen_ip}:${this.params.listen_port}`)
|
||||||
this.outputServerInfo()
|
|
||||||
|
if (!this.params.minimal) {
|
||||||
|
this.outputServerInfo()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,8 +408,6 @@ class Server {
|
|||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
outputServerInfo = () => {
|
outputServerInfo = () => {
|
||||||
InternalConsole.log("✅ Ready !")
|
|
||||||
|
|
||||||
InternalConsole.table({
|
InternalConsole.table({
|
||||||
"linebridge_version": LINEBRIDGE_SERVER_VERSION,
|
"linebridge_version": LINEBRIDGE_SERVER_VERSION,
|
||||||
"engine": this.params.engine,
|
"engine": this.params.engine,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user