[翻译]Log Everything All the Time

本文探讨了在大型分布式系统中,传统的错误/警告/信息记录方式存在的局限性,并提出了一种全新的日志记录方法,旨在通过记录所有相关信息来辅助问题诊断。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言:

本文翻译来自 Log Everything All the Time,其中个人省略了少量内容,如果有需要,请阅读原文。本文来自 博客园 逖靖寒 http://gpcuster.cnblogs.com

 

译文:

本次的JoelOnSoftware 问答活动中,提到了一个古老的问题,什么是log以及如何去log。平常的trace/error/warning/info方式在大型的分布式系统中不是非常有用。你需要将所有的信息都记录下来才能解决遇到的问题。

为了解释为什么常用的log方式不好用,可以想象这样一种情形:你的网站运行了好几周时间都没有问题,可是突然有1天,凌晨2点的时候出现了一个问题,用户有时无法提交评论,这个现象时断时续。你现在需要去修复这个问题。

那么,我们如何去找到这个问题并修复它呢?监控系统并没有任何异常的现象,你自己提交一个评论去测试,运行正常,没有问题。看来这个问题不是那么好解决的,因为提交一个评论涉及了许多的东西,比如说:负载平衡系统,垃圾过滤,web服务器,数据库服务器,缓存服务器,文件服务器,还有交换机和路由器等等,究竟是什么地方出问题了呢?

这个时候,你所拥有的只有log。你不能关闭你的系统因为用户正在使用它,你不能更新部署一个新的系统因为你没有环境去测试新的系统是否会进入新的问题,添加debugger也无法解决这个问题。

你需要做的事情就是查看这些log,看看会其中记录了什么信息。你不需要函数或是方法的信息,你需要知道系统中所有有意思的事情发生的记录,知道这个叫“func1”的函数被调用没有任何帮助。你需要知道什么参数被传递给了函数,函数的返回值是什么。

所以,这里没有log的级别之分。你需要记录所有的信息来帮助你在将来遇到问题的时候解决问题。你真正需要的是一个时光机,虽然这是不现实的,但是主要我们的log足够详细,那么就可以认为我们拥有一个时光机。他将帮助你了解到期间发生的所有事情:是不是一个接口丢失了一个包数据,是不是相应超时了,是不是互斥锁没有正确使用?等等。

绝大多数系统都是慢慢发展到去记录所有的东西的。它们开始的时候只记录一点点信息甚至什么都不记录。当发生问题以后,它们会增加记录的内容。但是log通常没有很好的分类与整理,这将导致不好的问题覆盖率和降低程序的性能。

程序反常一般通过log来查找,反常就是一些没有预料到的东西,比如说操作,处理顺序,计算时间过长等等。不过这些反常的现象也有好处,它会告诉你如何让自己的程序更加健壮,让你知道如何在真实的环境中去处理相关的问题。

所以,好好想一下你需要调试哪些问题。不要害怕去添加log帮助你了解系统真正是如何工作的。

比如说,给每一个请求需要分配一个全局唯一的ID,这样你就区分不同请求的相关信息了,帮助你提供调试的效率和准确性。

通常log有2个等级:系统级别和开发级别。

系统级别的log会记录所有你需要去调试系统的日志,它将一直存在,不会被关闭。

开发级别的日志将添加更加详细的信息,并且可以以模块为单位开启或者是关闭。

我通常会用一个配置文件,里面定义了默认的输出级别。不过我让每一个进程通过相应的接口改变自己的输出级别。这样在开发的时候就会非常的方便。

我时常听到这样的言论:记录所有的信息效率非常低,会产生过多的数据。我不这么认为。我参加过一些项目,其中有的是实时的嵌入式系统,他们都会记录下所有的信息,甚至是驱动程序,他们都是这么做的。

