Add an assertion when updating conversations; update cleanData
This commit is contained in:
parent
73a304faba
commit
bc37b5c907
23 changed files with 749 additions and 79 deletions
33
ts/logging/log.ts
Normal file
33
ts/logging/log.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { noop } from 'lodash';
|
||||
import { LogLevel } from './shared';
|
||||
|
||||
type LogAtLevelFnType = (
|
||||
level: LogLevel,
|
||||
...args: ReadonlyArray<unknown>
|
||||
) => void;
|
||||
|
||||
let logAtLevel: LogAtLevelFnType = noop;
|
||||
let hasInitialized = false;
|
||||
|
||||
type LogFn = (...args: ReadonlyArray<unknown>) => void;
|
||||
export const fatal: LogFn = (...args) => logAtLevel(LogLevel.Fatal, ...args);
|
||||
export const error: LogFn = (...args) => logAtLevel(LogLevel.Error, ...args);
|
||||
export const warn: LogFn = (...args) => logAtLevel(LogLevel.Warn, ...args);
|
||||
export const info: LogFn = (...args) => logAtLevel(LogLevel.Info, ...args);
|
||||
export const debug: LogFn = (...args) => logAtLevel(LogLevel.Debug, ...args);
|
||||
export const trace: LogFn = (...args) => logAtLevel(LogLevel.Trace, ...args);
|
||||
|
||||
/**
|
||||
* Sets the low-level logging interface. Should be called early in a process's life, and
|
||||
* can only be called once.
|
||||
*/
|
||||
export function setLogAtLevel(log: LogAtLevelFnType): void {
|
||||
if (hasInitialized) {
|
||||
throw new Error('Logger has already been initialized');
|
||||
}
|
||||
logAtLevel = log;
|
||||
hasInitialized = true;
|
||||
}
|
|
@ -19,6 +19,7 @@ import {
|
|||
getLogLevelString,
|
||||
isLogEntry,
|
||||
} from './shared';
|
||||
import * as log from './log';
|
||||
import { reallyJsonStringify } from '../util/reallyJsonStringify';
|
||||
|
||||
// To make it easier to visually scan logs, we make all levels the same length
|
||||
|
@ -33,13 +34,13 @@ function now() {
|
|||
return date.toJSON();
|
||||
}
|
||||
|
||||
function log(...args: ReadonlyArray<unknown>) {
|
||||
function consoleLog(...args: ReadonlyArray<unknown>) {
|
||||
logAtLevel(LogLevel.Info, ...args);
|
||||
}
|
||||
|
||||
if (window.console) {
|
||||
console._log = console.log;
|
||||
console.log = log;
|
||||
console.log = consoleLog;
|
||||
}
|
||||
|
||||
// The mechanics of preparing a log for publish
|
||||
|
@ -126,13 +127,15 @@ function logAtLevel(level: LogLevel, ...args: ReadonlyArray<unknown>): void {
|
|||
});
|
||||
}
|
||||
|
||||
log.setLogAtLevel(logAtLevel);
|
||||
|
||||
window.log = {
|
||||
fatal: _.partial(logAtLevel, LogLevel.Fatal),
|
||||
error: _.partial(logAtLevel, LogLevel.Error),
|
||||
warn: _.partial(logAtLevel, LogLevel.Warn),
|
||||
info: _.partial(logAtLevel, LogLevel.Info),
|
||||
debug: _.partial(logAtLevel, LogLevel.Debug),
|
||||
trace: _.partial(logAtLevel, LogLevel.Trace),
|
||||
fatal: log.fatal,
|
||||
error: log.error,
|
||||
warn: log.warn,
|
||||
info: log.info,
|
||||
debug: log.debug,
|
||||
trace: log.trace,
|
||||
fetch,
|
||||
publish,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue