Skip to content

Commit

Permalink
account for non-sudo runs irt logger
Browse files Browse the repository at this point in the history
  • Loading branch information
chilcote committed Jun 22, 2019
1 parent 6308917 commit 26c7756
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions pkgroot/usr/local/vfuse/bin/vfuse
Original file line number Diff line number Diff line change
Expand Up @@ -1162,23 +1162,26 @@ def main():
status = "success"
message = args.template.split("/")[-1].replace(".json", "")

root_logger = logging.getLogger()
mylogger = logging.getLogger("vfuse_logger")
mylogger.setLevel(logging.INFO)
our_formatter = logging.Formatter(
fmt="%(asctime)s; %(message)s", datefmt="%Y-%m-%d %H:%M:%S %z"
)
# Set up file handler
file_handler = logging.FileHandler(logger_file)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(our_formatter)
mylogger.addHandler(file_handler)
root_logger.disabled = True
# Message must always match a certain structure
msg = "type: {}; action: {}; status: {}; msg: {};".format(
msg_type, action, status, message
)
mylogger.info(msg)
try:
root_logger = logging.getLogger()
mylogger = logging.getLogger("vfuse_logger")
mylogger.setLevel(logging.INFO)
our_formatter = logging.Formatter(
fmt="%(asctime)s; %(message)s", datefmt="%Y-%m-%d %H:%M:%S %z"
)
# Set up file handler
file_handler = logging.FileHandler(logger_file)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(our_formatter)
mylogger.addHandler(file_handler)
root_logger.disabled = True
# Message must always match a certain structure
msg = "type: {}; action: {}; status: {}; msg: {};".format(
msg_type, action, status, message
)
mylogger.info(msg)
except IOError:
print(colored("Use sudo to write to logger: %s" % logger_file, "yellow"))


if __name__ == "__main__":
Expand Down

0 comments on commit 26c7756

Please sign in to comment.