下面有一些与log相关的技巧(感觉原文说得更加到位,就不翻译了):

  • Make logging efficient from the start so you aren't afraid to use it.
  • Create a dead simple to use log library that makes logging trivial for developers. Document it. Provide example code. Check for it during code reviews.
  • Log to a separate task and let the task push out log data when it can.
  • Use a preallocated buffer pool for log messages so memory allocation is just pop and push.
  • Log integer values for very time sensitive code.
  • For less time sensitive code sprintf'ing into a preallocated buffer is usually quite fast. When it's not you can use reference counted data structures and do the formatting in the logging thread.
  • Triggering a log message should take exactly one table lookup. Then the performance hit is minimal.
  • Don't do any formatting before it is determined the log is needed. This removes constant overhead for each log message.
  • Allow fancy stream based formatting so developers feel free to dump all the data they wish in any format they wish.
  • In an ISR context do not take locks or you'll introduce unbounded variable latency into the system.
  • Directly format data into fixed size buffers in the log message. This way there is no unavoidable overhead.
  • Make the log message directly queueable to the log task so queuing doesn't take more memory allocations. Memory allocation is a primary source of arbitrary latency and dead lock because of the locking. Avoid memory allocation in the log path.
  • Make the logging thread a lower priority so it won't starve the main application thread.
  • Store log messages in a circular queue to limit resource usage.
  • Write log messages to disk in big sequential blocks for efficiency.
  • Every object in your system should be dumpable to a log message. This makes logging trivial for developers.
  • Tie your logging system into your monitoring system so all the logging data from every process on every host winds its way to your centralized monitoring system. At the same time you can send all your SLA related metrics and other stats. This can all be collected in the back ground so it doesn't impact performance.
  • Add meta data throughout the request handling process that makes it easy to diagnose problems and alert on future potential problems.
  • Map software components to subsystems that are individually controllable, cross application trace levels aren't useful.
  • Add a command ports to processes that make it easy to set program behaviors at run-time and view important statistics and logging information.
  • Log information like task switch counts and times, queue depths and high and low watermarks, free memory, drop counts, mutex wait times, CPU usage, disk and network IO, and anything else that may give a full picture of how your software is behaving in the real world.
  • log的数据是你调试绝大多数大型分布式系统的根据。

    所以,从现在开始,记录所有的日志,当开始提到的那个凌晨2点钟的问题再次发生时,你就知道如何应对,修改问题了:)

     

    本文来自 博客园 逖靖寒 http://gpcuster.cnblogs.com

