Add an assertion when updating conversations; update cleanData

This commit is contained in:
Evan Hahn 2021-02-04 13:54:03 -06:00 committed by GitHub
parent 73a304faba
commit bc37b5c907
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 749 additions and 79 deletions

33
ts/logging/log.ts Normal file
View 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;
}