Log4j2打印具有自动装配的log4j包装器的类的名称

时间:2015-08-19 09:27:07

标签: java spring logging autowired log4j2

我正在使用Spring IOC和Logger的autowired bean,它是一个围绕logger的自定义包装器。

"{"FileUpload1":{"name":"image.jpg","type":"image\\/jpeg","tmp_name":"\\/tmp\\/phpwUhnu3","error":0,"size":347593}}
PHP Notice:  Undefined index: filename in /var/www/html/utilities/helpers.php on line 307"

它有一些包装代码,基本上用于格式化字符串,以及在枚举传递的情况下打印列的值。

 NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

    NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",TEST_BASE_URL,FILE_UPLOAD_URL];

    NSURL * url = [NSURL URLWithString:urlString];

    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url
                                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                          timeoutInterval:60.0];


    [urlRequest setHTTPMethod:@"POST"];

    NSString *boundary = @"---------------------------14737809831466499882746641449";
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
    [urlRequest setValue:contentType forHTTPHeaderField: @"Content-Type"];

    NSMutableData *body = [NSMutableData data];

    // Add __VIEWSTATE
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition: form-data; name=\"__VIEWSTATE\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"/wEPDwUKLTQwMjY2MDA0M2RkXtxyHItfb0ALigfUBOEHb/mYssynfUoTDJNZt/K8pDs=" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

    // add image data
    NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
    if (imageData) {
        [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[@"Content-Disposition: form-data; name=\"FileUpload1\"; filename=\"image.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:imageData];
        [body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    }

    [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

    [urlRequest setHTTPBody:body];
    NSURLSessionDataTask * dataTask =[defaultSession dataTa..........etc 

还有一些语句从Application类中记录,其中此Logger bean已为Ex ::

自动装配
    @Autowired
    private Loggers logger;

其中记录器指的是上述类。

这是log4j2.xml中的log4j模式布局我用来打印消息以及类名行号

       public class Loggers implements Serializable {

        private static final long serialVersionUID = 1L;

        public static Logger TRACE = LogManager.getLogger("com.mypackage.class");
        public static String msgXidFormat = " %s : %s : %s ";
        public static String msgFormat = " %s : %s ";

        public static Logger getLogger(Class clazz) {
            Logger logger = LogManager.getLogger(clazz);
            return logger;
        }

        public void info(String message) {
            TRACE.info(String.format(msgXidFormat,message);
        }
}

但我得到每个类的类名称为 Loggers ,其中我期望首次请求此日志语句的类。 有没有办法我可以通过不更改代码来处理这个问题,因为有很多类已经自动装配了。如果有人遇到过类似的情况或对此有所了解,请分享。

0 个答案:

没有答案