Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stanbubnoff/logmark
Simple, lightweight and dependency free nodejs logger
https://github.com/stanbubnoff/logmark
console debugging javascript log logger logging logging-library logs nodejs print terminal
Last synced: about 11 hours ago
JSON representation
Simple, lightweight and dependency free nodejs logger
- Host: GitHub
- URL: https://github.com/stanbubnoff/logmark
- Owner: stanbubnoff
- License: mit
- Created: 2022-11-08T11:20:50.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-14T15:51:28.000Z (over 2 years ago)
- Last Synced: 2025-02-13T08:52:24.789Z (2 days ago)
- Topics: console, debugging, javascript, log, logger, logging, logging-library, logs, nodejs, print, terminal
- Language: JavaScript
- Homepage: https://github.com/stasbubnoff/logmark
- Size: 471 KB
- Stars: 10
- Watchers: 1
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
![]()
# Simple, lightweight (<5Kb) and dependency free nodejs logger with human-readable logs
> ## Why?
> I needed a very simple logger without third-party dependencies, a complex > configuration and with a beautiful human-readable output.
>
> I didn't find it, so I wrote it.## Quick start
Install the library from npm:
``` properties
npm install logmark
```
or
``` properties
yarn add logmark
```
Logmark supports five levels of logs:- debug
- info
- warn
- error
- fatalBy default, Logmark generates a new 'logs' folder in your project root, and write all logs to a single `logs.log` file
Let's look at the code below:
```javascript
import { Logmark } from 'logmark'const mark = new Logmark()
mark.debug('some debug message')
mark.info('some info message')
mark.warn('some warn message')
mark.error('some error message')
mark.fatal('some fatal message')
```
Now we can see next terminal output:!['console screen1'](./docs/img/console_screen1.png)
As you can see, Logmark adds local time, pid and memory usage information to each message.
I think the memory usage information is very important, and seeing it in logs is very convenient for tracking memory leaks. It may also make it clear early on that refactoring of some functions is necessary.
Logmark has already created the logs folder and added the `logs.log` file to it.
Let's look at the file output:!['file screen1'](./docs/img/file_screen1.png)
In many cases this is enough for basic use, but you can add a few settings to distribute logs to different files, and you can also attach additional information to messages.
## Usage
### Config
Let's look how you can set a custom path for the logs folder and file, and distribute logs to different files.```javascript
import { Logmark } from 'logmark'const mark = new Logmark({
files: {
enabled: true, // set the value to false to disable logging to files
pathname: 'custom logs path',
filename: 'custom logs file'
}
})
```
You can also assign a file name for each log level and group logs in any way.```javascript
import { Logmark } from 'logmark'const mark = new Logmark({
files: {
enabled: true,
pathname: 'custom logs path',
// filename: 'custom logs file'
filenames: {
debug: 'डिबग',
info: '资料',
warn: 'atención',
error: 'errors',
fatal: 'errors'
}
}
})
```### Add tag
You can set a tag to identify the initiator of the message.
```javascript
import { Logmark } from 'logmark'const mark = new Logmark()
mark.debug('some debug message', {
tag: 'server'
})
```
Console output:!['file screen2'](./docs/img/console_screen2.png)
### Add attachment
You can add an any data or error object to your log message```javascript
import { Logmark } from 'logmark'const mark = new Logmark()
mark.info('some debug message', {
tag: 'server',
data: { important: 'object' }
})mark.warn('some debug message', {
tag: 'server',
data: 'important string'
})mark.debug('some debug message', {
tag: 'server',
data: 10000
})mark.error('some debug message', {
tag: 'server',
error: new Error('error object')
})mark.fatal('some debug message', {
tag: 'server',
error: new Error('fatal error object')
})
```
Console output:!['file screen2'](./docs/img/console_screen3.png)
File output:
!['file screen2'](./docs/img/file_screen2.png)
## Roadmap
I hope to keep developing the library without compromising on its simplicity and minimalism. If there are suggestions, then forks and pull request are welcome!
If you would like to see some functionality, you can open an issue.
I plan to add functionality for daily file rotation in the near future.
## Contributing
Use StandardJS style and SonarLint - contributions are welcome!
## Support project
If you want to support the project with a small donation for my small contribution to open source, I will be very very happy!
BTC: bc1q4my5g4jf9cy0gzqams9mp06kmyuj59qgpwmrh6
ETH: 0x2C4e8803ecF2E44D55aF615dF8476C786B5b764a
USDT: 0x2C4e8803ecF2E44D55aF615dF8476C786B5b764a
USDC: 0x2C4e8803ecF2E44D55aF615dF8476C786B5b764aAlso, giving me a simple "star" on GitHub is an easy way to support :)
Thanks!