"""
GILGAMESH
Copyright (C) 2019  Contributors as noted in the AUTHORS file

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import os
import logging

import zmq
from zmq.log.handlers import PUBHandler

class GLog(object):
    """
        logging to resource manager
        TODO: write doc
    """
    def __init__(self, *args, **kwargs):

        self.LOG_DEST   = "ipc:///tmp/logger"

        self.glog = logging.getLogger(str(os.getpid()))
        if kwargs['verbose']:
            self.glog.setLevel(logging.DEBUG)
        else:
            self.glog.setLevel(logging.INFO)

        pub = self.context.socket(zmq.PUB)
        pub.connect(self.LOG_DEST)
        handler = PUBHandler(pub)
        #handler.root_topic = self.name

        self.glog.addHandler(handler)

        #self.glog.debug("Starting glog at {0}.".format(os.getpid()))
