Nessuna descrizione

log.js 751B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. export default class Log {
  2. _name:string;
  3. _isEnable:boolean = true
  4. _level:number = 0
  5. constructor(name:string) {
  6. this._name = name
  7. }
  8. level(val:number) {
  9. this._isEnable = true
  10. this._level = val
  11. }
  12. enable() {
  13. this._isEnable = true
  14. }
  15. disable() {
  16. this._isEnable = false
  17. }
  18. verbose(...args) {
  19. this._isEnable && this._level > 2 && console.log(this._name, 'verbose:', ...args)
  20. }
  21. debug(...args) {
  22. this._isEnable && this._level > 1 && console.log(this._name, 'debug:', ...args)
  23. }
  24. info(...args) {
  25. this._isEnable && this._level > 0 && console.log(this._name, 'info:', ...args)
  26. }
  27. error(...args) {
  28. this._isEnable && this._level > -1 && console.warn(this._name, 'error:', ...args)
  29. }
  30. }