|
|
Строка 2: |
Строка 2: |
| === 2020-10 === | | === 2020-10 === |
| | | |
| + | * 2020-10-29, 00:10:17: [https://pypi.org/project/pygtail/ pygtail · PyPI] |
| + | *: <html><span class="kn">from</span> <span class="nn">pygtail</span> <span class="kn">import</span> <span class="n">Pygtail</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">Pygtail</span><span class="p">(</span><span class="s2">"some.log"</span><span class="p">):</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span></html> |
| + | <!-- NEXT BOOKMARK --> |
| * 2020-10-29, 00:09:15: [https://stackoverflow.com/questions/36327265/python-parse-log-file-in-realtime-reload-when-the-log-rotates Python Parse log file in realtime, reload when the log rotates - Stack Overflow] | | * 2020-10-29, 00:09:15: [https://stackoverflow.com/questions/36327265/python-parse-log-file-in-realtime-reload-when-the-log-rotates Python Parse log file in realtime, reload when the log rotates - Stack Overflow] |
| *: <html><span class="hljs-keyword">import</span> os file_path = <span class="hljs-string">'/var/log/app/access.log'</span> <span class="hljs-keyword">with</span> open(file_path) <span class="hljs-keyword">as</span> f: file_size = <span class="hljs-number">0</span> <span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>: line = f.readline() <span class="hljs-keyword">if</span> line: <span class="hljs-keyword">print</span> line file_status_obj = os.stat(file_path) <span class="hljs-keyword">if</span> file_size < file_status_obj.st_size: f.seek(<span class="hljs-number">0</span>) file_size = file_status_obj.st_size </html> | | *: <html><span class="hljs-keyword">import</span> os file_path = <span class="hljs-string">'/var/log/app/access.log'</span> <span class="hljs-keyword">with</span> open(file_path) <span class="hljs-keyword">as</span> f: file_size = <span class="hljs-number">0</span> <span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>: line = f.readline() <span class="hljs-keyword">if</span> line: <span class="hljs-keyword">print</span> line file_status_obj = os.stat(file_path) <span class="hljs-keyword">if</span> file_size < file_status_obj.st_size: f.seek(<span class="hljs-number">0</span>) file_size = file_status_obj.st_size </html> |