{"action":"created","issue":{"url":"https://api.github.com/repos/vnpy/vnpy/issues/405","repository_url":"https://api.github.com/repos/vnpy/vnpy","labels_url":"https://api.github.com/repos/vnpy/vnpy/issues/405/labels{/name}","comments_url":"https://api.github.com/repos/vnpy/vnpy/issues/405/comments","events_url":"https://api.github.com/repos/vnpy/vnpy/issues/405/events","html_url":"https://github.com/vnpy/vnpy/issues/405","id":242932348,"number":405,"title":"关于日志打印的一点建议","user":{"login":"zzniwei","id":29447404,"avatar_url":"https://avatars2.githubusercontent.com/u/29447404?v=4","gravatar_id":"","url":"https://api.github.com/users/zzniwei","html_url":"https://github.com/zzniwei","followers_url":"https://api.github.com/users/zzniwei/followers","following_url":"https://api.github.com/users/zzniwei/following{/other_user}","gists_url":"https://api.github.com/users/zzniwei/gists{/gist_id}","starred_url":"https://api.github.com/users/zzniwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zzniwei/subscriptions","organizations_url":"https://api.github.com/users/zzniwei/orgs","repos_url":"https://api.github.com/users/zzniwei/repos","events_url":"https://api.github.com/users/zzniwei/events{/privacy}","received_events_url":"https://api.github.com/users/zzniwei/received_events","type":"User","site_admin":false},"labels":[{"id":182220021,"url":"https://api.github.com/repos/vnpy/vnpy/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-07-14T08:34:07Z","updated_at":"2017-09-01T06:36:26Z","closed_at":"2017-09-01T06:36:26Z","author_association":"NONE","body":"我在编写自己的代码调测的过程中，发现系统日志打印不是很方便，自己写了个日志打印的类，在写程序\r\n的时候可以自己打印日志，方面程序调测和数据分析，建议vnpy能不能提供一个强大日志打印模块，方便大家调测系统。\r\n\r\n\r\n--------------------\r\n自定义日志类\r\nclass AppLoger(object):\r\n    \"\"\"自定义日志\"\"\"\r\n    def __init__(self):\r\n        super(AppLoger, self).__init__()\r\n\r\n        self.loger = logging.getLogger('test')\r\n        \r\n        #设置日志格式\r\n        fmt = '%(asctime)s %(filename)s[line:%(lineno)d] %(thread)d %(levelname)s %(message)s'\r\n        datefmt = '%a, %d %b %Y %H:%M:%S'\r\n        self.rotation_handler =handlers.RotatingFileHandler('vnapp.log', 'a', 10*1024*1024, 5)\r\n        rotation_handler_formater = logging.Formatter(fmt,datefmt)\r\n        self.rotation_handler.setFormatter(rotation_handler_formater)\r\n        #设置日志级别\r\n        self.rotation_handler.setLevel(logging.DEBUG)\r\n        self.loger.addHandler(self.rotation_handler)\r\n\r\n    def get_logger(self):\r\n        return self.loger\r\n\r\n    def set_log_level(self, level):\r\n        self.loger.setLevel(level)\r\n\r\n    def set_log_format(self, para):\r\n        self.rotation_handler.setFormatter(para)\r\n--------------------------------\r\n使用\r\n\r\nfrom vtFunction import AppLoger\r\napploger = AppLoger()\r\napploger.set_log_level(logging.INFO)\r\nDtpLogger = apploger.get_logger()\r\n----------------------------------\r\n样例\r\n\r\nFri, 14 Jul 2017 09:30:56 strategyDualThrustPlus.py[line:220] 22680 INFO self.range 66.000000, self.longEntry 3689.200000, self.shortEntry 3662.800000 \r\nFri, 14 Jul 2017 09:30:56 strategyDualThrustPlus.py[line:220] 22680 INFO self.range 66.000000, self.longEntry 3689.200000, self.shortEntry 3662.800000 \r\nFri, 14 Jul 2017 09:30:56 strategyDualThrustPlus.py[line:220] 22680 INFO self.range 66.000000, self.longEntry 3689.200000, self.shortEntry 3662.800000 \r\nFri, 14 Jul 2017 13:36:57 strategyDualThrustPlus.py[line:265] 22680 INFO open long position at 3691.200000 with orderid CtaStopOrder.1 bartime None self.pos 0\r\nFri, 14 Jul 2017 13:36:57 strategyDualThrustPlus.py[line:265] 22680 INFO open long position at 3691.200000 with orderid CtaStopOrder.1 bartime None self.pos 0\r\nFri, 14 Jul 2017 13:36:57 strategyDualThrustPlus.py[line:265] 22680 INFO open long position at 3691.200000 with orderid CtaStopOrder.1 bartime None self.pos 0\r\nFri, 14 Jul 2017 14:55:57 strategyRbreaker.py[line:440] 22680 INFO cover the positon time prev_close:6108.200000, bar.close:6093.800000\r\nFri, 14 Jul 2017 14:55:57 strategyRbreaker.py[line:440] 22680 INFO cover the positon time prev_close:6108.200000, bar.close:6093.800000\r\nFri, 14 Jul 2017 14:55:57 strategyRbreaker.py[line:440] 22680 INFO cover the positon time prev_close:6108.200000, bar.close:6093.800000\r\nFri, 14 Jul 2017 14:55:57 strategyDualThrustPlus.py[line:339] 22680 INFO endtrading sell position at 3694.400000 with orderid CtaStopOrder.2 bartime None self.pos 2\r\nFri, 14 Jul 2017 14:55:57 strategyDualThrustPlus.py[line:339] 22680 INFO endtrading sell position at 3694.400000 with orderid CtaStopOrder.2 bartime None self.pos 2\r\nFri, 14 Jul 2017 14:55:57 strategyDualThrustPlus.py[line:339] 22680 INFO endtrading sell position at 3694.400000 with orderid CtaStopOrder.2 bartime None self.pos 2\r\nFri, 14 Jul 2017 14:56:57 strategyRbreaker.py[line:440] 22680 INFO cover the positon time prev_close:6108.200000, bar.close:6095.400000\r\nFri, 14 Jul 2017 14:56:57 strategyRbreaker.py[line:440] 22680 INFO cover the positon time prev_close:6108.200000, bar.close:6095.400000\r\nFri, 14 Jul 2017 14:56:57 strategyRbreaker.py[line:440] 22680 INFO cover the positon time prev_close:6108.200000, bar.close:6095.400000\r\nFri, 14 Jul 2017 14:57:57 strategyRbreaker.py[line:440] 22680 INFO cover the positon time prev_close:6108.200000, bar.close:6093.600000\r\nFri, 14 Jul 2017 14:57:57 strategyRbreaker.py[line:440] 22680 INFO cover the positon time prev_close:6108.200000, bar.close:6093.600000\r\n------------------------\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/vnpy/vnpy/issues/comments/326502185","html_url":"https://github.com/vnpy/vnpy/issues/405#issuecomment-326502185","issue_url":"https://api.github.com/repos/vnpy/vnpy/issues/405","id":326502185,"user":{"login":"vnpy","id":11263900,"avatar_url":"https://avatars0.githubusercontent.com/u/11263900?v=4","gravatar_id":"","url":"https://api.github.com/users/vnpy","html_url":"https://github.com/vnpy","followers_url":"https://api.github.com/users/vnpy/followers","following_url":"https://api.github.com/users/vnpy/following{/other_user}","gists_url":"https://api.github.com/users/vnpy/gists{/gist_id}","starred_url":"https://api.github.com/users/vnpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vnpy/subscriptions","organizations_url":"https://api.github.com/users/vnpy/orgs","repos_url":"https://api.github.com/users/vnpy/repos","events_url":"https://api.github.com/users/vnpy/events{/privacy}","received_events_url":"https://api.github.com/users/vnpy/received_events","type":"User","site_admin":false},"created_at":"2017-09-01T06:36:26Z","updated_at":"2017-09-01T06:36:26Z","author_association":"OWNER","body":"已完成"}}
{"actor":{"display_login":"vnpy"}}