未解决logback问题:rollingPolicy报错

Posted 针胖胖

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了未解决logback问题:rollingPolicy报错相关的知识,希望对你有一定的参考价值。

/*solution

target/classes/下面并没有照片
图片路径缺失



*/
package com.imooc.o2o.util;

import java.io.File;

import java.io.IOException;

//import java.util.ArrayList;

import java.util.List;

import javax.imageio.ImageIO;

import net.coobird.thumbnailator.Thumbnails;

import net.coobird.thumbnailator.geometry.Positions;

//import org.springframework.web.multipart.commons.CommonsMultipartFile;

public class ImageUtil {

public static void main(String[] args) throws IOException {

//从线程逆推到线加载器,获取绝对值路径

String basePath= Thread.currentThread().getContextClassLoader().getResource("").getPath();

//basePath=URLDecoder.decode(basePath,"utf-8");

//of可以直接传入文件目标是在test01上加上src/main/resource的watermark

//ImageIO.read获取图片流

//0.5f指的是透明度

//outputQuality是压缩图片0.8f压缩成80%

//toFile指的是输出的位置

Thumbnails.of(new File("/Users/lenovo/Desktop/backgroud/test01.jpg"))

.size(100, 100).watermark(Positions.BOTTOM_RIGHT, 

ImageIO.read(new File(basePath+"/watermark01.png")),0.25f).outputQuality(0.8f)

.toFile("/Users/lenovo/Desktop/backgroud/test01new.jpg");

}

}

/*

import java.io.File;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import net.coobird.thumbnailator.Thumbnails;

import org.springframework.web.multipart.commons.CommonsMultipartFile;

public class ImageUtil {

public static String generateThumbnail(CommonsMultipartFile thumbnail, String targetAddr) {

String realFileName = FileUtil.getRandomFileName();

String extension = getFileExtension(thumbnail);

makeDirPath(targetAddr);

String relativeAddr = targetAddr + realFileName + extension;

File dest = new File(FileUtil.getImgBasePath() + relativeAddr);

try {

Thumbnails.of(thumbnail.getInputStream()).size(200, 200).outputQuality(0.25f).toFile(dest);

} catch (IOException e) {

throw new RuntimeException("创建缩略图失败:" + e.toString());

}

return relativeAddr;

}

public static String generateNormalImg(CommonsMultipartFile thumbnail, String targetAddr) {

String realFileName = FileUtil.getRandomFileName();

String extension = getFileExtension(thumbnail);

makeDirPath(targetAddr);

String relativeAddr = targetAddr + realFileName + extension;

File dest = new File(FileUtil.getImgBasePath() + relativeAddr);

try {

Thumbnails.of(thumbnail.getInputStream()).size(337, 640).outputQuality(0.5f).toFile(dest);

} catch (IOException e) {

throw new RuntimeException("创建缩略图失败:" + e.toString());

}

return relativeAddr;

}

public static List<String> generateNormalImgs(List<CommonsMultipartFile> imgs, String targetAddr) {

int count = 0;

List<String> relativeAddrList = new ArrayList<String>();

if (imgs != null && imgs.size() > 0) {

makeDirPath(targetAddr);

for (CommonsMultipartFile img : imgs) {

String realFileName = FileUtil.getRandomFileName();

String extension = getFileExtension(img);

String relativeAddr = targetAddr + realFileName + count + extension;

File dest = new File(FileUtil.getImgBasePath() + relativeAddr);

count++;

try {

Thumbnails.of(img.getInputStream()).size(600, 300).outputQuality(0.5f).toFile(dest);

} catch (IOException e) {

throw new RuntimeException("创建图片失败:" + e.toString());

}

relativeAddrList.add(relativeAddr);

}

}

return relativeAddrList;

}

private static void makeDirPath(String targetAddr) {

String realFileParentPath = FileUtil.getImgBasePath() + targetAddr;

File dirPath = new File(realFileParentPath);

if (!dirPath.exists()) {

dirPath.mkdirs();

}

}

private static String getFileExtension(CommonsMultipartFile cFile) {

String originalFileName = cFile.getOriginalFilename();

return originalFileName.substring(originalFileName.lastIndexOf("."));

}

}

}

}*/ 



以上是关于未解决logback问题:rollingPolicy报错的主要内容,如果未能解决你的问题,请参考以下文章

未设置 logback logstash 编码器 Syslog 标头

logback如何按线程打印日志

Logback日志输出问号的问题解决方案

如何在 logback-spring.xml 中包含自定义 xml?

LogBack 日志压缩产生上百G的tmp文件问题 logback同时按照日期和大小分割日志

一文详细了解logback之日志打印FileAppender