@foxford/logger 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. package/browser.js +297 -411
  2. package/browser.mjs +295 -399
  3. package/index.d.ts +170 -11
  4. package/node.js +262 -385
  5. package/node.mjs +260 -372
  6. package/package.json +5 -4
package/index.d.ts CHANGED
@@ -1,9 +1,161 @@
1
- // Generated by dts-bundle-generator v8.0.1
2
-
3
- import { Logger as LoglevelLogger, RootLogger } from 'loglevel';
4
-
5
- export type Id = `${string}-${string}-${string}-${string}-${string}`;
6
- export interface HierarchicalLogger extends LoglevelLogger {
1
+ interface LogLevel {
2
+ TRACE: 0;
3
+ DEBUG: 1;
4
+ INFO: 2;
5
+ WARN: 3;
6
+ ERROR: 4;
7
+ SILENT: 5;
8
+ }
9
+ type LogLevelNumbers = LogLevel[keyof LogLevel];
10
+ type LogLevelDesc = LogLevelNumbers | LogLevelNames | "silent" | keyof LogLevel;
11
+ type LogLevelNames = "trace" | "debug" | "info" | "warn" | "error";
12
+ type LoggingMethod = (...message: any[]) => void;
13
+ type MethodFactory = (methodName: LogLevelNames, level: LogLevelNumbers, loggerName: string | symbol) => LoggingMethod;
14
+ interface RootLogger extends Logger {
15
+ /**
16
+ * If you're using another JavaScript library that exposes a 'log' global, you can run into conflicts with loglevel.
17
+ * Similarly to jQuery, you can solve this by putting loglevel into no-conflict mode immediately after it is loaded
18
+ * onto the page. This resets to 'log' global to its value before loglevel was loaded (typically undefined), and
19
+ * returns the loglevel object, which you can then bind to another name yourself.
20
+ */
21
+ noConflict(): any;
22
+ /**
23
+ * This gets you a new logger object that works exactly like the root log object, but can have its level and
24
+ * logging methods set independently. All loggers must have a name (which is a non-empty string or a symbol)
25
+ * Calling * getLogger() multiple times with the same name will return an identical logger object.
26
+ * In large applications, it can be incredibly useful to turn logging on and off for particular modules as you are
27
+ * working with them. Using the getLogger() method lets you create a separate logger for each part of your
28
+ * application with its own logging level. Likewise, for small, independent modules, using a named logger instead
29
+ * of the default root logger allows developers using your module to selectively turn on deep, trace-level logging
30
+ * when trying to debug problems, while logging only errors or silencing logging altogether under normal
31
+ * circumstances.
32
+ * @param name The name of the produced logger
33
+ */
34
+ getLogger(name: string | symbol): Logger;
35
+ /**
36
+ * This will return you the dictionary of all loggers created with getLogger, keyed off of their names.
37
+ */
38
+ getLoggers(): {
39
+ [name: string]: Logger;
40
+ };
41
+ /**
42
+ * A .default property for ES6 default import compatibility
43
+ */
44
+ default: RootLogger;
45
+ }
46
+ interface Logger {
47
+ /**
48
+ * Available log levels.
49
+ */
50
+ readonly levels: LogLevel;
51
+ /**
52
+ * Plugin API entry point. This will be called for each enabled method each time the level is set
53
+ * (including initially), and should return a MethodFactory to be used for the given log method, at the given level,
54
+ * for a logger with the given name. If you'd like to retain all the reliability and features of loglevel, it's
55
+ * recommended that this wraps the initially provided value of log.methodFactory
56
+ */
57
+ methodFactory: MethodFactory;
58
+ /**
59
+ * Output trace message to console.
60
+ * This will also include a full stack trace
61
+ *
62
+ * @param msg any data to log to the console
63
+ */
64
+ trace(...msg: any[]): void;
65
+ /**
66
+ * Output debug message to console including appropriate icons
67
+ *
68
+ * @param msg any data to log to the console
69
+ */
70
+ debug(...msg: any[]): void;
71
+ /**
72
+ * Output debug message to console including appropriate icons
73
+ *
74
+ * @param msg any data to log to the console
75
+ */
76
+ log(...msg: any[]): void;
77
+ /**
78
+ * Output info message to console including appropriate icons
79
+ *
80
+ * @param msg any data to log to the console
81
+ */
82
+ info(...msg: any[]): void;
83
+ /**
84
+ * Output warn message to console including appropriate icons
85
+ *
86
+ * @param msg any data to log to the console
87
+ */
88
+ warn(...msg: any[]): void;
89
+ /**
90
+ * Output error message to console including appropriate icons
91
+ *
92
+ * @param msg any data to log to the console
93
+ */
94
+ error(...msg: any[]): void;
95
+ /**
96
+ * This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something")
97
+ * or log.error("something") will output messages, but log.info("something") will not.
98
+ *
99
+ * @param level as a string, like 'error' (case-insensitive) or as a number from 0 to 5 (or as log.levels. values)
100
+ * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling
101
+ * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass
102
+ * false as the optional 'persist' second argument, persistence will be skipped.
103
+ */
104
+ setLevel(level: LogLevelDesc, persist?: boolean): void;
105
+ /**
106
+ * Returns the current logging level, as a value from LogLevel.
107
+ * It's very unlikely you'll need to use this for normal application logging; it's provided partly to help plugin
108
+ * development, and partly to let you optimize logging code as below, where debug data is only generated if the
109
+ * level is set such that it'll actually be logged. This probably doesn't affect you, unless you've run profiling
110
+ * on your code and you have hard numbers telling you that your log data generation is a real performance problem.
111
+ */
112
+ getLevel(): LogLevel[keyof LogLevel];
113
+ /**
114
+ * This sets the current log level only if one has not been persisted and can’t be loaded. This is useful when
115
+ * initializing scripts; if a developer or user has previously called setLevel(), this won’t alter their settings.
116
+ * For example, your application might set the log level to error in a production environment, but when debugging
117
+ * an issue, you might call setLevel("trace") on the console to see all the logs. If that error setting was set
118
+ * using setDefaultLevel(), it will still say as trace on subsequent page loads and refreshes instead of resetting
119
+ * to error.
120
+ *
121
+ * The level argument takes is the same values that you might pass to setLevel(). Levels set using
122
+ * setDefaultLevel() never persist to subsequent page loads.
123
+ *
124
+ * @param level as a string, like 'error' (case-insensitive) or as a number from 0 to 5 (or as log.levels. values)
125
+ */
126
+ setDefaultLevel(level: LogLevelDesc): void;
127
+ /**
128
+ * This resets the current log level to the default level (or `warn` if no explicit default was set) and clears
129
+ * the persisted level if one was previously persisted.
130
+ */
131
+ resetLevel(): void;
132
+ /**
133
+ * This enables all log messages, and is equivalent to log.setLevel("trace").
134
+ *
135
+ * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling
136
+ * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass
137
+ * false as the optional 'persist' second argument, persistence will be skipped.
138
+ */
139
+ enableAll(persist?: boolean): void;
140
+ /**
141
+ * This disables all log messages, and is equivalent to log.setLevel("silent").
142
+ *
143
+ * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling
144
+ * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass
145
+ * false as the optional 'persist' second argument, persistence will be skipped.
146
+ */
147
+ disableAll(persist?: boolean): void;
148
+ /**
149
+ * Rebuild the logging methods on this logger and its child loggers.
150
+ *
151
+ * This is mostly intended for plugin developers, but can be useful if you update a logger's `methodFactory` or
152
+ * if you want to apply the root logger’s level to any *pre-existing* child loggers (this updates the level on
153
+ * any child logger that hasn't used `setLevel()` or `setDefaultLevel()`).
154
+ */
155
+ rebuild(): void;
156
+ }
157
+ type Id = `${string}-${string}-${string}-${string}-${string}`;
158
+ export interface HierarchicalLogger extends Logger {
7
159
  id: Id;
8
160
  parent: HierarchicalLogger | null;
9
161
  debugEnabled: boolean;
@@ -15,25 +167,32 @@ export interface HierarchicalLogger extends LoglevelLogger {
15
167
  isDebugEnabled(): boolean;
16
168
  getDebugPattern(): string | null;
17
169
  }
170
+ declare global {
171
+ interface Window {
172
+ loggerCache: Map<Id, HierarchicalLogger>;
173
+ previousLevels: Map<Id, LogLevelDesc>;
174
+ }
175
+ }
18
176
  /**
19
177
  * Плагин иерархического логгера для loglevel
20
178
  */
21
179
  export declare const hierarchicalPlugin: {
22
180
  apply(rootLogger: RootLogger): void;
23
181
  };
24
- export type FormatFunction = (level: string, name: string, timestamp: Date) => string | string[];
25
- export interface PrefixOptions {
182
+ type FormatFunction = (level: string, name: string, timestamp: Date) => string | string[];
183
+ interface PrefixOptions {
26
184
  format: FormatFunction;
27
185
  }
28
186
  export declare const prefixPlugin: {
29
- apply(rootLogger: LoglevelLogger, options?: Partial<PrefixOptions>): void;
187
+ apply(rootLogger: Logger, options?: Partial<PrefixOptions>): void;
30
188
  };
31
- export interface Logger extends RootLogger {
189
+ interface Logger$1 extends RootLogger {
32
190
  getLogger(name: string): HierarchicalLogger;
33
191
  }
34
- declare const extendedLog: Logger;
192
+ declare const extendedLog: Logger$1;
35
193
 
36
194
  export {
195
+ Logger$1 as Logger,
37
196
  extendedLog as log,
38
197
  };
39
198