public static function log($level, $message, $context = [])
    {
        // Throw out debug messages if we are not in debug mode
        if (($level == 'debug') && (Config::get('app.debug') != true)) {
            return;
        }

        // Fetch the currently logged in user
        $username = ApplogHelper::currentUserName();

        // Get the list of client IP addresses
        $clientIp = ApplogHelper::getClientIps();

        // Split the log message to see how it is formatted.
        $logdata = explode(':', $message, 6);
        if (count($logdata) == 6) {
            list($classname, $traitname, $filename, $linenumber, $functionname, $message) = $logdata;
        } else {
            list($classname, $traitname, $filename, $linenumber, $functionname, $message) =
                ['', '', '', '', '', $message];
        }

        // Store the log entry.
        try {
            $error = static::create([
                'type'          => $level,
                // 'modelname'    => get_class($target),
                // 'foreign_id'   => $target->id,
                'classname'     => $classname,
                'traitname'     => $traitname,
                'filename'      => $filename,
                'linenumber'    => $linenumber,
                'functionname'  => $functionname,
                'message'       => $message,
                'details'       => json_encode($context),
                'ipaddr'        => $clientIp,
                'created_by'    => $username,
                'updated_by'    => $username,
            ]);

            // Send an email out for error messages -- example code below.
            /*
            if ($level == 'error') {
                MandrillMailerRepository::sendError(env('MAIL_TO_ADDRESS'), env('MAIL_TO_NAME'), $error);
            }
            */
        } catch (\Exception $e) {
            // Do nothing if the log fails -- possibly fatal database error
        }
    }