atmxk123 2018-12-21 12:01 采纳率: 0%
浏览 579

java问题一个系统的操作日志怎么推送给另一个系统,有什么设计思路吗

我有一个系统,要将本系统的操作日志推送给别人的系统,这个对接有什么设计思路吗?我的想法是生成一个文件让对方读取,但是日志推送是用线程定时读的,还有更正的地方或者实现思路吗?请大佬帮我解答一下,十分感激.现在输出是写死的 需要输出到别的系统

public class NoticesThread extends Thread
{
private String sql = " select t.id, "+
         "       t.content, "+
         "       t.log_type, "+
         "       u.name     as userName, "+
         "       d.name     as departName "+
         " from ry_gis_opr_log t "+
         " left join cfg_user u "+
         "   on t.operator_fk = u.id "+
         " left join ry_gis_department d "+
         "   on t.belongto_fk = d.id "+
         " where t.log_type = '上传' "+
         "  and t.is_fail != 1 " +
         "  and t.belongto_fk != 0" +
         "  and t.id > ? " +
         " order by t.id desc ";

 boolean isStart = true;
 Long startLogId = 0l;
public void run() {
  Properties prop = new Properties();
  try {
    InputStream in = new     NoticesThread().getClass().getResourceAsStream("/config/jdbc.properties");
    prop.load(in);
} catch (IOException e) {
    e.printStackTrace();
}
final String driverName = prop.getProperty("jdbc.driverClassName");
final String url = prop.getProperty("jdbc.url");
final String oracleUser = prop.getProperty("jdbc.username");
final String password = prop.getProperty("jdbc.password");
Timer timer = new Timer();
timer.schedule(new TimerTask() {
    @Override
    public void run() {
        Connection conn = null;
        PreparedStatement st = null;
        try {
            Class.forName(driverName);
            conn = DriverManager.getConnection(url, oracleUser, password);
            st = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);  
            st.setLong(1, startLogId);
            ResultSet rs = st.executeQuery();
            if(!isStart){
                if(rs.first()) {
                    startLogId = rs.getLong(1);
                    String content = rs.getString(2);
                    String userName = rs.getString(4);
                    String departName = rs.getString(5);
                    System.out.println("---logId:" + startLogId + "---content:"+content +"----userName:" + userName +"---departName:" + departName);
                }
                while(rs.next()){
                    Long logId = rs.getLong(1);
                    String content = rs.getString(2);
                    String userName = rs.getString(4);
                    String departName = rs.getString(5);
                    System.out.println("---logId:" + logId + "---content:"+content +"----userName:" + userName +"---departName:" + departName);
                }
            } else {
                isStart = false;
                if(rs.first()) {
                    startLogId = rs.getLong(1);
                }
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if(conn != null) {
                    conn.close();
                }
                if(st != null) {
                    st.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}, 0, 5000);

}
}

  • 写回答

3条回答

  • 爱码少年 2018-12-21 04:34
    关注

    日志可以邮件发送,可以写入数据库,都有相应实现,不用自己写代码,配置一下就ok,不冲突,而且可以多个日志输出终点

    评论

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题