私はpython-watchdog
を使用して、追加、削除、変更などの変更の特定のパスを監視しています。時間とメッセージの情報とともに、その変更を行ったユーザーのユーザー名を取得します。私はgetpass
を見ていて、ロギングの中で変数を探し回っていましたが、何も見つけられませんでした。PythonのロギングライブラリでOSユーザーのユーザー名を取得する方法は?
手がかりはありますか?マイウォッチドッグ・コードは、私は以下のようなものを私の問題を解決することができました
print 'starting the watcher mate...'
create_log_file()
logging.basicConfig(filename = log_file, level = logging.INFO, format = '%(asctime)s - %(message)s', datefmt = '%Y-%m-%d %H:%M:%S')
path = sys.argv[1] if len(sys.argv) > 1 else '/etc/nginx/'
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
これは役立つかもしれない:http://stackoverflow.com/questions/842059/is-there-a-portable-way-to-get-the-current-username-in-python –