{"id":18368218,"url":"https://github.com/thinkjs/think-logger","last_synced_at":"2025-04-06T17:31:39.791Z","repository":{"id":18599450,"uuid":"82624961","full_name":"thinkjs/think-logger","owner":"thinkjs","description":"Logger for ThinkJS 3.x","archived":false,"fork":false,"pushed_at":"2023-06-10T12:46:20.000Z","size":495,"stargazers_count":6,"open_issues_count":1,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-22T04:01:54.559Z","etag":null,"topics":["logger","thinkjs","thinkjs3"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thinkjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2017-02-21T02:08:16.000Z","updated_at":"2022-01-23T07:08:30.000Z","dependencies_parsed_at":"2024-06-18T18:19:22.444Z","dependency_job_id":"1e00870c-a32f-4f8b-bcd1-2d6f0cf32499","html_url":"https://github.com/thinkjs/think-logger","commit_stats":{"total_commits":94,"total_committers":13,"mean_commits":7.230769230769231,"dds":"0.34042553191489366","last_synced_commit":"53bb296c31f45466c1b491128563283542bbff57"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkjs","download_url":"https://codeload.github.com/thinkjs/think-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247522336,"owners_count":20952524,"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","thinkjs","thinkjs3"],"created_at":"2024-11-05T23:25:09.458Z","updated_at":"2025-04-06T17:31:39.419Z","avatar_url":"https://github.com/thinkjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# think-logger\n\n[![npm](https://img.shields.io/npm/v/think-logger3.svg?style=flat-square)]()\n[![Travis](https://img.shields.io/travis/thinkjs/think-logger.svg?style=flat-square)]()\n[![Coveralls](https://img.shields.io/coveralls/thinkjs/think-logger/master.svg?style=flat-square)]()\n[![David](https://img.shields.io/david/thinkjs/think-logger.svg?style=flat-square)]()\n\nThinkJS3.x log module, based on [log4js](https://github.com/log4js-node/log4js-node).\n\n## Installation\n\n    npm install think-logger3\n\n\n## How To Use\n\n\n### Basic \n\n  ```js\n const Logger = require('think-logger3');\n const logger = new Logger();\n logger.debug('Hello World');\n  ```\n\n\nThere has four log function you can use:\n\n ```js\nlogger.info('info log');\nlogger.debug('debug log');\nlogger.warn('warn log');\nlogger.error('error log');\n ```\n\n### Advanced\n\nIf you want to log file, you can use file adapter like this:\n\n```js\nconst Logger = require('think-logger3');\nconst logger = new Logger({\n   handle: Logger.File,\n   filename: __dirname + '/test.log'\n});\nlogger.debug('Hello World');\n```\n\n## Adapters\n\n### File\n\nThis adapter will log to a file, and supports split log file by a constant file size. For example:\n\n```js\nconst Logger = require('think-logger3');\nconst logger = new Logger({\n  handle: Logger.File,\n  filename: __dirname + '/debug.log',\n  maxLogSize: 50 * 1024,  //50M\n  backups: 10 //max chunk number\n})\n```\n\nThen initial log would create a file called `debug.log`. After this file reached `maxLogSize`, a new file named `debug.log.1` will be created. After log file number reached `backups`, old log chunk file will be removed.\n\n#### Configuration\n\n- `filename`: log filename\n- `maxLogSize`: The maximum size (in bytes) for a log file, if not provided then logs won't be rotated.\n- `backups`: The number of log files to keep after logSize has been reached (default 5)\n- `absolute`: If `filename` is a absolute path, the `absolute` value should be `true`.\n- `layout`: Layout defines the way how a log record is rendered. More layouts can see [here](https://log4js-node.github.io/log4js-node/layouts.html).\n\n### DateFile\n\nThis adapter will log to a file, moving old log messages to timestamped files according to a specified pattern. For example:\n\n```js\nconst Logger = require('think-logger3');\nconst logger = new Logger({\n  handle: Logger.DateFile,\n  filename: __dirname + '/debug.log',\n  pattern: '-yyyy-MM-dd',\n  alwaysIncludePattern: false\n});\n```\n\nThen initial log would create a file called `debug.log`. At midnight, the current `debug.log` file would be rename to `debug.log-2017-03-12`(for example), and a new `debug.log` file created.\n\n#### Configuration\n\n- `level`: log level\n- `filename`: log base filename\n- `pattern`: date filename would append to filename. A new file is started whenever the pattern for the current log entry differs from that of the previous log entry. The following strings are recognised in the pattern:\n  - yyyy - the full year, use yy for just the last two digits\n  - MM - the month\n  - dd - the day of the month\n  - hh - the hour of the day (24-hour clock)\n  - mm - the minute of the hour\n  - ss - seconds\n  - SSS - milliseconds (although I'm not sure you'd want to roll your logs every millisecond)\n  - O - timezone (capital letter o)\n- `alwaysIncludePattern`: If `alwaysIncludePattern` is true, then the initial file will be `filename.2017-03-12` and no renaming will occur at midnight, but a new file will be written to with the name `filename.2017-03-13`.\n- `absolute`: If `filename` is a absolute path, the `absolute` value should be `true`.\n- `layout`: Layout defines the way how a log record is rendered. More layouts can see [here](https://log4js-node.github.io/log4js-node/layouts.html).\n\n### Basic\n\nIf those adapter configuration can't satisfy your need, you can use this adapter and set config like log4js. For example:\n\n```js\nconst Logger = require('think-logger3');\nconst logger = new Logger({\n  handle: Logger.Basic,\n  appenders: {\n    everything: { type: 'file', filename: 'all-the-logs.log' },\n    emergencies: {  type: 'file', filename: 'oh-no-not-again.log' },\n    'just-errors': { type: 'logLevelFilter', appender: 'emergencies', level: 'error' }\n  },\n  categories: {\n    default: { appenders: ['just-errors', 'everything'], level: 'debug' }\n  }\n});\n```\n\nAll properties are as same as log4js except `handle` property. You can see more configure properties on [log4js documentation](https://log4js-node.github.io/log4js-node/api.html#configuration-object).\n\n\n## Contributing\n\nContributions welcome!\n\n## License\n\n[MIT](https://github.com/thinkjs/think-logger/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkjs%2Fthink-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-logger/lists"}