Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/logtown/logtown
🦄 Simple Logging Facade for JavaScript
https://github.com/logtown/logtown
javascript logging logging-facade logtown
Last synced: 3 days ago
JSON representation
🦄 Simple Logging Facade for JavaScript
- Host: GitHub
- URL: https://github.com/logtown/logtown
- Owner: logtown
- License: apache-2.0
- Created: 2016-11-04T19:02:32.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2025-01-05T10:26:46.000Z (29 days ago)
- Last Synced: 2025-01-21T23:08:37.398Z (12 days ago)
- Topics: javascript, logging, logging-facade, logtown
- Language: TypeScript
- Homepage:
- Size: 629 KB
- Stars: 32
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-node-esm - logtown - simple Logging Facade for JavaScript. (Packages / Logging)
README
# Logtown
[![npm](https://img.shields.io/npm/v/logtown?color=0000ff&label=npm&labelColor=000)](https://npmjs.com/package/logtown)
Lightweight logging wrapper with only one dependency. Logtown is not a logger and does not depend on any loggers.
The reasoning behind this package is to provide a simple and easy-to-use logging interface that can be used with any logger within any environment.
Nowadays, application can be run in many different environments, such as Cloudflare Workers, Deno, AWS Lambda, Node.js, Bun.js, Browsers and many others. Each of these environments has its own logging capabilities and requirements. **Logtown** is designed to be a single logging interface that can be used in any of these environments.
For example, for local development you can enable console logging that would include colors, while in production you would use a logger that sends logs to a remote server, such as AWS CloudWatch, and/or you can configure it to send logs in a specific format, like JSON.
## Log levels
Logtown supports the following log levels:
- `verbose`
- `debug`
- `info`
- `warn`
- `error`No other log levels are supported and never will be. The decision to keep the number of log levels to a minimum and never change them, so that the code that uses Logtown will be more predictable and easier to maintain.
## Installation
```bash
npm install logtown
yarn add logtown
pnpm add logtown
bun add logtown
```## Usage
```typescript
import { createLogger, registerWrapper, ConsoleWrapper } from "logtown";const logger = new createLogger("my-logger");
logger.info("Hello World");
// ^ nothing happens, because no wrappers were addedregisterWrapper(ConsoleWrapper);
logger.info("Hello World");
// ^ prints "Hello World" to the console
```## Wrappers
Wrappers are the actual loggers that will be used to log messages. You should create your own wrapper. The wrapper can be either a function or an object that has a `log` method(that would be called for all log levels) or any of log level methods.
```typescript
import { createLogger, registerWrapper, type LoggerPayload } from "logtown";// the following wrapper will log all messages to the console
registerWrapper({
log: ({ level, message }: LoggerPayload) => {
console.log(`[${level}] ${message}`);
},
});
``````typescript
import { createLogger, registerWrapper, type LoggerPayload } from "logtown";
import debug from "debug";if (process.env.NODE_ENV === "development") {
// the following wrapper will log debug messages only to the debug logger
registerWrapper({
debug: ({ level, timestamp, id, message, ...rest }: LoggerPayload) => {
const debugLog = debug(id);
debugLog(message, ...rest);
},
});
}
```## License
`logtown` released under the Apache 2.0 license
## Donate
[![](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/red_rabbit)
[![](https://img.shields.io/static/v1?label=UNITED24&message=support%20Ukraine&color=blue)](https://u24.gov.ua/)