Skip to content

Commit

Permalink
version 0.2.1. updated to new action api scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Jul 8, 2013
1 parent 61370df commit 0b07cb2
Show file tree
Hide file tree
Showing 16 changed files with 3,123 additions and 306 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,35 @@
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject
8 changes: 5 additions & 3 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,9 @@
vim-wakatime 0.1.2 vim-wakatime 0.2.1
=========== ==================


Automatic time tracking for Vim. Automatic time tracking for Vim.



Installation Installation
------------ ------------


Expand All @@ -12,7 +13,7 @@ https://wakati.me


2) Run this shell command replacing KEY with your api key: 2) Run this shell command replacing KEY with your api key:


echo "api_key=KEY" >> ~/.wakatime echo "api_key=KEY" >> ~/.wakatime.conf


3) Using [Vundle](https://github.com/gmarik/vundle), the Vim plugin manager: 3) Using [Vundle](https://github.com/gmarik/vundle), the Vim plugin manager:


Expand All @@ -26,6 +27,7 @@ Then inside Vim, type `:BundleInstall` or run this shell command:


Visit https://wakati.me to view your time spent in each file. Visit https://wakati.me to view your time spent in each file.



Screen Shots Screen Shots
------------ ------------


Expand Down
Empty file.
85 changes: 85 additions & 0 deletions plugin/packages/wakatime/log.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,85 @@
# -*- coding: utf-8 -*-
"""
wakatime.log
~~~~~~~~~~~~
Provides the configured logger for writing JSON to the log file.
:copyright: (c) 2013 Alan Hamlett.
:license: BSD, see LICENSE for more details.
"""

import json
import logging
import os

try:
from collections import OrderedDict
except ImportError:
from .packages.ordereddict import OrderedDict


class CustomEncoder(json.JSONEncoder):

def default(self, obj):
return super(CustomEncoder, self).default(obj)


class JsonFormatter(logging.Formatter):

def __init__(self, timestamp, endtime, isWrite, targetFile, version,
plugin, datefmt=None):
self.timestamp = timestamp
self.endtime = endtime
self.isWrite = isWrite
self.targetFile = targetFile
self.version = version
self.plugin = plugin
super(JsonFormatter, self).__init__(datefmt=datefmt)

def format(self, record):
data = OrderedDict([
('now', self.formatTime(record, self.datefmt)),
('version', self.version),
('plugin', self.plugin),
('time', self.timestamp),
('endtime', self.endtime),
('isWrite', self.isWrite),
('file', self.targetFile),
('level', record.levelname),
('message', record.msg),
])
if not self.endtime:
del data['endtime']
if not self.plugin:
del data['plugin']
if not self.isWrite:
del data['isWrite']
return CustomEncoder().encode(data)

def formatException(self, exc_info):
return exec_info[2].format_exc()


def setup_logging(args, version):
logfile = args.logfile
if not logfile:
logfile = '~/.wakatime.log'
handler = logging.FileHandler(os.path.expanduser(logfile))
formatter = JsonFormatter(
timestamp=args.timestamp,
endtime=args.endtime,
isWrite=args.isWrite,
targetFile=args.targetFile,
version=version,
plugin=args.plugin,
datefmt='%Y-%m-%dT%H:%M:%SZ',
)
handler.setFormatter(formatter)
logger = logging.getLogger()
logger.addHandler(handler)
level = logging.INFO
if args.verbose:
level = logging.DEBUG
logger.setLevel(level)
return logger
Empty file.
Loading

0 comments on commit 0b07cb2

Please sign in to comment.