Node.js Logging with Winston 教程

随笔3个月前发布 乌园长
33 0 0

Node.js Logging with Winston 教程

nodejs-logging-winstonNode.js client integration between Stackdriver Logging and Winston.项目地址:https://gitcode.com/gh_mirrors/no/nodejs-logging-winston

1. 项目的目录结构及介绍




nodejs-logging-winston/


├── samples/


│   ├── quickstart.js


│   └── system-tests/


├── src/


│   ├── index.ts


│   ├── logging-winston.ts


│   └── protos/


├── test/


│   ├── logging-winston.test.ts


│   └── system-test/


├── .gitignore


├── .npmignore


├── .prettierrc


├── CONTRIBUTING.md


├── LICENSE


├── README.md


├── package.json


└── tsconfig.json

samples/: 包含示例代码,如 quickstart.js 快速启动示例。src/: 项目的主要源代码,包括入口文件 index.ts 和主要逻辑文件 logging-winston.tstest/: 包含项目的测试文件,如单元测试和系统测试。.gitignore: Git 忽略文件列表。.npmignore: NPM 忽略文件列表。.prettierrc: Prettier 代码格式化配置文件。CONTRIBUTING.md: 贡献指南。LICENSE: 项目许可证。README.md: 项目说明文档。package.json: 项目依赖和脚本配置。tsconfig.json: TypeScript 配置文件。

2. 项目的启动文件介绍

项目的启动文件位于 samples/quickstart.js,这是一个快速启动示例,展示了如何使用 nodejs-logging-winston 进行日志记录。




const winston = require('winston');


const { LoggingWinston } = require('@google-cloud/logging-winston');


 


const loggingWinston = new LoggingWinston();


 


const logger = winston.createLogger({


  level: 'info',


  transports: [


    new winston.transports.Console(),


    loggingWinston,


  ],


});


 


logger.info('Hello, world!');

3. 项目的配置文件介绍

项目的配置文件主要是 package.jsontsconfig.json

package.json




{


  "name": "@google-cloud/logging-winston",


  "version": "4.0.0",


  "description": "Stackdriver Logging transport for Winston",


  "main": "build/src/index.js",


  "types": "build/src/index.d.ts",


  "files": [


    "build/src"


  ],


  "scripts": {


    "test": "npm run compile && npm run system-test",


    "compile": "tsc",


    "prepublishOnly": "npm run compile"


  },


  "dependencies": {


    "@google-cloud/logging": "^9.0.0",


    "winston": "^3.0.0",


    "duplexify": "^4.1.1"


  },


  "devDependencies": {


    "@types/node": "^14.0.0",


    "typescript": "^4.0.0"


  }


}

tsconfig.json




{


  "compilerOptions": {


    "target": "es2018",


    "module": "commonjs",


    "outDir": "./build",


    "rootDir": "./src",


    "strict": true,


    "esModuleInterop": true,


    "skipLibCheck": true


  },


  "include": [


    "src/**/*.ts"


  ]


}

以上是 nodejs-logging-winston 项目的基本介绍和配置文件说明。希望这些信息能帮助你更好地理解和使用该项目。

nodejs-logging-winstonNode.js client integration between Stackdriver Logging and Winston.项目地址:https://gitcode.com/gh_mirrors/no/nodejs-logging-winston

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...