How to Use Zoya: A Highly Composable Logging Utility in TypeScript

Nov 27, 2022 | Programming

In the realm of programming, logging is essential. It’s like your application’s diary, capturing events for later analysis. Zoya is a fantastic logging library built specifically with TypeScript, designed to be both highly composable and user-friendly. This blog will guide you through the steps to install, configure, and use Zoya effectively.

What’s in Store?

Description

Zoya is a highly composable logging library used for both client and server applications. It’s a complete rewrite of Signale, crafted by Klaus Siani, and is tailored to accommodate a broader range of logging needs without being a direct replacement.

Highlights

  • Easy to set up and compose
  • Control over appearance and formatting
  • Extensible with built-in fields
  • JSON output support
  • Multiple writable streams with filtering
  • Minimally verbose syntax

Install

To get Zoya up and running, install it via Yarn or NPM:

Using Yarn

bash
yarn add zoya

Using NPM

bash
npm install zoya

Usage

Imagine logging as crafting a tasty dish. Each ingredient represents a log field that can mix and match. With Zoya, you’re the chef!

Here’s how you can utilize Zoya:

typescript
import zoya from 'zoya';
zoya.info('Hello world!');

The default logger from Zoya writes to process.stdout and supports various logging levels:

typescript
import log from 'zoya';
log.trace('trace messages...');
log.debug('debug messages...');
log.info('info messages...');
log.success('success messages...');
log.warn('warn messages...');
log.error('error messages...');
log.failed('failed messages...');
log.fatal('fatal messages...');

Think of these log levels like the weather forecast: from sunny info to stormy errors; they all convey essential data.

Configuration

Zoya allows extensive customization to tailor the logging experience:

typescript
import zoya, { Level } from 'zoya';

const jsonLogger = zoya({ json: true });
const stderrLogger = zoya({
  streams: [
    {
      level: Level.error,
      stream: process.stderr
    }
  ]
});

Now, you can log in a way that works best for your application needs!

Development

Want to contribute? It’s as easy as forking the repository, cloning it to your machine, navigating to your local copy, and running:

bash
npm install
npm test

FAQ

Why Zoya?

Because it’s flexible, user-friendly, and meets a wide range of logging needs. As succinctly expressed by its creator, it draws inspiration from projects like Trine.

Acknowledgements

Special thanks to the contributors on the TypeScript Discord channel who provided invaluable insights!

License

Zoya is available under the MIT License.

Troubleshooting

If you encounter issues while using Zoya, consider checking the installation steps, reviewing logger configurations, or ensuring that the necessary dependencies are installed. Also, explore the examples folder for further guidance.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox