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

VS2005下日志路径不支持中文 #8

Closed
MoSights opened this issue May 20, 2013 · 5 comments
Closed

VS2005下日志路径不支持中文 #8

MoSights opened this issue May 20, 2013 · 5 comments

Comments

@MoSights
Copy link

bool OpenLogger(LoggerId id)
{
...
setlocale(LC_ALL, "");
pLogger->_handle.open(path.c_str(), std::ios::app|std::ios::out|std::ios::binary); // std::fstream 在VS2005下打开中文路径的文件会出问题
setlocale(LC_ALL, "C");//还原
...
}
这是我目前的解决方法

@zsummer
Copy link
Owner

zsummer commented May 20, 2013

hi~ MoSights :
非常感谢您对log4z的关注与支持.

中文日志路径只在VS2005下才会出现 而setlocale是一个全局的调用
log4z本身工作在独立的一个线程下 因此此更改可能会影响到加载log4z的项目.

另外还有一个可能存在的候选方案是使用C的fopen接口 但还没有做过测试进行验证 ^ ^

如果这个方案可行的话 在稍后的版本中会对此问题进行解决.

再次感谢!
------ zsummer .

@zsummer
Copy link
Owner

zsummer commented May 20, 2013

简单的写了个测试验证了fopen不存在[中文路径/带空格路径]不能识别的问题

查了下vs2005对中文路径支持的相关资料 如下所说:
2005中为了让std::wfstream的路径支持wchar_t,所有底层函数的路径都是转换成wchar_t来进行操作的
而这个转换是通过C库的wcstombos来进行转换的。 而wcstombos则根据当前全局的locale设置进行具体的转换
当全局的locale设置并不是wcstombos所要转换的文字的代码页时 BUG就出现了

so . C 的fopen接口可以避免

@zsummer
Copy link
Owner

zsummer commented May 29, 2013

新版本中已支持 谢谢提供建议.

@zsummer zsummer closed this as completed May 29, 2013
@MoSights
Copy link
Author

MoSights commented Jun 1, 2013

测试了下新版本,好像有问题,默认的主log的路径不能自定义的,也就是我设置了自定义路径,发现有两个log文件夹,一个是默认位置的log,一个是自定义的log

2013/5/29 zhangyawei notifications@github.com

新版本中已支持 谢谢提供建议.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-18592772
.

@asummersday
Copy link
Contributor

主LOGGER的name是Main, 可通过配置文件增加[Main]段配置 或者在程序中调用CreateLogger("Main",....) 来进行定制, 参见advance例子.

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

No branches or pull requests

3 participants