{"id":22433736,"url":"https://github.com/gavinning/gre","last_synced_at":"2025-03-27T07:46:06.252Z","repository":{"id":57253864,"uuid":"65288979","full_name":"gavinning/gre","owner":"gavinning","description":"日志输出","archived":false,"fork":false,"pushed_at":"2016-08-19T06:59:38.000Z","size":987,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-30T00:23:08.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/gavinning.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-09T11:16:02.000Z","updated_at":"2016-08-09T11:16:43.000Z","dependencies_parsed_at":"2022-08-31T22:12:01.127Z","dependency_job_id":null,"html_url":"https://github.com/gavinning/gre","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fgre","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fgre/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fgre/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fgre/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gavinning","download_url":"https://codeload.github.com/gavinning/gre/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245806390,"owners_count":20675296,"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":[],"created_at":"2024-12-05T22:15:45.617Z","updated_at":"2025-03-27T07:46:06.207Z","avatar_url":"https://github.com/gavinning.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"gre\n---\n日志输出\n\n\n### Install\n```sh\nnpm i gre --save\n```\n\n### Example 1\n```js\nvar gre = require('gre');\n// dev模式\nvar g = gre.create();\n\ng.log('hello');\ng.trace('hello', 'world');\ng.debug('hello',  'world', 123);\ng.info('hello',  'world', 123, {foo:'bar'});\ng.warn('hello', 'world', 123, {foo:'bar'});\ng.error('hello', 'world', 123, {foo:'bar'}, [1, 2, 3, 4], Object);\n```\n==\u003e Result :  \n![result](img/1.png)\n\n### Example 2\n```js\nvar gre = require('gre');\n// tiny模式 最小化输出\nvar g = gre.create('tiny');\n\ng.log('hello');\ng.trace('hello', 'world');\ng.debug('hello',  'world', 123);\ng.info('hello',  'world', 123, {foo:'bar'});\ng.warn('hello', 'world', 123, {foo:'bar'});\ng.error('hello', 'world', 123, {foo:'bar'}, [1, 2, 3, 4], Object);\n```\n==\u003e Result :  \n![result](img/2.png)\n\n### Example 3\n```js\nvar gre = require('gre');\n// prod模式\ng = gre.create({\n    format: 'prod',\n    project: path.dirname(__dirname)\n})\n\ng.log('hello');\ng.trace('hello', 'world');\ng.debug('hello',  'world', 123);\ng.info('hello',  'world', 123, {foo:'bar'});\ng.warn('hello', 'world', 123, {foo:'bar'});\ng.error('hello', 'world', 123, {foo:'bar'}, [1, 2, 3, 4], Object);\n```\n==\u003e Result :  \n![result](img/3.png)\n\n### Options\n```js\n{\n    // 格式化字符串\n    format: 'dev',\n    // 是否彩色输出\n    color: true,\n    // 项目路径，配置次参数:path输出相对路径，不配置:path输出绝对路径\n    project: '',\n    // 默认时间格式化字符串\n    dateformat: 'yyyy-MM-dd hh:mm:ss'\n}\n```\n\n### Format String\n内置配置\n```js\ndev: '[:file::line] :message',\ntiny: ':message',\nprod: '[:time[yyyy-MM-dd hh:mm:ss]][:title][:path::line] :message',\nfull: '[:time[yyyy-MM-dd hh:mm:ss.SSS]][:title][:path::line] :message',\ntime: '[:time[hh:mm:ss]][:file::line] :message',\nfulltime: '[:time][:file::line] :message'\n```\n所有关键字\n```none\n:time[yyyy-MM-dd hh:mm:ss.SSS] :title :file :path :line :message\n```\n自定义关键字 \u0026 自定义日志输出格式\n```js\nvar os = require('os');\nvar gre = require('gre');\n\n// 自定义关键字\ngre.token('platform', () =\u003e os.platform())\n\n// 自定义日志输出格式\nvar g = gre.create('[:time[hh:mm:ss]][:platform][:file::line] :message');\n\ng.log('hello');\ng.trace('hello', 'world');\ng.debug('hello',  'world', 123);\ng.info('hello',  'world', 123, {foo:'bar'});\ng.warn('hello', 'world', 123, {foo:'bar'});\ng.error('hello', 'world', 123, {foo:'bar'}, [1, 2, 3, 4], Object);\n```\n==\u003e Result :  \n![result](img/4.png)\n\n---\n```sh\nnpm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fgre","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavinning%2Fgre","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fgre/lists"}