#SceneScript Reference SceneScript is follows the ECMAScript 2018 specification, so you can utilize all functionalities from ECMAScript that you would also find in similar languages such as JavaScript. This is very useful as you can make use of various helpful classes. For example, allows you to access the current date and time, allows you to access various mathematical utility functions.DateMath This page only covers all additions that SceneScript adds to make working with wallpapers possible. #Globals SceneScript introduces a handful of globals which you can access at any point in your code. Global Description engine Access to general features of the application. class.IEngine input Input related data, mainly the mouse cursor. class.IInput thisScene The currently loaded scene wallpaper. classIScene thisLayer The layer this script has been loaded on. class.ILayer thisObject The object this script belongs to. class.IThisPropertyObject console Access the console log for debugging purposes. class.IConsole shared Empty by default, allows you to share data between multiple scripts. class.Shared #Events SceneScript uses an event system that allows you to run specific code whenever certain events take place. Most notably, the event is most commonly used to execute SceneScript code at every frame that Wallpaper Engine calculates. The event is good for running code once when the wallpaper is first loaded and the event allows you to react to changes to user properties of your wallpaper. Additionally, there are a handful of events which related to mouse movement and mouse input which you can incorporate into your wallpaper.updateinitapplyUserPropertiescursor Event Description init This initialization function will be called once after the object it belongs to has been created. update This event function will be called every frame for all scripts that export it. destroy This event function will be called just before the object it belongs to gets destroyed. resizeScreen This function will be called every time the wallpaper resizes because of a change to the current resolution. applyUserProperties This event function will be called once initially when the wallpaper is loaded and whenever any user properties are being adjusted by the user. cursorEnter This event function will be called when the cursor enters the bounds of the object. cursorLeave This event function will be called when the cursor leaves the bounds of the object. cursorMove This event function will be called when the cursor has been moved. cursorDown This event function will be called when the cursor is being pressed down on an object. cursorUp This event function will be called when the cursor is being released over an object. cursorClick This event function will be called when the cursor has been pressed and released on the same object. mediaStatusChanged This event function will be called when the media integration is turned on or off by the user. mediaPlaybackChanged This event function will be called when the users starts, stops or pauses media. mediaPropertiesChanged This event function will be called when the properties of the currently playing media change. mediaThumbnailChanged This event function will be called when the thumbnail of the currently playing media changes. mediaTimelineChanged This event function will be called when the current time of the playing media changes and is only provided by certain applications. #Classes All components of Wallpaper Engine are provided with a fitting class so that you can access everything programmatically. The following list contains all relevant classes introduced by SceneScript: Class Description AnimationEvent This object describes an animation event that has been fired from a timeline or puppet warp animation. AudioBuffers Provides access to the left and right audio spectrum values and their combined average for audio visualization purposes. CameraTransforms Objects of this class describe the camera orientation and position. CursorEvent Provides information about the cursor position during cursor events. IAnimation This class represents a timeline property animation. IAnimationLayer This class represents a puppet warp or 3D model animation layer. IConsole You can access this interface anywhere in your SceneScript code through the global object to interact with the console log.console IEffect Provides access to image effects used on image layers. IEffectLayer Base class for image and text layers. IEngine Provides general information about the user device and the running wallpaper. IImageLayer This class provides access to functions specific to image layers. ITextLayer This class provides access to functions specific to text layers. IModelLayer This class provides access to functions specific to 3D model layers. IInput Provides access to input related data, mainly the mouse cursor. ILayer Provides access to data related to a layer. ILocalStorage Provides access to the local storage functionality. IMaterial Provides access to dynamic properties of materials / shader properties. IParticleSystem Provides access to particle systems and lets you modify their playback state. IParticleSystemInstance Provides access to instance modifiers for particle systems. You can use this to adjust details of a particle system dynamically. IScene Provides access to properties of the currently loaded scene. ISoundLayer Provides access functions specific to sound layers. ITextureAnimation This class represents a texture animation. IVideoTexture This class represents a video texture animation. Mat4 Utility class used for creating a 4 dimensional identity matrix. MediaPlaybackEvent Media integration event, fired when the user starts, stops or pauses media. MediaPropertiesEvent Media integration event, fired when the properties of the current media session are changing. MediaStatusEvent Media integration event, fired when the user turns the media integration on or off. MediaThumbnailEvent Media integration event, fired when the thumbnail pertaining to the current media changes. MediaTimelineEvent Optional media integration event, fired irregularly when the current time of the media session changes. Shared Related to the global object which you may use to share data between multiple scripts.shared Vec2 Utility class which holds a 2 dimensional value pair: and .xy Vec3 Utility class which holds a 3 dimensional value pair: , and .xyz #Modules Wallpaper Engine also provides some modules which can be used to access certain utility functions. These can be helpful to easily implement certain use-cases. Module Description WEColor Module which provides utility functions related to color manipulation. WEMath Module which provides utility functions related to general mathematical functions. WEVector Module which provides utility functions related to working with vectors.我让你写的代码是在wallpaer引擎内使用的,这是他的语言参考
08-06
bitbake --help usage: bitbake [-s] [-e] [-g] [-u UI] [--version] [-h] [-f] [-c CMD] [-C INVALIDATE_STAMP] [--runall RUNALL] [--runonly RUNONLY] [--no-setscene] [--skip-setscene] [--setscene-only] [-n] [-p] [-k] [-P] [-S SIGNATURE_HANDLER] [--revisions-changed] [-b BUILDFILE] [-D] [-l DEBUG_DOMAINS] [-v] [-q] [-w WRITEEVENTLOG] [-B BIND] [-T SERVER_TIMEOUT] [--remote-server REMOTE_SERVER] [-m] [--token XMLRPCTOKEN] [--observe-only] [--status-only] [--server-only] [-r PREFILE] [-R POSTFILE] [-I EXTRA_ASSUME_PROVIDED] [recipename/target [recipename/target ...]] It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which will provide the layer, BBFILES and other configuration information. General options: recipename/target Execute the specified task (default is 'build') for these target recipes (.bb files). -s, --show-versions Show current and preferred versions of all recipes. -e, --environment Show the global or per-recipe environment complete with information about where variables were set/changed. -g, --graphviz Save dependency tree information for the specified targets in the dot syntax. -u UI, --ui UI The user interface to use (knotty, ncurses, taskexp, taskexp_ncurses or teamcity - default knotty). --version Show programs version and exit. -h, --help Show this help message and exit. Task control options: -f, --force Force the specified targets/task to run (invalidating any existing stamp file). -c CMD, --cmd CMD Specify the task to execute. The exact options available depend on the metadata. Some examples might be 'compile' or 'populate_sysroot' or 'listtasks' may give a list of the tasks available. -C INVALIDATE_STAMP, --clear-stamp INVALIDATE_STAMP Invalidate the stamp for the specified task such as 'compile' and then run the default task for the specified target(s). --runall RUNALL Run the specified task for any recipe in the taskgraph of the specified target (even if it wouldn't otherwise have run). --runonly RUNONLY Run only the specified task within the taskgraph of the specified targets (and any task dependencies those tasks may have). --no-setscene Do not run any setscene tasks. sstate will be ignored and everything needed, built. --skip-setscene Skip setscene tasks if they would be executed. Tasks previously restored from sstate will be kept, unlike --no-setscene. --setscene-only Only run setscene tasks, don't run any real tasks. Execution control options: -n, --dry-run Don't execute, just go through the motions. -p, --parse-only Quit after parsing the BB recipes. -k, --continue Continue as much as possible after an error. While the target that failed and anything depending on it cannot be built, as much as possible will be built before stopping. -P, --profile Profile the command and save reports. -S SIGNATURE_HANDLER, --dump-signatures SIGNATURE_HANDLER Dump out the signature construction information, with no task execution. The SIGNATURE_HANDLER parameter is passed to the handler. Two common values are none and printdiff but the handler may define more/less. none means only dump the signature, printdiff means recursively compare the dumped signature with the most recent one in a local build or sstate cache (can be used to find out why tasks re-run when that is not expected) --revisions-changed Set the exit code depending on whether upstream floating revisions have changed or not. -b BUILDFILE, --buildfile BUILDFILE Execute tasks from a specific .bb recipe directly. WARNING: Does not handle any dependencies from other recipes. Logging/output control options: -D, --debug Increase the debug level. You can specify this more than once. -D sets the debug level to 1, where only bb.debug(1, ...) messages are printed to stdout; -DD sets the debug level to 2, where both bb.debug(1, ...) and bb.debug(2, ...) messages are printed; etc. Without -D, no debug messages are printed. Note that -D only affects output to stdout. All debug messages are written to ${T}/log.do_taskname, regardless of the debug level. -l DEBUG_DOMAINS, --log-domains DEBUG_DOMAINS Show debug logging for the specified logging domains. -v, --verbose Enable tracing of shell tasks (with 'set -x'). Also print bb.note(...) messages to stdout (in addition to writing them to ${T}/log.do_<task>). -q, --quiet Output less log message data to the terminal. You can specify this more than once. -w WRITEEVENTLOG, --write-log WRITEEVENTLOG Writes the event log of the build to a bitbake event json file. Use '' (empty string) to assign the name automatically. Server options: -B BIND, --bind BIND The name/address for the bitbake xmlrpc server to bind to. -T SERVER_TIMEOUT, --idle-timeout SERVER_TIMEOUT Set timeout to unload bitbake server due to inactivity, set to -1 means no unload, default: Environment variable BB_SERVER_TIMEOUT. --remote-server REMOTE_SERVER Connect to the specified server. -m, --kill-server Terminate any running bitbake server. --token XMLRPCTOKEN Specify the connection token to be used when connecting to a remote server. --observe-only Connect to a server as an observing-only client. --status-only Check the status of the remote bitbake server. --server-only Run bitbake without a UI, only starting a server (cooker) process. Configuration options: -r PREFILE, --read PREFILE Read the specified file before bitbake.conf. -R POSTFILE, --postread POSTFILE Read the specified file after bitbake.conf. -I EXTRA_ASSUME_PROVIDED, --ignore-deps EXTRA_ASSUME_PROVIDED Assume these dependencies don't exist and are already provided (equivalent to ASSUME_PROVIDED). Useful to make dependency graphs more appealing.
07-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值