소스 검색

new logging

hmt 3 년 전
부모
커밋
e74bdf3afe
3개의 변경된 파일10개의 추가작업 그리고 8개의 파일을 삭제
  1. 8 4
      app.ts
  2. 2 3
      mod.ts
  3. 0 1
      servers.ts

+ 8 - 4
app.ts

@@ -17,7 +17,7 @@ router.use((req, res, next)=> {
 router.use("/:call", (req, res, next) => {
   const handler = new BBB(req)
   const authenticated = handler.authenticated(secret)
-  console.log(`${date()} New call to ${Color.green(handler.call)} ${authenticated ? '':Color.red('Rejected')}`)
+  res.locals.log = [`${date()} ${Color.green(handler.call)}${authenticated ? '':Color.red(' Rejected')}`]
   if (authenticated) { 
     res.locals.handler = handler
     next()
@@ -42,12 +42,15 @@ router.all("/:call", async (req, res, next) => {
   let server: server
   try {
     server = await handler.find_meeting_id(S.servers)
+    res.locals.log.push(`found, ${handler.call==='join'?'redirect to':'reply with'} ${server.host}`)
   } catch (e) {
-    console.log(`Found no server with Meeting ID ${Color.yellow(handler.meeting_id)}`)
-    if (handler.call === 'create') { S.get_available_server() }
+    res.locals.log.push(`${Color.yellow("not found,")}`)
+    if (handler.call === 'create') {
+      S.get_available_server()
+      res.locals.log.push(`open new room on ${Color.green(S.current_server.host)}`);
+    }
     server = S.current_server
   }
-  console.log(`Redirecting to ${server.host}`)
   const redirect = handler.rewritten_query(server)
   if (handler.call === 'join') {
     res.redirect(redirect)
@@ -62,6 +65,7 @@ router.all("/:call", async (req, res, next) => {
       next(createError(500))
     }
   }
+  console.log(res.locals.log.join(' '));
 });
 // the fake answering machine to make sure we are recognized as a proper api
 router.get("/", (req, res, next) => {

+ 2 - 3
mod.ts

@@ -1,10 +1,9 @@
 import { Color, secret } from './deps.ts'
 
-const date = () => new Date().toLocaleTimeString('de')
-const VERSION = 'v1.6.1'
+const VERSION = 'v1.6.2'
 // give your tinyscale server a secret so it looks like a BBB server
 if (!secret) throw "No secret set for tinyscale"
-console.log(date() + Color.green(` Starting tinyscale ${VERSION}`))
+console.log(Color.green(`Starting tinyscale ${VERSION}`))
 console.log(`Your secret is set to ${Color.green(secret)}`)
 
 import app from "./app.ts";

+ 0 - 1
servers.ts

@@ -48,7 +48,6 @@ export class Servers {
       this.iterator = this.servers[Symbol.iterator]()
       candidate = this.iterator.next()
     }
-    console.log(`Using next server ${Color.green(candidate.value.host)}`)
     this.current_server = candidate.value;
     return this.current_server
   }