protected function log($type, $msg)
    {
        $msg    = trim($msg);
        if ('' == $msg) {
            return false;
        }

        $filesystem = $this->filesystem;
        if (!$filesystem->isDirectory($this->dirPath)) {
            return false;
        }

        $type       = intval($type);
        $subPath    = sprintf("%s%s%s%s", date('Y'), DIRECTORY_SEPARATOR, date('m'), DIRECTORY_SEPARATOR);
        $file       = $this->dirPath . DIRECTORY_SEPARATOR . $subPath;
        switch($type) {
            case self::TYPE_DEBUG:
                $file   .= "debug";
                $str     = "[debug]";
                break;
            case self::TYPE_INFO:
                $file   .= "info";
                $str     = "[info]";
                break;
            case self::TYPE_NOTICE:
                $file   .= "notice";
                $str     = "[notice]";
                break;
            case self::TYPE_WARNING:
                $file   .= "warning";
                $str     = "[warning]";
                break;
            case self::TYPE_ERROR:
                $file   .= "error";
                $str     = "[error]";
                break;
            case self::TYPE_API:
                $file   .= "api";
                $str     = "[api]";
                break;
            case self::TYPE_DB:
                $file   .= "db";
                $str     = "[db]";
                break;
            // @codeCoverageIgnoreStart
            default:
                return false;
        }
        // @codeCoverageIgnoreEnd
        $file       .= '_' . date('Y_m_d');
        $target     = $file . '_' . date('His') . '.log';
        $file       .= '.log';

        // check log file size
        if ($filesystem->isFile($file) && ($filesystem->size($file) > self::MAX_FILE_SIZE)) {
            $filesystem->move($file, $target);
        }

        // Determine if log dir exists
        $dirPath    = $filesystem->dirName($file);
        if (!$filesystem->isDirectory($dirPath)) {
            $filesystem->makeDirectory($dirPath, 0755, true, true);
        }

        $str        .= date('Y-m-d H:i:s') . '|' . $msg . "\n";

        return $filesystem->append($file, $str) > 0;
    }