{"rsdb":{"rid":"397284","subhead":"","postdate":"0","aid":"273506","fid":"78","uid":"1","topic":"1","content":"
\n

\u5728\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u8bb0\u5f55\u65e5\u5fd7\u662f\u4e00\u9879\u5173\u952e\u7684\u4efb\u52a1\uff0c\u4ee5\u4fbf\u5728\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u65f6\u8ffd\u8e2a\u95ee\u9898\u3001\u76d1\u89c6\u6027\u80fd\u548c\u4fdd\u7559\u5ba1\u8ba1\u8bb0\u5f55\u3002Go \u8bed\u8a00\u63d0\u4f9b\u4e86\u7075\u6d3b\u4e14\u5f3a\u5927\u7684\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u914d\u7f6e\u548c\u4f7f\u7528\u3002\u5176\u4e2d\u4e00\u4e2a\u5e38\u7528\u7684\u65e5\u5fd7\u8bb0\u5f55\u5e93\u662f github.com\/natefinch\/lumberjack<\/code>\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b9\u4fbf\u7684\u65b9\u5f0f\u6765\u5904\u7406\u65e5\u5fd7\u6587\u4ef6\u7684\u8f6e\u6362\uff0c\u4ee5\u9632\u6b62\u65e5\u5fd7\u6587\u4ef6\u65e0\u9650\u589e\u957f\u3002<\/p> \n

\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd github.com\/natefinch\/lumberjack<\/code>\uff0c\u5305\u62ec\u5176\u4e3b\u8981\u7279\u70b9\u3001\u5982\u4f55\u4f7f\u7528\u5b83\u4ee5\u53ca\u793a\u4f8b\u4ee3\u7801\u3002\u8ba9\u6211\u4eec\u4e00\u8d77\u6df1\u5165\u4e86\u89e3\u8fd9\u4e2a\u6709\u7528\u7684 Go \u8bed\u8a00\u65e5\u5fd7\u8bb0\u5f55\u5e93\u3002<\/p> \n

\u4e3b\u8981\u7279\u70b9<\/h3> \n

github.com\/natefinch\/lumberjack<\/code> \u7684\u4e3b\u8981\u7279\u70b9\u5305\u62ec\uff1a<\/p> \n

    \n
  1. \u65e5\u5fd7\u8f6e\u6362<\/strong>\uff1a\u5b83\u5141\u8bb8\u6307\u5b9a\u65e5\u5fd7\u6587\u4ef6\u7684\u6700\u5927\u5927\u5c0f\u3002\u5f53\u65e5\u5fd7\u6587\u4ef6\u5927\u5c0f\u8fbe\u5230\u6307\u5b9a\u7684\u5927\u5c0f\u9650\u5236\u65f6\uff0c\u5b83\u4f1a\u81ea\u52a8\u8fdb\u884c\u65e5\u5fd7\u8f6e\u6362\uff0c\u5c06\u65e5\u5fd7\u5199\u5165\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u4e2d\u3002\u8fd9\u6709\u52a9\u4e8e\u907f\u514d\u65e5\u5fd7\u6587\u4ef6\u53d8\u5f97\u8fc7\u5927\u3002<\/li> \n
  2. \u57fa\u4e8e\u65e5\u5fd7\u6587\u4ef6\u5e74\u9f84\u7684\u8f6e\u6362<\/strong>\uff1a\u9664\u4e86\u57fa\u4e8e\u5927\u5c0f\u7684\u8f6e\u6362\uff0c\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u65e5\u5fd7\u6587\u4ef6\u7684\u6700\u5927\u5e74\u9f84\u3002\u5f53\u65e5\u5fd7\u6587\u4ef6\u7684\u5e74\u9f84\u8d85\u8fc7\u6307\u5b9a\u7684\u5929\u6570\u65f6\uff0c\u5b83\u4e5f\u4f1a\u8fdb\u884c\u8f6e\u6362\u3002<\/li> \n
  3. \u5907\u4efd<\/strong>\uff1a\u8be5\u5e93\u652f\u6301\u4fdd\u7559\u4e00\u5b9a\u6570\u91cf\u7684\u5907\u4efd\u65e5\u5fd7\u6587\u4ef6\u3002\u8fd9\u4e9b\u5907\u4efd\u901a\u5e38\u4ee5\u9012\u589e\u7684\u7f16\u53f7\u547d\u540d\uff0c\u4f8b\u5982 yourlog.log<\/code>\u3001yourlog.log.1<\/code>\u3001yourlog.log.2<\/code> \u7b49\u7b49\u3002<\/li> \n
  4. \u9ad8\u6027\u80fd<\/strong>\uff1alumberjack<\/code> \u4e13\u4e3a\u9ad8\u6027\u80fd\u65e5\u5fd7\u8bb0\u5f55\u800c\u8bbe\u8ba1\u3002\u5b83\u4ee5\u5f02\u6b65\u65b9\u5f0f\u5199\u5165\u65e5\u5fd7\u6761\u76ee\uff0c\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u5728\u65e0\u9700\u7b49\u5f85\u65e5\u5fd7\u5199\u5165\u5b8c\u6210\u7684\u60c5\u51b5\u4e0b\u7ee7\u7eed\u8fd0\u884c\uff0c\u4ece\u800c\u51cf\u5c11\u6027\u80fd\u5f71\u54cd\u3002<\/li> \n <\/ol> \n

    \u5982\u4f55\u4f7f\u7528 lumberjack<\/code><\/h3> \n

    \u8981\u5728 Go \u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 github.com\/natefinch\/lumberjack<\/code>\uff0c\u901a\u5e38\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p> \n

      \n
    1. \u5bfc\u5165\u5305<\/strong>\uff1a<\/p>

      \u5c06 github.com\/natefinch\/lumberjack<\/code> \u5305\u5bfc\u5165\u3002\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5bfc\u5165\u8bed\u53e5\uff1a<\/p>

      import "github.com\/natefinch\/lumberjack"\n<\/code><\/pre> <\/li> \n  
    2. \u521b\u5efa Lumberjack \u65e5\u5fd7\u8bb0\u5f55\u5668<\/strong>\uff1a<\/p>

      \u521b\u5efa lumberjack.Logger<\/code> \u7ed3\u6784\u7684\u65b0\u5b9e\u4f8b\uff0c\u6307\u5b9a\u65e5\u5fd7\u6587\u4ef6\u7684\u540d\u79f0\u3001\u6700\u5927\u5927\u5c0f\u3001\u6700\u5927\u5907\u4efd\u6570\u548c\u6700\u5927\u4fdd\u5b58\u5929\u6570\u3002\u4f8b\u5982\uff1a<\/p>

      logger := &lumberjack.Logger{\n    Filename:   "myapp.log",\n    MaxSize:    100, \/\/ \u5146\u5b57\u8282\n    MaxBackups: 3,\n    MaxAge:     28,  \/\/ \u5929\u6570\n}\n<\/code><\/pre> 

      \u8fd9\u4e2a\u5b9e\u4f8b\u5c06\u8d1f\u8d23\u5904\u7406\u65e5\u5fd7\u6587\u4ef6\u7684\u8f6e\u6362\u548c\u7ba1\u7406\u3002<\/p> <\/li> \n

    3. \u8bbe\u7f6e Go \u65e5\u5fd7\u8bb0\u5f55\u5668\u7684\u8f93\u51fa<\/strong>\uff1a<\/p>

      \u5982\u679c\u4f7f\u7528 Go \u7684\u6807\u51c6 log<\/code> \u5305\u8fdb\u884c\u65e5\u5fd7\u8bb0\u5f55\uff0c\u53ef\u4ee5\u5c06 lumberjack.Logger<\/code> \u8bbe\u7f6e\u4e3a\u65e5\u5fd7\u8bb0\u5f55\u5668\u7684\u8f93\u51fa\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b8c\u6210\uff1a<\/p>

      log.SetOutput(logger)\n<\/code><\/pre> 

      \u8fd9\u6837\uff0c\u901a\u8fc7 log.Print()<\/code>\u3001log.Println()<\/code> \u6216 log.Printf()<\/code> \u521b\u5efa\u7684\u4efb\u4f55\u65e5\u5fd7\u6761\u76ee\u90fd\u5c06\u5199\u5165\u7531 lumberjack<\/code> \u7ba1\u7406\u7684\u65e5\u5fd7\u6587\u4ef6\u3002<\/p> <\/li> \n

    4. \u7f16\u5199\u65e5\u5fd7\u6761\u76ee<\/strong>\uff1a<\/p>

      \u4f7f\u7528 Go \u7684\u6807\u51c6\u65e5\u5fd7\u8bb0\u5f55\u51fd\u6570\u6765\u7f16\u5199\u65e5\u5fd7\u6761\u76ee\u3002\u4f8b\u5982\uff1a<\/p>

      log.Println("\u8fd9\u5c06\u88ab\u5199\u5165\u7531 lumberjack \u7ba1\u7406\u7684\u65e5\u5fd7\u6587\u4ef6\u3002")\n<\/code><\/pre> <\/li> \n  
    5. \u5173\u95ed\u65e5\u5fd7\u8bb0\u5f55\u5668<\/strong>\uff1a<\/p>

      \u5728\u5e94\u7528\u7a0b\u5e8f\u9000\u51fa\u65f6\uff0c\u6216\u5728\u9002\u5f53\u7684\u65f6\u673a\uff0c\u8bf7\u786e\u4fdd\u5173\u95ed lumberjack.Logger<\/code> \u4ee5\u786e\u4fdd\u5237\u65b0\u4efb\u4f55\u5269\u4f59\u7684\u65e5\u5fd7\u6761\u76ee\u5e76\u6b63\u786e\u5173\u95ed\u65e5\u5fd7\u6587\u4ef6\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b8c\u6210\uff1a<\/p>

      logger.Close()\n<\/code><\/pre> <\/li> \n <\/ol> \n 

      \u793a\u4f8b<\/h3> \n

      \u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u5728 Go \u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 lumberjack<\/code>\uff1a<\/p> \n

      package main\n\nimport (\n\t"log"\n\t"github.com\/natefinch\/lumberjack"\n)\n\nfunc main() {\n\tlogger := &lumberjack.Logger{\n\t\tFilename:   "myapp.log",\n\t\tMax\n        Size:    100,    \/\/ \u5146\u5b57\u8282\n\t\tMaxBackups: 3,\n\t\tMaxAge:     28,  \/\/ \u5929\u6570\n\t}\n\n\tdefer logger.Close()\n\tlog.SetOutput(logger)\n\n\tlog.Println("\u8fd9\u5c06\u88ab\u5199\u5165\u7531 lumberjack \u7ba1\u7406\u7684\u65e5\u5fd7\u6587\u4ef6\u3002")\n}\n<\/code><\/pre> \n 

      \u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u65e5\u5fd7\u5c06\u5199\u5165\u540d\u4e3a "myapp.log"<\/code> \u7684\u6587\u4ef6\u4e2d\u3002\u5f53\u65e5\u5fd7\u6587\u4ef6\u5927\u5c0f\u8fbe\u5230 100 \u5146\u5b57\u8282\u3001\u8d85\u8fc7 28 \u5929\u6216\u8fbe\u5230 3 \u4e2a\u5907\u4efd\u65f6\uff0c\u5c06\u8fdb\u884c\u65e5\u5fd7\u8f6e\u6362\u3002<\/p> \n

      github.com\/natefinch\/lumberjack<\/code> \u662f\u4e00\u4e2a\u5f3a\u5927\u800c\u7075\u6d3b\u7684 Go \u8bed\u8a00\u5e93\uff0c\u7528\u4e8e\u5904\u7406\u65e5\u5fd7\u6587\u4ef6\u7684\u8f6e\u6362\u548c\u7ba1\u7406\u3002\u65e0\u8bba\u662f\u5f00\u53d1\u5c0f\u578b\u5de5\u5177\u8fd8\u662f\u5927\u89c4\u6a21\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u90fd\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b9\u4fbf\u7684\u65b9\u5f0f\u6765\u786e\u4fdd\u65e5\u5fd7\u6587\u4ef6\u4e0d\u4f1a\u65e0\u9650\u589e\u957f\uff0c\u5e76\u4e14\u80fd\u591f\u8f7b\u677e\u7ba1\u7406\u65e5\u5fd7\u6570\u636e\u3002\u5e0c\u671b\u8fd9\u7bc7\u535a\u5ba2\u80fd\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u4e86\u89e3\u5e76\u4f7f\u7528 lumberjack<\/code>\u3002<\/p> \n


      \n
      \n \"\u5b5f\u65af\u7279\" \n <\/div> \n
      \n

      \u58f0\u660e\uff1a\u672c\u4f5c\u54c1\u91c7\u7528\u7f72\u540d-\u975e\u5546\u4e1a\u6027\u4f7f\u7528-\u76f8\u540c\u65b9\u5f0f\u5171\u4eab 4.0 \u56fd\u9645 (CC BY-NC-SA 4.0)<\/a>\u8fdb\u884c\u8bb8\u53ef\uff0c\u4f7f\u7528\u65f6\u8bf7\u6ce8\u660e\u51fa\u5904\u3002
      Author:
      mengbin<\/a>
      blog:
      mengbin<\/a>
      Github:
      mengbin92<\/a>
      cnblogs:
      \u604b\u6c34\u65e0\u610f<\/a><\/p> \n <\/blockquote> \n


      \n<\/div>","orderid":"0","title":"\u6bcf\u65e5\u4e00\u5e93\uff1alumberjack -- \u65e5\u5fd7\u8f6e\u6362\u548c\u7ba1\u7406","smalltitle":"","mid":"0","fname":"GO","special_id":"0","bak_id":"0","info":"0","hits":"182","pages":"1","comments":"0","posttime":"2023-09-23 15:43:54","list":"1695455034","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"lumberjack<\/A> --\u65e5<\/A> \u7ba1\u7406<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"112.94.1.100","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u6bcf\u65e5\u4e00\u5e93\uff1alumberjack -- \u65e5\u5fd7\u8f6e\u6362\u548c\u7ba1\u7406","lastview":"1713310027","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}