Advertisement
borlabs

Specific type for _logs

Sep 10th, 2020 (edited)
3,624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type LogLevel =
  2.   | "emergency"
  3.   | "alert"
  4.   | "critical"
  5.   | "error"
  6.   | "warning"
  7.   | "notice"
  8.   | "info"
  9.   | "debug";
  10.  
  11. type LogList = {
  12.   [key in LogLevel]: Array<string>;
  13. };
  14.  
  15. export class Log {
  16.   _logs: LogList = {
  17.     emergency: [],
  18.     alert: [],
  19.     critical: [],
  20.     error: [],
  21.     warning: [],
  22.     notice: [],
  23.     info: [],
  24.     debug: [],
  25.   };
  26.  
  27.   constructor() {}
  28.  
  29.   add(level: LogLevel, message: string): void {
  30.     this._logs[level].push(message);
  31.   }
  32.  
  33.   emergency(message: string): void {
  34.     this.add("emergency", message);
  35.   }
  36.  
  37.   alert(message: string): void {
  38.     this.add("alert", message);
  39.   }
  40.  
  41.   critical(message: string): void {
  42.     this.add("critical", message);
  43.   }
  44.  
  45.   error(message: string): void {
  46.     this.add("error", message);
  47.   }
  48.  
  49.   warning(message: string): void {
  50.     this.add("warning", message);
  51.   }
  52.  
  53.   notice(message: string): void {
  54.     this.add("notice", message);
  55.   }
  56.  
  57.   info(message: string): void {
  58.     this.add("notice", message);
  59.   }
  60.  
  61.   debug(message: string): void {
  62.     this.add("debug", message);
  63.   }
  64.  
  65.   get logs(): LogList {
  66.     return this._logs;
  67.   }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement