tokens.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { nbformat } from '@jupyterlab/coreutils';
  4. import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
  5. import { IOutputAreaModel } from '@jupyterlab/outputarea';
  6. import { Token } from '@phosphor/coreutils';
  7. import { ISignal } from '@phosphor/signaling';
  8. /* tslint:disable */
  9. /**
  10. * The Logger Registry token.
  11. */
  12. export const ILoggerRegistry = new Token<ILoggerRegistry>(
  13. '@jupyterlab/logconsole:ILoggerRegistry'
  14. );
  15. export type ILoggerRegistryChange = 'append';
  16. /**
  17. * A Logger Registry that registers and provides loggers by source.
  18. */
  19. export interface ILoggerRegistry {
  20. /**
  21. * Get the logger for the specified source.
  22. *
  23. * @param source - The name of the log source.
  24. *
  25. * @returns The logger for the specified source.
  26. */
  27. getLogger(source: string): ILogger;
  28. /**
  29. * Get all loggers registered.
  30. *
  31. * @returns The array containing all registered loggers.
  32. */
  33. getLoggers(): ILogger[];
  34. /**
  35. * A signal emitted when the logger registry changes.
  36. */
  37. readonly registryChanged: ISignal<this, ILoggerRegistryChange>;
  38. }
  39. /**
  40. * Log severity level
  41. */
  42. export type LogLevel = 'critical' | 'error' | 'warning' | 'info' | 'debug';
  43. /**
  44. * The base log payload type.
  45. */
  46. export interface ILogPayloadBase {
  47. /**
  48. * Type of log data.
  49. */
  50. type: string;
  51. /**
  52. * Log level
  53. */
  54. level: LogLevel;
  55. /**
  56. * Data
  57. */
  58. data: any;
  59. }
  60. /**
  61. * Plain text log payload.
  62. */
  63. export interface ITextLog extends ILogPayloadBase {
  64. /**
  65. * Type of log data.
  66. */
  67. type: 'text';
  68. /**
  69. * Log data as plain text.
  70. */
  71. data: string;
  72. }
  73. /**
  74. * HTML log payload.
  75. */
  76. export interface IHtmlLog extends ILogPayloadBase {
  77. /**
  78. * Type of log data.
  79. */
  80. type: 'html';
  81. /**
  82. * Log data as HTML string.
  83. */
  84. data: string;
  85. }
  86. /**
  87. * Notebook kernel output log payload.
  88. */
  89. export interface IOutputLog extends ILogPayloadBase {
  90. /**
  91. * Type of log data.
  92. */
  93. type: 'output';
  94. /**
  95. * Log data as Notebook kernel output.
  96. */
  97. data: nbformat.IOutput;
  98. }
  99. /**
  100. * Log payload union type.
  101. */
  102. export type ILogPayload = ITextLog | IHtmlLog | IOutputLog;
  103. export type ILoggerChange = 'append' | 'clear';
  104. export interface ILoggerOutputAreaModel extends IOutputAreaModel {
  105. /**
  106. * The maximum number of outputs to store.
  107. */
  108. maxLength: number;
  109. }
  110. /**
  111. * A Logger that manages logs from a particular source.
  112. */
  113. export interface ILogger {
  114. /**
  115. * Number of outputs logged.
  116. */
  117. readonly length: number;
  118. /**
  119. * Max number of messages.
  120. */
  121. maxLength: number;
  122. /**
  123. * Log level.
  124. */
  125. level: LogLevel;
  126. /**
  127. * Rendermime to use when rendering outputs logged.
  128. */
  129. rendermime: IRenderMimeRegistry;
  130. /**
  131. * A signal emitted when the log model changes.
  132. */
  133. readonly logChanged: ISignal<this, ILoggerChange>;
  134. /**
  135. * A signal emitted when the rendermime changes.
  136. */
  137. readonly rendermimeChanged: ISignal<this, void>;
  138. /**
  139. * The name of the log source.
  140. */
  141. readonly source: string;
  142. /**
  143. * Output Area Model used to manage log storage in memory.
  144. */
  145. readonly outputAreaModel: ILoggerOutputAreaModel;
  146. /**
  147. * The cumulative number of messages the log has stored.
  148. */
  149. readonly version: number;
  150. /**
  151. * Log an output to logger.
  152. *
  153. * @param log - The output to be logged.
  154. */
  155. log(log: ILogPayload): void;
  156. /**
  157. * Clear all outputs logged.
  158. */
  159. clear(): void;
  160. }