from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer


# Log to Sandbox logs channel
#
def __ws_log(message):
    channel_layer = get_channel_layer()
    async_to_sync(channel_layer.group_send)(
        'sandbox-logs',
        {
            'type': 'send_message',
            'message': message
        }
    )


def ws_log_message(text):
    __ws_log(
        {'text': text,
         'is_error': False}
    )


def ws_log_error(text):
    __ws_log(
        {'text': text,
         'is_error': True}
    )
