npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@siteed/react-native-logger

v0.7.1

Published

Simple logger to wrap console and keep track of latest logs

Downloads

291

Readme

react-native-logger

react-native-logger is a simple, yet powerful logging library designed for React Native applications. It extends the basic console logging functions by maintaining a log history that can be displayed within your app or exported for troubleshooting. This feature is particularly useful in production environments where direct console access is not possible.

Demo

Installation

npm install @siteed/react-native-logger

Key Features

  • Easy Integration: Seamlessly integrates with any React Native project.
  • Persistent Log History: Keeps a history of log messages that can be displayed in-app for easier debugging and diagnostics.
  • Flexible Logging Levels: Supports multiple logging levels (debug, info, warn, error) to categorize log output.
  • Production Debugging: Facilitates debugging in production by allowing logs to be reviewed directly from a device.

Usage

To get started with react-native-logger, wrap your application's root component with LoggerProvider. You can then use useLogger within your React components or getLogger outside of them to log messages.

Basic Setup

import { LoggerProvider, useLogger, getLogger } from '@siteed/react-native-logger'

// To use outside react component, you can call getLogger directly
const outLogger = getLogger(`out`);
outLogger.debug(`This is a debug message`);
outLogger.info(`This is an info message`);
outLogger.warn(`This is a warning message`);
outLogger.error(`This is an error message`);

const App = () => {
  const { logger } = useLogger('App')
  useEffect( () => {
    logger.log(`App mounted`)
  })

  return (
    <View>
      <Text>App</Text>
    </View>
  )
}

const WithLogger = () => {
  return (
    <LoggerProvider>
      <App />
    </LoggerProvider>
  )
}
export default WithLogger

Accessing logs in Production

react-native-logger is particularly useful in production, where traditional debugging tools are not accessible. For instance, you can create a dedicated screen within your app that displays log history, allowing users to copy and send these logs for support purposes, or even set up automatic log forwarding via email or a web service.

import { LoggerProvider, useLoggerState } from '@siteed/react-native-logger';

const LogScreen = () => {
  const { logs } = useLoggerState();

  const handleSendLogs = async () => {
    const logData = logs.map(log => `${log.timestamp}: ${log.message}`).join('\n');
    await sendLogsToSupport(logData); // Define this function to match your backend support system
  };

  return (
    <View>
      <Text>Log Details</Text>
      <Button title="Send Logs to Support" onPress={handleSendLogs} />
    </View>
  );
};

const App = () => (
  <LoggerProvider>
    <LogScreen />
  </LoggerProvider>
);

export default App;

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Try it out

yarn example web

License

MIT


Made with create-react-native-library