Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

终端log输出 #5

Open
dwdcth opened this issue Jan 7, 2015 · 2 comments
Open

终端log输出 #5

dwdcth opened this issue Jan 7, 2015 · 2 comments
Labels
Milestone

Comments

@dwdcth
Copy link

dwdcth commented Jan 7, 2015

希望提供终端log输出的功能。

@cheerayhuang
Copy link
Contributor

Hi,

src/framework/debug.lua 文件中,有这样几个函数:

if CCLuaLog then
    io.output():setvbuf('no')
elseif ngx and ngx.log then
    print = function(...)
        local arg = {...}
        for k,v in pairs(arg) do
            arg[k] = tostring(v)
        end
        ngx.log(ngx.ERR, table.concat(arg, "\t"))
    end
end

echo = print

function echoError(fmt, ...)
    echoLog("ERR", fmt, ...)
    print(debug.traceback("", 2))
end

function echoInfo(fmt, ...)
    echoLog("INFO", fmt, ...)
end

function echoLog(tag, fmt, ...)
    echo(string.format("[%s] %s", string.upper(tostring(tag)), string.format(tostring(fmt), ...)))
end

你可以使用它们输出你想要的内容,并且在安装后的的Quick Server路径下的 openresty/nginx/log/error.log里看到内容:)

@dualface dualface added this to the 0.5.1 milestone Mar 26, 2015
@dualface
Copy link
Owner

加入 FAQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants