https://github.com/louisxie0830/pretty-log
A TypeScript library for enhancing and formatting log messages.
https://github.com/louisxie0830/pretty-log
console-log pretty typescript
Last synced: 5 months ago
JSON representation
A TypeScript library for enhancing and formatting log messages.
- Host: GitHub
- URL: https://github.com/louisxie0830/pretty-log
- Owner: louisxie0830
- License: mit
- Created: 2024-06-27T15:13:50.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-27T17:52:29.000Z (about 2 years ago)
- Last Synced: 2024-12-30T20:48:30.000Z (over 1 year ago)
- Topics: console-log, pretty, typescript
- Language: TypeScript
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pretty Log
A TypeScript library for enhancing and formatting log messages.
## Features
- Pretty-print log messages in different styles.
- Supports both CommonJS and ES modules.
- Written in TypeScript with type definitions included.
- Easy to use and integrate into any project.
## Installation
You can install directly from GitHub:
```bash
npm install git+https://github.com/louisxie0830/pretty-log.git
```
## Examples
Here are examples of how to import and use this library in different projects:
### CommonJS
```javascript
const prettyLog = require('pretty-log').default;
const logger = prettyLog({ enabled: true });
logger.info('Hello, World!');
logger.error('Hello, World!');
logger.warn('Hello, World!');
logger.success('Hello, World!');
```
### ES Modules
```javascript
import prettyLog from 'pretty-log';
const logger = prettyLog({ enabled: true });
logger.info('Hello, World!');
logger.error('Hello, World!');
logger.warn('Hello, World!');
logger.success('Hello, World!');
```
### TypeScript
```typescript
import prettyLog from 'pretty-log';
const logger = prettyLog({ enabled: true });
logger.info('Hello, World!');
logger.error('Hello, World!');
logger.warn('Hello, World!');
logger.success('Hello, World!');
```
## API
### `prettyLog(options)`
- **options**: An object with the following properties:
- **enabled**: `boolean` - Enable or disable logging.
#### Methods
- **info(message: string, content?: string)**: Logs an informational message.
- **error(message: string, content?: string)**: Logs an error message.
- **warn(message: string, content?: string)**: Logs a warning message.
- **success(message: string, content?: string)**: Logs a success message.
- **setEnabled(enabled: boolean)**: Enables or disables logging.
## Development
### Building the Project
To build the project, run:
```bash
npm run build
```
This will generate the CommonJS and ES module versions of the library in the `dist` directory.
### Running Tests
To run tests, use:
```bash
npm test
```
This will run the tests using Jest.
### Linting and Formatting
To lint the code, use:
```bash
npm run lint
```
To format the code, use:
```bash
npm run format
```
### Project Structure
- `src/`: Source code files.
- `tests/`: Test files.
- `dist/`: Compiled output files.
- `package.json`: Project metadata and dependencies.
- `tsconfig.json`: TypeScript configuration.
- `tsconfig.cjs.json`: TypeScript configuration for CommonJS modules.
- `tsconfig.esm.json`: TypeScript configuration for ES modules.
- `jest.config.js`: Jest configuration.
- `.eslintrc.json`: ESLint configuration.
- `.prettierrc`: Prettier configuration.
- `.prettierignore`: Files ignored by Prettier.
- `.eslintignore`: Files ignored by ESLint.
- `.gitignore`: Files ignored by Git.
## Contributing
Contributions are welcome! Please open an issue or submit a pull request for any changes.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Contact
Author: Nil Xie
Email: bfgh2678@gmail.com
GitHub: [louisxie0830](https://github.com/louisxie0830)