Python Note 800 - logger

常用代码: self.logger = logging.getLogger(__name__) self.logger.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') ch.setFormatter(formatter) self.logger.addHandler(ch) 基本用法: import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s %(message)s') LOG = logging.getLogger('test') LOG.debug('调试信息') LOG.info('有用的信息') LOG.warning('警告信息') LOG.error('错误信息') LOG.critical('严重错误信息') %(name)s Logger的名字 %(levelno)s 数字形式的日志级别 %(levelname)s 文本形式的日志级别 %(pathname)s 调用日志输出函数的模块的完整路径名,可能没有 %(filename)s 调用日志输出函数的模块的文件名 %(module)s 调用日志输出函数的模块名 %(funcName)s 调用日志输出函数的函数名 %(lineno)d 调用日志输出函数的语句所在的代码行 %(created)f 当前时间,用UNIX标准的表示时间的浮点数表示 %(relativeCreated)d 输出日志信息时的,自Logger创建以来的毫秒数 %(asctime)s 字符串形式的当前时间。默认格式是“2003-07-0816:49:45,896”。逗号后面的是毫秒 %(thread)d 线程ID。可能没有 %(threadName)s 线程名。可能没有 %(process)d 进程ID。可能没有 %(message)s 用户输出的消息

February 13, 2017 · 1 min · Me

Python Note 900 - Other

ConfigParser Usage Example: conf_file = 'conf.ini' conf_parser = ConfigParser.ConfigParser() conf_parser.read(conf_file) conf = {key: value for key, value in conf_parser.items(section_name)} Deal with INI file 基本的文件示例如下: [DEFAULT] ServerAliveInterval = 45 Compression = yes CompressionLevel = 9 ForwardX11 = yes [bitbucket.org] User = hg [topsecret.server.com] Port = 50022 ForwardX11 = no 如何生成 INI 文件 >>> import configparser >>> config = configparser.ConfigParser() >>> config['DEFAULT'] = {'ServerAliveInterval': '45', ... 'Compression': 'yes', ... 'CompressionLevel': '9'} >>> config['bitbucket....

February 13, 2017 · 4 min · Me

Git Note

基本用法 添加文件: git add README test.rb LICENSE 提交变动: git commit -m 'initial commit of my project' git commit -a -m 'made a change' 列出当前所有分支,前面带星号的是当前所有分支: git branch 查看各个分支最后一个提交对象的信息: git branch -v: 创建分支: git branch test 切换分支: git checkout test 创建并切换到新分支: git checkout -b iss53 合并分支,下例把 hotfix 分支并入 master 分支: git checkout master git merge hotfix 删除分支: git branch -d hotfix 查询合并时产生的冲突: git status 可视化的解决冲突的工具: git mergetool 要从该清单中筛选出你已经(或尚未)与当前分支合并的分支, 可以用 –merge 和 –no-merged 选项(Git 1....

February 11, 2017 · 3 min · Me

Mac Note

Install firefox 2017年 2月16日 星期四 21时48分05秒 CST wget -O FirefoxSetup.exe "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" For other operating systems replace 'os=win' with: Windows 64bit os=win64 OS X os=osx Linux x86_64 os=linux64 Linux i686 os=linux But it is very strange: MyMac:Downloads somebody$ wget -O FirefoxSetup.exe "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" --2017-02-16 21:54:48-- https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US Resolving download.mozilla.org... 54.149.16.117 Connecting to download.mozilla.org|54.149.16.117|:443... connected. HTTP request sent, awaiting response... 302 Found Location: http://download.cdn.mozilla.net/pub/firefox/releases/51.0.1/mac/en-US/Firefox%2051.0.1.dmg [following] --2017-02-16 21:54:50-- http://download.cdn.mozilla.net/pub/firefox/releases/51.0.1/mac/en-US/Firefox%2051.0.1.dmg Resolving download.cdn.mozilla.net... 23.2.16.56, 23.2.16.64, 2402:4f00:4001::df77:3293, ... Connecting to download....

February 10, 2017 · 2 min · Me

Vim Note

Use MacVim in Command line 2017年 2月16日 星期四 22时46分40秒 CST Add following in ./bash_profile: alias gvim='/Applications/MacVim.app/Contents/MacOS/Vim -g' Edit more than one file open file Out vim vim file1 file2 : open multiple files vim -o file1 file2 : open multiple files with horizontal windows vim -O file1 file2 : open multiple files with vertical windows in vim e file : open new file sp file : open new file in hroizontal window vsp file : open new file in vertical window close file :bd close current buffer...

February 10, 2017 · 2 min · Me