Created
March 9, 2018 20:11
-
-
Save beall49/6d5c024290593856a73f17ddbfbd72b8 to your computer and use it in GitHub Desktop.
tail logs in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import call | |
from datetime import datetime | |
import os | |
class Logs: | |
LR_HOME = 'LIFERAY_HOME' | |
LR_DEFAULT = '/opt/home/{}/liferay-current/' | |
LOG_DIR = '{}logs/liferay.{}.log' | |
DT_FORMAT = '%Y-%m-%d' | |
TAIL = 'tail' | |
FOLLOW = '-f' | |
def __init__(self): | |
self.lr_directory = self.get_liferay_home() | |
self.log_date = self.get_log_date() | |
self.log_path = self.get_log_path() | |
def get_liferay_default(self): | |
return self.LR_DEFAULT.format(os.getlogin()) | |
def get_liferay_home(self): | |
return os.environ.get(self.LR_HOME, self.get_liferay_default()) | |
def get_log_date(self): | |
return datetime.strftime(datetime.utcnow(), self.DT_FORMAT) | |
def get_log_path(self): | |
return self.LOG_DIR.format(self.lr_directory, self.log_date) | |
def get_tail_cmd(self): | |
return [self.TAIL, self.FOLLOW, self.log_path] | |
if __name__ == '__main__': | |
logs = Logs() | |
cmd = logs.get_tail_cmd() | |
call(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment