diff options
| author | Aravinda VK <avishwan@redhat.com> | 2017-06-21 12:56:14 +0530 | 
|---|---|---|
| committer | Amar Tumballi <amarts@redhat.com> | 2017-11-15 05:20:08 +0000 | 
| commit | 705ec055040268f876d04fe5743a6ce4738d6e02 (patch) | |
| tree | 47841519fd8415e31777418a94575cfae06b4bb8 /geo-replication/syncdaemon/logutils.py | |
| parent | da825da9501bcb51656e82cda3c21a2ef592c5e2 (diff) | |
geo-rep: Refactoring Config and Arguments parsing
- Fixed Python pep8 issues
- Removed dead code
- Rewritten configuration management
- Rewritten Arguments/subcommands handling
- Added Args upgrade to accommodate all these changes without changing
  glusterd code
- use of md5 removed, which was used to hash the brick path for workdir
Both Master and Slave nodes will have subdir for session in the
format "<mastervol>_<primary_slave_host>_<slavevol>
  $GLUSTER_LOGDIR/geo-replication/<mastervol>_<primary_slave_host>_<slavevol>
  $GLUSTER_LOGDIR/geo-replication-slaves/<mastervol>_<primary_slave_host>_<slavevol>
Log file paths renamed since session info is available with directory
name itself.
  $LOG_DIR_MASTER/
      - gsyncd.log - Gsyncd, Worker monitor logs
      - mnt-<brick-path>.log - Aux mount logs, mounted by each worker
      - changes-<brick-path>.log - Changelog related logs(One per brick)
  $LOG_DIR_SLAVE/
      - gsyncd.log - Slave Gsyncd logs
      - mnt-<master-node>-<master-brick-path>.log - Aux mount logs,
        mounted for each connection from master-node:master-brick
      - mnt-mbr-<master-node>-<master-brick-path>.log - Same as above,
        but mountbroker setup
Fixes: #73
Change-Id: I2ec2a21e4e2a92fd92899d026e8543725276f021
Signed-off-by: Aravinda VK <avishwan@redhat.com>
Diffstat (limited to 'geo-replication/syncdaemon/logutils.py')
| -rw-r--r-- | geo-replication/syncdaemon/logutils.py | 66 | 
1 files changed, 66 insertions, 0 deletions
diff --git a/geo-replication/syncdaemon/logutils.py b/geo-replication/syncdaemon/logutils.py new file mode 100644 index 00000000000..f00685cd92c --- /dev/null +++ b/geo-replication/syncdaemon/logutils.py @@ -0,0 +1,66 @@ +import logging +from logging import Logger, handlers +import sys +import time + + +class GLogger(Logger): + +    """Logger customizations for gsyncd. + +    It implements a log format similar to that of glusterfs. +    """ + +    def makeRecord(self, name, level, *a): +        rv = Logger.makeRecord(self, name, level, *a) +        rv.nsecs = (rv.created - int(rv.created)) * 1000000 +        fr = sys._getframe(4) +        callee = fr.f_locals.get('self') +        if callee: +            ctx = str(type(callee)).split("'")[1].split('.')[-1] +        else: +            ctx = '<top>' +        if not hasattr(rv, 'funcName'): +            rv.funcName = fr.f_code.co_name +        rv.lvlnam = logging.getLevelName(level)[0] +        rv.ctx = ctx +        return rv + + +LOGFMT = ("[%(asctime)s.%(nsecs)d] %(lvlnam)s [%(module)s{0}" +          ":%(lineno)s:%(funcName)s] %(ctx)s: %(message)s") + + +def setup_logging(level="INFO", label="", log_file=""): +    if label: +        label = "(" + label + ")" + +    filename = None +    stream = None +    if log_file: +        if log_file in ('-', '/dev/stderr'): +            stream = sys.stderr +        elif log_file == '/dev/stdout': +            stream = sys.stdout +        else: +            filename = log_file + +    datefmt = "%Y-%m-%d %H:%M:%S" +    fmt = LOGFMT.format(label) +    logging.root = GLogger("root", level) +    logging.setLoggerClass(GLogger) +    logging.Formatter.converter = time.gmtime  # Log in GMT/UTC time +    logging.getLogger().handlers = [] +    logging.getLogger().setLevel(level) + +    if filename is not None: +        logging_handler = handlers.WatchedFileHandler(filename) +        formatter = logging.Formatter(fmt=fmt, +                                      datefmt=datefmt) +        logging_handler.setFormatter(formatter) +        logging.getLogger().addHandler(logging_handler) +    else: +        logging.basicConfig(stream=stream, +                            format=fmt, +                            datefmt=datefmt, +                            level=level)  | 
