human-logs
v1.1.1
Published
Human friendly logs for your APIs & projects.
Downloads
690
Maintainers
Readme
human-logs
🛠 A tiny log library that allows you to take events, explanations and solutions and connect them like lego-pieces to create user-friendly logs.
Good log messages increases customer satisfaction, as they work as sort of a guide, helping the user achieve what they wanted to achieve. Good logs minimize the amount of support calls, improve customer satisfaction and trust in your product, ultimately being a win-win for both the creators of software and the users.
Inspired by Vercel's Error design framework, human-logs allows you to take events, explanations and solutions, and connect them like lego-pieces, to create user-friendly logs in a versatile manner.
Focus on understanding the errors.
Features
- Create consistent, human-friendly logs throughout your application or library
- Build versatile errors like lego-blocks
- Support for parameters
💻 Example Usage
export const apiLogs = createHumanLogs({
events: {
project_create_failed: 'Cannot create your project',
team_create_failed: 'Cannot create your team',
},
explanations: {
api_unreachable: 'because the API cannot be reached.',
team_exists: {
template: 'because a team with ID "{teamId}" already exists.',
params: {
teamId: ''
}
}
},
solutions: {
check_status_page: {
template: 'You can check the status of our services on our status page.',
params: {},
actions: [
{
text: 'Go to status page',
href: 'https://skosh.dev'
}
]
}
}
})
// You can now use `apiLogs` to create user-friendly error logs, by connecting events, explanations and solutions like lego-blocks.
const log = apiLogs({
event: ['project_create_failed'],
explanation: ['api_unreachable'],
solution: ['check_status_page']
})
console.log(log.message)
// => Cannot create your project because the API cannot be reached. You can check the status of our services on our status page.
console.log(log.actions)
/* => [{
text: 'Go to status page',
href: 'https://status.foobar.inc'
}]*/
console.log(log.toString())
// => Cannot create your project because the API cannot be reached. You can check the status of our services on our status page. Go to status page (https://status.foobar.inc)
// Example with parameters
const logWithParams = apiLogs({
event: ['team_create_failed'],
explanation: ['team_exists'],
params: {
teamId: 'winning-team'
}
})
console.log(logWithParams.message)
// => Cannot create your team because a team with ID "winning-team" already exists.
💻 Development
- Clone this repository
- Enable Corepack using
corepack enable
(usenpm i -g corepack
for Node.js < 16.10) - Install dependencies using
pnpm install
- Run the tests using
pnpm dev
License
Made with ❤️ in Helsinki
Published under MIT License.