{"id":23004455,"url":"https://github.com/marvin-j97/skriva","last_synced_at":"2025-04-02T14:27:06.166Z","repository":{"id":37858359,"uuid":"444822047","full_name":"marvin-j97/skriva","owner":"marvin-j97","description":"Unopinionated logger, with 0 dependencies - tailored for Typescript usage.","archived":false,"fork":false,"pushed_at":"2024-06-03T12:49:34.000Z","size":183,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T13:55:28.837Z","etag":null,"topics":["logger","logging","logging-library","minimal","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marvin-j97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://www.buymeacoffee.com/marvin.j97"]}},"created_at":"2022-01-05T13:53:31.000Z","updated_at":"2022-02-07T00:48:28.000Z","dependencies_parsed_at":"2025-02-08T05:29:11.592Z","dependency_job_id":"9a1444ad-c86e-4742-93a8-484e7ac9b699","html_url":"https://github.com/marvin-j97/skriva","commit_stats":{"total_commits":45,"total_committers":2,"mean_commits":22.5,"dds":0.06666666666666665,"last_synced_commit":"7ee2ed1c9d19ffef693119bd39ab63475b60379e"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":"marvin-j97/typescript-eslint-ava-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marvin-j97%2Fskriva","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marvin-j97%2Fskriva/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marvin-j97%2Fskriva/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marvin-j97%2Fskriva/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marvin-j97","download_url":"https://codeload.github.com/marvin-j97/skriva/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246830916,"owners_count":20840904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logger","logging","logging-library","minimal","typescript"],"created_at":"2024-12-15T07:18:35.496Z","updated_at":"2025-04-02T14:27:06.143Z","avatar_url":"https://github.com/marvin-j97.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/marvin.j97"],"categories":[],"sub_categories":[],"readme":"# skriva\n\n[![Node.js CI](https://github.com/marvin-j97/skriva/actions/workflows/node.js.yml/badge.svg)](https://github.com/marvin-j97/skriva/actions/workflows/node.js.yml)\n\nFrom Old Norse _skrifa_, from Proto-Germanic _\\*skrībaną_, a late borrowing from Latin _scrībō_ (\"write\")\n\n## About\n\nSuper-unopinionated no-black-magic logger, with zero dependencies, tailored for Typescript usage.\n\nLike other logging libraries, multiple transports with custom logging levels are supported.\n\n## Install\n\n```bash\nnpm i skriva\nyarn add skriva\n```\n\n## Examples\n\n### Define log levels\n\n```typescript\n// Lower value = more important\nconst logLevels = {\n  error: 0,\n  warn: 10,\n  info: 20,\n  debug: 30,\n};\n\nconst logger = createLogger({\n  logLevels,\n  // Setting to 'info' will print everything up to info (error, warn, info in this case)\n  level: \"info\",\n  /* ... */\n});\n\nconst logger1 = createLogger({\n  logLevels,\n  // Setting to an array works like a whitelist, so in this case ONLY info will be printed\n  level: [\"info\"],\n  /* ... */\n});\n```\n\n### Basic console logger\n\n```typescript\nimport { createLogger } from \"skriva\";\n// Use prebuilt console transport\nimport { createConsoleTransport } from \"skriva-transport-console\";\n\nconst logLevels = {\n  error: 0,\n  warn: 10,\n  info: 20,\n  debug: 30,\n};\n\n// createLogger has 3 types that describe what types of logs are being used\n// Type 1 is the message type, aka. the data that is being written\n// Type 2 is the log level type\n// Type 3 is the type of the base context\nconst logger = createLogger\u003cstring, typeof logLevels, {}\u003e({\n  context: () =\u003e ({}),\n  logLevels,\n  level: \"debug\",\n  transports: [\n    // Transports receive an object (packet) containing:\n    // - the message\n    // - the log level\n    // - the base context (merged into the object)\n    {\n      handler: createConsoleTransport({\n        format: ({ message }) =\u003e message,\n      }),\n    },\n  ],\n});\n\n// logger is fully type-safe, containing your custom log levels as functions\nlogger.info(\"This is a log\");\n// -\u003e This is a log\n```\n\n### Base context\n\n```typescript\nconst logger = createLogger({\n  // Adds timestamp to every log\n  // This alone won't make it show up in the message, you need to consume the context (see \"More complex logger\" or \"Console logger with colours\")\n  // The base context function is executed for every received log message\n  context: () =\u003e ({ timestamp: new Date() }),\n  /* ... */\n});\n```\n\n### Basic JSON logger\n\n```typescript\nimport { createLogger } from \"skriva\";\n// Use prebuilt console transport\nimport { createConsoleTransport } from \"skriva-transport-console\";\n\nconst logLevels = {\n  error: 0,\n  warn: 10,\n  info: 20,\n  debug: 30,\n};\n\nconst logger = createLogger\u003cstring, typeof logLevels, { timestamp: Date }\u003e({\n  context: () =\u003e ({ timestamp: new Date() }),\n  logLevels,\n  level: \"debug\",\n  transports: [\n    {\n      handler: createConsoleTransport({\n        format: (packet) =\u003e JSON.stringify(packet),\n      }),\n    },\n  ],\n});\n\nlogger.info(\"This is a log\");\n// -\u003e {\"timestamp\":\"2022-01-18T20:27:32.389Z\",\"message\":\"This is a log\",\"level\":\"info\"}\n```\n\n### More complex logger\n\n```typescript\nimport { createLogger } from \"skriva\";\n// Use prebuilt console transport\nimport { createConsoleTransport } from \"skriva-transport-console\";\n\nconst logLevels = {\n  error: 0,\n  warn: 10,\n  info: 20,\n  debug: 30,\n};\n\nconst logger = createLogger\u003c\n  { module: \"orm\" | \"rest_api\"; text: string },\n  typeof logLevels,\n  { timestamp: Date }\n\u003e({\n  context: () =\u003e ({ timestamp: new Date() }),\n  logLevels,\n  level: \"debug\",\n  transports: [\n    {\n      handler: createConsoleTransport({\n        format: ({ message, ...rest }) =\u003e JSON.stringify({ ...message, ...rest }),\n      }),\n    },\n  ],\n});\n\nlogger.error({\n  module: \"orm\",\n  text: \"i had an error\",\n});\n// -\u003e {\"module\":\"orm\",\"message\":\"i had an error\",\"timestamp\":\"2022-01-18T20:31:10.553Z\",\"level\":\"error\"}\n```\n\n### Handle errors\n\n```typescript\nimport { createLogger } from \"skriva\";\n\nconst logger = createLogger({\n  /* ... */\n  onError: (error) =\u003e {\n    console.error(\"Logging error\");\n    sendMessageToSlack(error);\n  },\n});\n```\n\n### Console logger with colours\n\n```typescript\nimport { createLogger } from \"skriva\";\n// Use prebuilt console transport\nimport { createConsoleTransport } from \"skriva-transport-console\";\nimport chalk from \"chalk\";\n\nconst logLevels = {\n  error: 0,\n  warn: 10,\n  info: 20,\n  debug: 30,\n};\n\nconst colorize: Record\u003ckeyof typeof logLevels, Chalk\u003e = {\n  error: chalk.red,\n  warn: chalk.yellow,\n  info: chalk.green,\n  debug: chalk.magentaBright,\n};\n\nconst logger = createLogger\u003cstring, typeof logLevels, { timestamp: Date }\u003e({\n  context: () =\u003e ({ timestamp: new Date() }),\n  logLevels,\n  level: \"debug\",\n  transports: [\n    {\n      handler: createConsoleTransport({\n        format: ({ timestamp, level, message }) =\u003e\n          `${chalk.grey(timestamp.toISOString())} ${colorize[level](level)} ${message}`,\n      }),\n    },\n  ],\n});\n\nlogger.info(\"Hello world\");\nlogger.debug(\"Another message\");\nlogger.error(\"Oh no\");\nlogger.warn(\"Warning\");\n```\n\n## Transports\n\n- [Console transport](./packages/transport-console) (recommended)\n- [Rotating file transport](./packages/transport-rotate-file) (recommended)\n- [Elasticsearch transport](./packages/transport-elasticsearch)\n\n## Planned\n\n- HTTP(s) transport\n- Parseable transport\n- DynamoDB transport\n- Redis transport\n- MongoDB transport\n- SQS transport\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarvin-j97%2Fskriva","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarvin-j97%2Fskriva","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarvin-j97%2Fskriva/lists"}