logger.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * Adapted from LiteMol
  5. * Copyright (c) 2016 - now David Sehnal, licensed under Apache 2.0, See LICENSE file for more info.
  6. */
  7. import { LogEvent } from '../event/basic'
  8. import { Context } from '../context/context'
  9. export class Logger {
  10. private log(e: Logger.Entry) {
  11. LogEvent.dispatch(this.context, e);
  12. }
  13. message(m: string) {
  14. this.log({ type: Logger.EntryType.Message, timestamp: new Date(), message: m });
  15. }
  16. error(m: string) {
  17. this.log({ type: Logger.EntryType.Error, timestamp: new Date(), message: m });
  18. }
  19. warning(m: string) {
  20. this.log({ type: Logger.EntryType.Warning, timestamp: new Date(), message: m });
  21. }
  22. info(m: string) {
  23. this.log({ type: Logger.EntryType.Info, timestamp: new Date(), message: m });
  24. }
  25. constructor(private context: Context) {
  26. }
  27. }
  28. export namespace Logger {
  29. export enum EntryType {
  30. Message,
  31. Error,
  32. Warning,
  33. Info
  34. }
  35. export interface Entry {
  36. type: EntryType;
  37. timestamp: Date;
  38. message: any
  39. }
  40. }