Read data directly from /dev/log Unix Domain Socket

后端 未结 1 1789
误落风尘
误落风尘 2021-01-26 02:34

My project aims at reading log messages directly from /dev/log UNIX domain socket in Java. Currently I am using junixsocket. Below is a sample code of client that r

相关标签:
1条回答
  • 2021-01-26 03:28

    Since you cannot connect to an existing server socket as mentioned in the log traces, then you haven't bound one one the mentioned file, so try creating an AF_UNIX server socket then connect to it.

    It could be done in a separate class:

    public class DevLogServer {
    
      public static void main(String[] args) throws IOException {
    
        final File socketFile = new File("/dev/log");
        AFUNIXServerSocket server = AFUNIXServerSocket.newInstance();
        try {
          server.bind(new AFUNIXSocketAddress(socketFile));
        } catch (Exception e) {
          throw e;
        }
    
      }
    
    }
    

    Edit as per @Ankit comment:

    You may also need to make sure the syslod daemon is stopped by runnig below command in a terminal window:

    sudo service syslog stop
    

    You may alternatively need to grand write permission to the /dev directory.

    0 讨论(0)
提交回复
热议问题