/** * REACT-NATIVE-LOGS * Alessandro Bottamedi - a.bottamedi@me.com * * Performance-aware simple logger for React-Native with custom levels and transports (colored console, file writing, etc.) * * MIT license * * Copyright (c) 2021 Alessandro Bottamedi. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** Import preset transports */ import { consoleTransport, ConsoleTransportOptions } from "./transports/consoleTransport"; import { mapConsoleTransport, MapConsoleTransportOptions } from "./transports/mapConsoleTransport"; import { fileAsyncTransport, FileAsyncTransportOptions } from "./transports/fileAsyncTransport"; import { sentryTransport } from "./transports/sentryTransport"; import { crashlyticsTransport, CrashlyticsTransportOption } from "./transports/crashlyticsTransport"; /** Types Declaration */ type transportFunctionType = (props: { msg: string; rawMsg: unknown; level: { severity: number; text: string; }; extension?: string | null; options?: T; }) => void; type ExtractOptions = T extends transportFunctionType ? U : never; type MergeTransportOptions = T extends (infer U)[] ? ExtractOptions : ExtractOptions; type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I extends U) => void ? I : never; type configLoggerType | transportFunctionType[], Level extends string> = { severity?: string; transport?: T; transportOptions?: UnionToIntersection>; levels?: Record; async?: boolean; asyncFunc?: Function; stringifyFunc?: (msg: any) => string; formatFunc?: null | ((level: string, extension: string | null, msgs: any) => string); dateFormat?: string | ((date: Date) => string); printLevel?: boolean; printDate?: boolean; fixedExtLvlLength?: boolean; enabled?: boolean; enabledExtensions?: string[] | string | null; }; type defLvlType = "debug" | "info" | "warn" | "error"; type levelMethods = { [key in levels]: (...args: unknown[]) => void; }; type LoggerInstance = levelMethods & { extend: (extension: string) => LoggerInstance; enable: (extension?: string) => boolean; disable: (extension?: string) => boolean; getExtensions: () => string[]; setSeverity: (level: string) => string; getSeverity: () => string; patchConsole: () => void; }; declare const logger: { createLogger: | transportFunctionType[] = transportFunctionType<{ _def: string; }>, Y extends string = "error" | "warn" | "info" | "debug">(config?: configLoggerType) => LoggerInstance; }; export { logger, consoleTransport, mapConsoleTransport, fileAsyncTransport, sentryTransport, crashlyticsTransport, }; export type { transportFunctionType, configLoggerType, defLvlType, LoggerInstance, ConsoleTransportOptions, MapConsoleTransportOptions, FileAsyncTransportOptions, CrashlyticsTransportOption, };