✨ 日志文件存储.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.orion.ops.framework.common.file;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 文件客户端
|
||||
@@ -65,8 +66,6 @@ public interface FileClient {
|
||||
*/
|
||||
String upload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) throws Exception;
|
||||
|
||||
// TODO getOutputStream
|
||||
|
||||
/**
|
||||
* 检查文件是否存在
|
||||
*
|
||||
@@ -102,4 +101,23 @@ public interface FileClient {
|
||||
*/
|
||||
InputStream getContentInputStream(String path) throws Exception;
|
||||
|
||||
/**
|
||||
* 获取文件输出流
|
||||
*
|
||||
* @param path path
|
||||
* @return stream
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
OutputStream getContentOutputStream(String path) throws Exception;
|
||||
|
||||
/**
|
||||
* 获取文件输出流
|
||||
*
|
||||
* @param path path
|
||||
* @param append append
|
||||
* @return stream
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
OutputStream getContentOutputStream(String path, boolean append) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.orion.lang.utils.Exceptions;
|
||||
import com.orion.ops.framework.common.file.FileClient;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 文件客户端工具
|
||||
@@ -85,8 +86,6 @@ public class FileClientUtils {
|
||||
return delegate.upload(path, in, autoClose, overrideIfExist);
|
||||
}
|
||||
|
||||
// TODO getOutputStream
|
||||
|
||||
/**
|
||||
* 检查文件是否存在
|
||||
*
|
||||
@@ -130,6 +129,29 @@ public class FileClientUtils {
|
||||
return delegate.getContentInputStream(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件输出流
|
||||
*
|
||||
* @param path path
|
||||
* @return stream
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
public static OutputStream getContentOutputStream(String path) throws Exception {
|
||||
return delegate.getContentOutputStream(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件输出流
|
||||
*
|
||||
* @param path path
|
||||
* @param append append
|
||||
* @return stream
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
public static OutputStream getContentOutputStream(String path, boolean append) throws Exception {
|
||||
return delegate.getContentOutputStream(path, append);
|
||||
}
|
||||
|
||||
public static void setDelegate(FileClient delegate) {
|
||||
if (FileClientUtils.delegate != null) {
|
||||
// unmodified
|
||||
|
||||
@@ -48,4 +48,13 @@ public class OrionStorageAutoConfiguration {
|
||||
return new LocalFileClient(config.getLocal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 日志文件客户端
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "orion.storage.logs.enabled", havingValue = "true")
|
||||
public FileClient logsFileClient() {
|
||||
return new LocalFileClient(config.getLogs());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,4 +20,9 @@ public class StorageConfig {
|
||||
*/
|
||||
private LocalFileClientConfig local;
|
||||
|
||||
/**
|
||||
* 日志文件客户端 配置
|
||||
*/
|
||||
private LocalFileClientConfig logs;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.orion.ops.framework.common.file.FileClient;
|
||||
import com.orion.ops.framework.common.utils.FileClientUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -57,14 +58,14 @@ public abstract class AbstractFileClient<Config extends FileClientConfig> implem
|
||||
|
||||
@Override
|
||||
public byte[] getContent(String path) throws Exception {
|
||||
try (InputStream in = this.doDownload(path)) {
|
||||
try (InputStream in = this.getContentInputStream(path)) {
|
||||
return Streams.toByteArray(in);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getContentInputStream(String path) throws Exception {
|
||||
return this.doDownload(path);
|
||||
public OutputStream getContentOutputStream(String path) throws Exception {
|
||||
return this.getContentOutputStream(path, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,15 +80,6 @@ public abstract class AbstractFileClient<Config extends FileClientConfig> implem
|
||||
*/
|
||||
protected abstract String doUpload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) throws Exception;
|
||||
|
||||
/**
|
||||
* 执行下载操作
|
||||
*
|
||||
* @param path path
|
||||
* @return stream
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
protected abstract InputStream doDownload(String path) throws Exception;
|
||||
|
||||
/**
|
||||
* 获取返回路径 用于客户端返回
|
||||
*
|
||||
|
||||
@@ -31,11 +31,15 @@ public class FileClientConfig {
|
||||
/**
|
||||
* 是否拼接时间作为文件夹
|
||||
*/
|
||||
protected boolean dateDirectory = true;
|
||||
protected boolean dateDirectory;
|
||||
|
||||
/**
|
||||
* 时间文件夹格式
|
||||
*/
|
||||
protected String datePattern = Dates.YMD;
|
||||
protected String datePattern;
|
||||
|
||||
public FileClientConfig() {
|
||||
this.datePattern = Dates.YMD;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.orion.lang.utils.Exceptions;
|
||||
import com.orion.ops.framework.common.file.FileClient;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 默认文件客户端
|
||||
@@ -61,6 +62,16 @@ public class PrimaryFileClient implements FileClient {
|
||||
return delegate.getContentInputStream(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getContentOutputStream(String path) throws Exception {
|
||||
return delegate.getContentOutputStream(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getContentOutputStream(String path, boolean append) throws Exception {
|
||||
return delegate.getContentOutputStream(path, append);
|
||||
}
|
||||
|
||||
public static void setDelegate(FileClient delegate) {
|
||||
if (PrimaryFileClient.delegate != null) {
|
||||
// unmodified
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.storage.core.client.AbstractFileClient;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 本地文件客户端
|
||||
@@ -20,6 +21,16 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
||||
super(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getContentInputStream(String path) throws Exception {
|
||||
return Files1.openInputStreamFast(this.getAbsolutePath(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getContentOutputStream(String path, boolean append) throws Exception {
|
||||
return Files1.openOutputStreamFast(this.getAbsolutePath(path), append);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doUpload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) {
|
||||
// 获取返回文件路径
|
||||
@@ -35,11 +46,6 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
||||
return returnPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream doDownload(String path) throws Exception {
|
||||
return Files1.openInputStreamFast(this.getAbsolutePath(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExists(String path) {
|
||||
return Files1.isFile(this.getAbsolutePath(path));
|
||||
|
||||
@@ -20,13 +20,18 @@ public class LocalFileClientConfig extends FileClientConfig {
|
||||
* <p>
|
||||
* 无需 / 结尾
|
||||
*/
|
||||
private String storagePath = "";
|
||||
private String storagePath;
|
||||
|
||||
/**
|
||||
* 基础路径
|
||||
* <p>
|
||||
* 无需 / 结尾
|
||||
*/
|
||||
private String basePath = "";
|
||||
private String basePath;
|
||||
|
||||
public LocalFileClientConfig() {
|
||||
this.storagePath = "";
|
||||
this.basePath = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
"name": "orion.storage.local",
|
||||
"type": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig",
|
||||
"sourceType": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig"
|
||||
},
|
||||
{
|
||||
"name": "orion.storage.logs",
|
||||
"type": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig",
|
||||
"sourceType": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig"
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
@@ -34,7 +39,7 @@
|
||||
"name": "orion.storage.local.date-directory",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "是否拼接时间作为文件夹.",
|
||||
"defaultValue": true
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "orion.storage.local.date-pattern",
|
||||
@@ -51,6 +56,40 @@
|
||||
"name": "orion.storage.local.base-path",
|
||||
"type": "java.lang.String",
|
||||
"description": "基础路径."
|
||||
},
|
||||
{
|
||||
"name": "orion.storage.logs.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "是否启用.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "orion.storage.logs.timestamp-prefix",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "是否使用时间戳作为文件名称前缀.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "orion.storage.logs.date-directory",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "是否拼接时间作为文件夹.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "orion.storage.logs.date-pattern",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "时间文件夹格式.",
|
||||
"defaultValue": "yyyy-MM-dd"
|
||||
},
|
||||
{
|
||||
"name": "orion.storage.logs.storage-path",
|
||||
"type": "java.lang.String",
|
||||
"description": "存储路径."
|
||||
},
|
||||
{
|
||||
"name": "orion.storage.logs.base-path",
|
||||
"type": "java.lang.String",
|
||||
"description": "基础路径."
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user